summaryrefslogtreecommitdiffabout
path: root/ui-summary.c
Unidiff
Diffstat (limited to 'ui-summary.c') (more/less context) (ignore whitespace changes)
-rw-r--r--ui-summary.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/ui-summary.c b/ui-summary.c
index 97f1b57..016fea2 100644
--- a/ui-summary.c
+++ b/ui-summary.c
@@ -73,173 +73,186 @@ static void cgit_print_branch(struct refinfo *ref)
73 } else { 73 } else {
74 html("<tr><td>"); 74 html("<tr><td>");
75 html_txt(name); 75 html_txt(name);
76 html("</td><td colspan='3'>"); 76 html("</td><td colspan='3'>");
77 htmlf("*** bad ref %s ***", sha1_to_hex(ref->object->sha1)); 77 htmlf("*** bad ref %s ***", sha1_to_hex(ref->object->sha1));
78 html("</td></tr>\n"); 78 html("</td></tr>\n");
79 } 79 }
80} 80}
81 81
82static void print_tag_header() 82static void print_tag_header()
83{ 83{
84 html("<tr class='nohover'><th class='left'>Tag</th>" 84 html("<tr class='nohover'><th class='left'>Tag</th>"
85 "<th class='left'>Age</th>" 85 "<th class='left'>Age</th>"
86 "<th class='left'>Author</th>" 86 "<th class='left'>Author</th>"
87 "<th class='left'>Reference</th></tr>\n"); 87 "<th class='left'>Reference</th></tr>\n");
88 header = 1; 88 header = 1;
89} 89}
90 90
91static int print_tag(struct refinfo *ref) 91static int print_tag(struct refinfo *ref)
92{ 92{
93 struct tag *tag; 93 struct tag *tag;
94 struct taginfo *info; 94 struct taginfo *info;
95 char *url, *name = (char *)ref->refname; 95 char *url, *name = (char *)ref->refname;
96 96
97 if (ref->object->type == OBJ_TAG) { 97 if (ref->object->type == OBJ_TAG) {
98 tag = lookup_tag(ref->object->sha1); 98 tag = lookup_tag(ref->object->sha1);
99 if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) 99 if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag)))
100 return 2; 100 return 2;
101 html("<tr><td>"); 101 html("<tr><td>");
102 url = cgit_pageurl(cgit_query_repo, "tag", 102 url = cgit_pageurl(cgit_query_repo, "tag",
103 fmt("id=%s", name)); 103 fmt("id=%s", name));
104 html_link_open(url, NULL, NULL); 104 html_link_open(url, NULL, NULL);
105 html_txt(name); 105 html_txt(name);
106 html_link_close(); 106 html_link_close();
107 html("</td><td>"); 107 html("</td><td>");
108 if (info->tagger_date > 0) 108 if (info->tagger_date > 0)
109 cgit_print_age(info->tagger_date, -1, NULL); 109 cgit_print_age(info->tagger_date, -1, NULL);
110 html("</td><td>"); 110 html("</td><td>");
111 if (info->tagger) 111 if (info->tagger)
112 html(info->tagger); 112 html(info->tagger);
113 html("</td><td>"); 113 html("</td><td>");
114 cgit_object_link(tag->tagged); 114 cgit_object_link(tag->tagged);
115 html("</td></tr>\n"); 115 html("</td></tr>\n");
116 } else { 116 } else {
117 if (!header) 117 if (!header)
118 print_tag_header(); 118 print_tag_header();
119 html("<tr><td>"); 119 html("<tr><td>");
120 html_txt(name); 120 html_txt(name);
121 html("</td><td colspan='2'/><td>"); 121 html("</td><td colspan='2'/><td>");
122 cgit_object_link(ref->object); 122 cgit_object_link(ref->object);
123 html("</td></tr>\n"); 123 html("</td></tr>\n");
124 } 124 }
125 return 0; 125 return 0;
126} 126}
127 127
128static 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,
129 int flags, void *cb_data) 129 int flags, void *cb_data)
130{ 130{
131 struct tag *tag; 131 struct tag *tag;
132 struct taginfo *info; 132 struct taginfo *info;
133 struct object *obj; 133 struct object *obj;
134 char buf[256], *url; 134 char buf[256], *url;
135 unsigned char fileid[20]; 135 unsigned char fileid[20];
136 136
137 if (prefixcmp(refname, "refs/archives")) 137 if (prefixcmp(refname, "refs/archives"))
138 return 0; 138 return 0;
139 strncpy(buf, refname+14, sizeof(buf)); 139 strncpy(buf, refname+14, sizeof(buf));
140 obj = parse_object(sha1); 140 obj = parse_object(sha1);
141 if (!obj) 141 if (!obj)
142 return 1; 142 return 1;
143 if (obj->type == OBJ_TAG) { 143 if (obj->type == OBJ_TAG) {
144 tag = lookup_tag(sha1); 144 tag = lookup_tag(sha1);
145 if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) 145 if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag)))
146 return 0; 146 return 0;
147 hashcpy(fileid, tag->tagged->sha1); 147 hashcpy(fileid, tag->tagged->sha1);
148 } else if (obj->type != OBJ_BLOB) { 148 } else if (obj->type != OBJ_BLOB) {
149 return 0; 149 return 0;
150 } else { 150 } else {
151 hashcpy(fileid, sha1); 151 hashcpy(fileid, sha1);
152 } 152 }
153 if (!header) { 153 if (!header) {
154 html("<table id='downloads'>"); 154 html("<table id='downloads'>");
155 html("<tr><th>Downloads</th></tr>"); 155 html("<tr><th>Downloads</th></tr>");
156 header = 1; 156 header = 1;
157 } 157 }
158 html("<tr><td>"); 158 html("<tr><td>");
159 url = cgit_pageurl(cgit_query_repo, "blob", 159 url = cgit_pageurl(cgit_query_repo, "blob",
160 fmt("id=%s&amp;path=%s", sha1_to_hex(fileid), 160 fmt("id=%s&amp;path=%s", sha1_to_hex(fileid),
161 buf)); 161 buf));
162 html_link_open(url, NULL, NULL); 162 html_link_open(url, NULL, NULL);
163 html_txt(buf); 163 html_txt(buf);
164 html_link_close(); 164 html_link_close();
165 html("</td></tr>"); 165 html("</td></tr>");
166 return 0; 166 return 0;
167} 167}
168 168
169static void print_refs_link(char *path)
170{
171 html("<tr class='nohover'><td colspan='4'>");
172 cgit_refs_link("[...]", NULL, NULL, cgit_query_head, NULL, path);
173 html("</td></tr>");
174}
175
169void cgit_print_branches(int maxcount) 176void cgit_print_branches(int maxcount)
170{ 177{
171 struct reflist list; 178 struct reflist list;
172 int i; 179 int i;
173 180
174 html("<tr class='nohover'><th class='left'>Branch</th>" 181 html("<tr class='nohover'><th class='left'>Branch</th>"
175 "<th class='left'>Idle</th>" 182 "<th class='left'>Idle</th>"
176 "<th class='left'>Author</th>" 183 "<th class='left'>Author</th>"
177 "<th class='left'>Head commit</th></tr>\n"); 184 "<th class='left'>Head commit</th></tr>\n");
178 185
179 list.refs = NULL; 186 list.refs = NULL;
180 list.alloc = list.count = 0; 187 list.alloc = list.count = 0;
181 for_each_branch_ref(cgit_refs_cb, &list); 188 for_each_branch_ref(cgit_refs_cb, &list);
182 189
183 if (maxcount == 0 || maxcount > list.count) 190 if (maxcount == 0 || maxcount > list.count)
184 maxcount = list.count; 191 maxcount = list.count;
185 192
186 if (maxcount < list.count) { 193 if (maxcount < list.count) {
187 qsort(list.refs, list.count, sizeof(*list.refs), cmp_branch_age); 194 qsort(list.refs, list.count, sizeof(*list.refs), cmp_branch_age);
188 qsort(list.refs, maxcount, sizeof(*list.refs), cmp_ref_name); 195 qsort(list.refs, maxcount, sizeof(*list.refs), cmp_ref_name);
189 } 196 }
190 197
191 for(i=0; i<maxcount; i++) 198 for(i=0; i<maxcount; i++)
192 cgit_print_branch(list.refs[i]); 199 cgit_print_branch(list.refs[i]);
200
201 if (maxcount < list.count)
202 print_refs_link("heads");
193} 203}
194 204
195void cgit_print_tags(int maxcount) 205void cgit_print_tags(int maxcount)
196{ 206{
197 struct reflist list; 207 struct reflist list;
198 int i; 208 int i;
199 209
200 header = 0; 210 header = 0;
201 list.refs = NULL; 211 list.refs = NULL;
202 list.alloc = list.count = 0; 212 list.alloc = list.count = 0;
203 for_each_tag_ref(cgit_refs_cb, &list); 213 for_each_tag_ref(cgit_refs_cb, &list);
204 if (list.count == 0) 214 if (list.count == 0)
205 return; 215 return;
206 qsort(list.refs, list.count, sizeof(*list.refs), cmp_tag_age); 216 qsort(list.refs, list.count, sizeof(*list.refs), cmp_tag_age);
207 if (!maxcount) 217 if (!maxcount)
208 maxcount = list.count; 218 maxcount = list.count;
209 else if (maxcount > list.count) 219 else if (maxcount > list.count)
210 maxcount = list.count; 220 maxcount = list.count;
211 print_tag_header(); 221 print_tag_header();
212 for(i=0; i<maxcount; i++) 222 for(i=0; i<maxcount; i++)
213 print_tag(list.refs[i]); 223 print_tag(list.refs[i]);
224
225 if (maxcount < list.count)
226 print_refs_link("tags");
214} 227}
215 228
216static void cgit_print_archives() 229static void cgit_print_archives()
217{ 230{
218 header = 0; 231 header = 0;
219 for_each_ref(cgit_print_archive_cb, NULL); 232 for_each_ref(cgit_print_archive_cb, NULL);
220 if (header) 233 if (header)
221 html("</table>"); 234 html("</table>");
222} 235}
223 236
224void cgit_print_summary() 237void cgit_print_summary()
225{ 238{
226 html("<div id='summary'>"); 239 html("<div id='summary'>");
227 cgit_print_archives(); 240 cgit_print_archives();
228 html("<h2>"); 241 html("<h2>");
229 html_txt(cgit_repo->name); 242 html_txt(cgit_repo->name);
230 html(" - "); 243 html(" - ");
231 html_txt(cgit_repo->desc); 244 html_txt(cgit_repo->desc);
232 html("</h2>"); 245 html("</h2>");
233 if (cgit_repo->readme) 246 if (cgit_repo->readme)
234 html_include(cgit_repo->readme); 247 html_include(cgit_repo->readme);
235 html("</div>"); 248 html("</div>");
236 if (cgit_summary_log > 0) 249 if (cgit_summary_log > 0)
237 cgit_print_log(cgit_query_head, 0, cgit_summary_log, NULL, NULL, 0); 250 cgit_print_log(cgit_query_head, 0, cgit_summary_log, NULL, NULL, 0);
238 html("<table class='list nowrap'>"); 251 html("<table class='list nowrap'>");
239 if (cgit_summary_log > 0) 252 if (cgit_summary_log > 0)
240 html("<tr class='nohover'><td colspan='4'>&nbsp;</td></tr>"); 253 html("<tr class='nohover'><td colspan='4'>&nbsp;</td></tr>");
241 cgit_print_branches(cgit_summary_branches); 254 cgit_print_branches(cgit_summary_branches);
242 html("<tr class='nohover'><td colspan='4'>&nbsp;</td></tr>"); 255 html("<tr class='nohover'><td colspan='4'>&nbsp;</td></tr>");
243 cgit_print_tags(cgit_summary_tags); 256 cgit_print_tags(cgit_summary_tags);
244 html("</table>"); 257 html("</table>");
245} 258}