summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--ui-summary.c21
1 files changed, 13 insertions, 8 deletions
diff --git a/ui-summary.c b/ui-summary.c
index 3d5eda8..05170cc 100644
--- a/ui-summary.c
+++ b/ui-summary.c
@@ -1,215 +1,220 @@
1/* ui-summary.c: functions for generating repo summary page 1/* ui-summary.c: functions for generating repo summary page
2 * 2 *
3 * Copyright (C) 2006 Lars Hjemli 3 * Copyright (C) 2006 Lars Hjemli
4 * 4 *
5 * Licensed under GNU General Public License v2 5 * Licensed under GNU General Public License v2
6 * (see COPYING for full license text) 6 * (see COPYING for full license text)
7 */ 7 */
8 8
9#include "cgit.h" 9#include "cgit.h"
10 10
11static int header; 11static int header;
12 12
13static int cmp_tag_age(void *a, void *b) 13static int cmp_age(int age1, int age2)
14{ 14{
15 struct refinfo *r1 = *(struct refinfo **)a; 15 if (age1 != 0 && age2 != 0)
16 struct refinfo *r2 = *(struct refinfo **)b; 16 return age2 - age1;
17
18 if (r1->tag->tagger_date != 0 && r2->tag->tagger_date != 0)
19 return r2->tag->tagger_date - r1->tag->tagger_date;
20 17
21 if (r1->tag->tagger_date == 0 && r2->tag->tagger_date == 0) 18 if (age1 == 0 && age2 == 0)
22 return 0; 19 return 0;
23 20
24 if (r1 == 0) 21 if (age1 == 0)
25 return +1; 22 return +1;
26 23
27 return -1; 24 return -1;
28} 25}
29 26
27static int cmp_tag_age(const void *a, const void *b)
28{
29 struct refinfo *r1 = *(struct refinfo **)a;
30 struct refinfo *r2 = *(struct refinfo **)b;
31
32 return cmp_age(r1->tag->tagger_date, r2->tag->tagger_date);
33}
34
30static void cgit_print_branch(struct refinfo *ref) 35static void cgit_print_branch(struct refinfo *ref)
31{ 36{
32 struct commit *commit; 37 struct commit *commit;
33 struct commitinfo *info; 38 struct commitinfo *info;
34 char *name = (char *)ref->refname; 39 char *name = (char *)ref->refname;
35 40
36 commit = lookup_commit(ref->object->sha1); 41 commit = lookup_commit(ref->object->sha1);
37 // object is not really parsed at this point, because of some fallout 42 // object is not really parsed at this point, because of some fallout
38 // from previous calls to git functions in cgit_print_log() 43 // from previous calls to git functions in cgit_print_log()
39 commit->object.parsed = 0; 44 commit->object.parsed = 0;
40 if (commit && !parse_commit(commit)){ 45 if (commit && !parse_commit(commit)){
41 info = cgit_parse_commit(commit); 46 info = cgit_parse_commit(commit);
42 html("<tr><td>"); 47 html("<tr><td>");
43 cgit_log_link(name, NULL, NULL, name, NULL, NULL, 0); 48 cgit_log_link(name, NULL, NULL, name, NULL, NULL, 0);
44 html("</td><td>"); 49 html("</td><td>");
45 cgit_print_age(commit->date, -1, NULL); 50 cgit_print_age(commit->date, -1, NULL);
46 html("</td><td>"); 51 html("</td><td>");
47 html_txt(info->author); 52 html_txt(info->author);
48 html("</td><td>"); 53 html("</td><td>");
49 cgit_commit_link(info->subject, NULL, NULL, name, NULL); 54 cgit_commit_link(info->subject, NULL, NULL, name, NULL);
50 html("</td></tr>\n"); 55 html("</td></tr>\n");
51 cgit_free_commitinfo(info); 56 cgit_free_commitinfo(info);
52 } else { 57 } else {
53 html("<tr><td>"); 58 html("<tr><td>");
54 html_txt(name); 59 html_txt(name);
55 html("</td><td colspan='3'>"); 60 html("</td><td colspan='3'>");
56 htmlf("*** bad ref %s ***", sha1_to_hex(ref->object->sha1)); 61 htmlf("*** bad ref %s ***", sha1_to_hex(ref->object->sha1));
57 html("</td></tr>\n"); 62 html("</td></tr>\n");
58 } 63 }
59} 64}
60 65
61static void print_tag_header() 66static void print_tag_header()
62{ 67{
63 html("<tr class='nohover'><th class='left'>Tag</th>" 68 html("<tr class='nohover'><th class='left'>Tag</th>"
64 "<th class='left'>Age</th>" 69 "<th class='left'>Age</th>"
65 "<th class='left'>Author</th>" 70 "<th class='left'>Author</th>"
66 "<th class='left'>Reference</th></tr>\n"); 71 "<th class='left'>Reference</th></tr>\n");
67 header = 1; 72 header = 1;
68} 73}
69 74
70static int print_tag(struct refinfo *ref) 75static int print_tag(struct refinfo *ref)
71{ 76{
72 struct tag *tag; 77 struct tag *tag;
73 struct taginfo *info; 78 struct taginfo *info;
74 char *url, *name = (char *)ref->refname; 79 char *url, *name = (char *)ref->refname;
75 80
76 if (ref->object->type == OBJ_TAG) { 81 if (ref->object->type == OBJ_TAG) {
77 tag = lookup_tag(ref->object->sha1); 82 tag = lookup_tag(ref->object->sha1);
78 if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) 83 if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag)))
79 return 2; 84 return 2;
80 html("<tr><td>"); 85 html("<tr><td>");
81 url = cgit_pageurl(cgit_query_repo, "tag", 86 url = cgit_pageurl(cgit_query_repo, "tag",
82 fmt("id=%s", name)); 87 fmt("id=%s", name));
83 html_link_open(url, NULL, NULL); 88 html_link_open(url, NULL, NULL);
84 html_txt(name); 89 html_txt(name);
85 html_link_close(); 90 html_link_close();
86 html("</td><td>"); 91 html("</td><td>");
87 if (info->tagger_date > 0) 92 if (info->tagger_date > 0)
88 cgit_print_age(info->tagger_date, -1, NULL); 93 cgit_print_age(info->tagger_date, -1, NULL);
89 html("</td><td>"); 94 html("</td><td>");
90 if (info->tagger) 95 if (info->tagger)
91 html(info->tagger); 96 html(info->tagger);
92 html("</td><td>"); 97 html("</td><td>");
93 cgit_object_link(tag->tagged); 98 cgit_object_link(tag->tagged);
94 html("</td></tr>\n"); 99 html("</td></tr>\n");
95 } else { 100 } else {
96 if (!header) 101 if (!header)
97 print_tag_header(); 102 print_tag_header();
98 html("<tr><td>"); 103 html("<tr><td>");
99 html_txt(name); 104 html_txt(name);
100 html("</td><td colspan='2'/><td>"); 105 html("</td><td colspan='2'/><td>");
101 cgit_object_link(ref->object); 106 cgit_object_link(ref->object);
102 html("</td></tr>\n"); 107 html("</td></tr>\n");
103 } 108 }
104 return 0; 109 return 0;
105} 110}
106 111
107static int cgit_print_archive_cb(const char *refname, const unsigned char *sha1, 112static int cgit_print_archive_cb(const char *refname, const unsigned char *sha1,
108 int flags, void *cb_data) 113 int flags, void *cb_data)
109{ 114{
110 struct tag *tag; 115 struct tag *tag;
111 struct taginfo *info; 116 struct taginfo *info;
112 struct object *obj; 117 struct object *obj;
113 char buf[256], *url; 118 char buf[256], *url;
114 unsigned char fileid[20]; 119 unsigned char fileid[20];
115 120
116 if (prefixcmp(refname, "refs/archives")) 121 if (prefixcmp(refname, "refs/archives"))
117 return 0; 122 return 0;
118 strncpy(buf, refname+14, sizeof(buf)); 123 strncpy(buf, refname+14, sizeof(buf));
119 obj = parse_object(sha1); 124 obj = parse_object(sha1);
120 if (!obj) 125 if (!obj)
121 return 1; 126 return 1;
122 if (obj->type == OBJ_TAG) { 127 if (obj->type == OBJ_TAG) {
123 tag = lookup_tag(sha1); 128 tag = lookup_tag(sha1);
124 if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) 129 if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag)))
125 return 0; 130 return 0;
126 hashcpy(fileid, tag->tagged->sha1); 131 hashcpy(fileid, tag->tagged->sha1);
127 } else if (obj->type != OBJ_BLOB) { 132 } else if (obj->type != OBJ_BLOB) {
128 return 0; 133 return 0;
129 } else { 134 } else {
130 hashcpy(fileid, sha1); 135 hashcpy(fileid, sha1);
131 } 136 }
132 if (!header) { 137 if (!header) {
133 html("<table id='downloads'>"); 138 html("<table id='downloads'>");
134 html("<tr><th>Downloads</th></tr>"); 139 html("<tr><th>Downloads</th></tr>");
135 header = 1; 140 header = 1;
136 } 141 }
137 html("<tr><td>"); 142 html("<tr><td>");
138 url = cgit_pageurl(cgit_query_repo, "blob", 143 url = cgit_pageurl(cgit_query_repo, "blob",
139 fmt("id=%s&amp;path=%s", sha1_to_hex(fileid), 144 fmt("id=%s&amp;path=%s", sha1_to_hex(fileid),
140 buf)); 145 buf));
141 html_link_open(url, NULL, NULL); 146 html_link_open(url, NULL, NULL);
142 html_txt(buf); 147 html_txt(buf);
143 html_link_close(); 148 html_link_close();
144 html("</td></tr>"); 149 html("</td></tr>");
145 return 0; 150 return 0;
146} 151}
147 152
148static void cgit_print_branches() 153static void cgit_print_branches()
149{ 154{
150 struct reflist list; 155 struct reflist list;
151 int i; 156 int i;
152 157
153 html("<tr class='nohover'><th class='left'>Branch</th>" 158 html("<tr class='nohover'><th class='left'>Branch</th>"
154 "<th class='left'>Idle</th>" 159 "<th class='left'>Idle</th>"
155 "<th class='left'>Author</th>" 160 "<th class='left'>Author</th>"
156 "<th class='left'>Head commit</th></tr>\n"); 161 "<th class='left'>Head commit</th></tr>\n");
157 162
158 list.refs = NULL; 163 list.refs = NULL;
159 list.alloc = list.count = 0; 164 list.alloc = list.count = 0;
160 for_each_branch_ref(cgit_refs_cb, &list); 165 for_each_branch_ref(cgit_refs_cb, &list);
161 for(i=0; i<list.count; i++) 166 for(i=0; i<list.count; i++)
162 cgit_print_branch(list.refs[i]); 167 cgit_print_branch(list.refs[i]);
163} 168}
164 169
165static void cgit_print_tags(int maxcount) 170static void cgit_print_tags(int maxcount)
166{ 171{
167 struct reflist list; 172 struct reflist list;
168 int i; 173 int i;
169 174
170 header = 0; 175 header = 0;
171 list.refs = NULL; 176 list.refs = NULL;
172 list.alloc = list.count = 0; 177 list.alloc = list.count = 0;
173 for_each_tag_ref(cgit_refs_cb, &list); 178 for_each_tag_ref(cgit_refs_cb, &list);
174 if (list.count == 0) 179 if (list.count == 0)
175 return; 180 return;
176 qsort(list.refs, list.count, sizeof(*list.refs), cmp_tag_age); 181 qsort(list.refs, list.count, sizeof(*list.refs), cmp_tag_age);
177 if (!maxcount) 182 if (!maxcount)
178 maxcount = list.count; 183 maxcount = list.count;
179 else if (maxcount > list.count) 184 else if (maxcount > list.count)
180 maxcount = list.count; 185 maxcount = list.count;
181 print_tag_header(); 186 print_tag_header();
182 for(i=0; i<maxcount; i++) 187 for(i=0; i<maxcount; i++)
183 print_tag(list.refs[i]); 188 print_tag(list.refs[i]);
184} 189}
185 190
186static void cgit_print_archives() 191static void cgit_print_archives()
187{ 192{
188 header = 0; 193 header = 0;
189 for_each_ref(cgit_print_archive_cb, NULL); 194 for_each_ref(cgit_print_archive_cb, NULL);
190 if (header) 195 if (header)
191 html("</table>"); 196 html("</table>");
192} 197}
193 198
194void cgit_print_summary() 199void cgit_print_summary()
195{ 200{
196 html("<div id='summary'>"); 201 html("<div id='summary'>");
197 cgit_print_archives(); 202 cgit_print_archives();
198 html("<h2>"); 203 html("<h2>");
199 html_txt(cgit_repo->name); 204 html_txt(cgit_repo->name);
200 html(" - "); 205 html(" - ");
201 html_txt(cgit_repo->desc); 206 html_txt(cgit_repo->desc);
202 html("</h2>"); 207 html("</h2>");
203 if (cgit_repo->readme) 208 if (cgit_repo->readme)
204 html_include(cgit_repo->readme); 209 html_include(cgit_repo->readme);
205 html("</div>"); 210 html("</div>");
206 if (cgit_summary_log > 0) 211 if (cgit_summary_log > 0)
207 cgit_print_log(cgit_query_head, 0, cgit_summary_log, NULL, NULL, 0); 212 cgit_print_log(cgit_query_head, 0, cgit_summary_log, NULL, NULL, 0);
208 html("<table class='list nowrap'>"); 213 html("<table class='list nowrap'>");
209 if (cgit_summary_log > 0) 214 if (cgit_summary_log > 0)
210 html("<tr class='nohover'><td colspan='4'>&nbsp;</td></tr>"); 215 html("<tr class='nohover'><td colspan='4'>&nbsp;</td></tr>");
211 cgit_print_branches(); 216 cgit_print_branches();
212 html("<tr class='nohover'><td colspan='4'>&nbsp;</td></tr>"); 217 html("<tr class='nohover'><td colspan='4'>&nbsp;</td></tr>");
213 cgit_print_tags(cgit_summary_tags); 218 cgit_print_tags(cgit_summary_tags);
214 html("</table>"); 219 html("</table>");
215} 220}