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