1 /* ui-summary.c: functions for generating repo summary page
3 * Copyright (C) 2006 Lars Hjemli
5 * Licensed under GNU General Public License v2
6 * (see COPYING for full license text)
13 static int cmp_age(int age1, int age2)
15 if (age1 != 0 && age2 != 0)
18 if (age1 == 0 && age2 == 0)
27 static int cmp_ref_name(const void *a, const void *b)
29 struct refinfo *r1 = *(struct refinfo **)a;
30 struct refinfo *r2 = *(struct refinfo **)b;
32 return strcmp(r1->refname, r2->refname);
35 static int cmp_branch_age(const void *a, const void *b)
37 struct refinfo *r1 = *(struct refinfo **)a;
38 struct refinfo *r2 = *(struct refinfo **)b;
40 return cmp_age(r1->commit->committer_date, r2->commit->committer_date);
43 static int cmp_tag_age(const void *a, const void *b)
45 struct refinfo *r1 = *(struct refinfo **)a;
46 struct refinfo *r2 = *(struct refinfo **)b;
48 return cmp_age(r1->tag->tagger_date, r2->tag->tagger_date);
51 static int print_branch(struct refinfo *ref)
53 struct commitinfo *info = ref->commit;
54 char *name = (char *)ref->refname;
59 cgit_log_link(name, NULL, NULL, name, NULL, NULL, 0);
62 if (ref->object->type == OBJ_COMMIT) {
63 cgit_print_age(info->commit->date, -1, NULL);
65 html_txt(info->author);
67 cgit_commit_link(info->subject, NULL, NULL, name, NULL);
69 html("</td><td></td><td>");
70 cgit_object_link(ref->object);
76 static void print_tag_header()
78 html("<tr class='nohover'><th class='left'>Tag</th>"
79 "<th class='left'>Age</th>"
80 "<th class='left'>Author</th>"
81 "<th class='left'>Reference</th></tr>\n");
85 static int print_tag(struct refinfo *ref)
89 char *url, *name = (char *)ref->refname;
91 if (ref->object->type == OBJ_TAG) {
92 tag = (struct tag *)ref->object;
97 url = cgit_pageurl(cgit_query_repo, "tag",
99 html_link_open(url, NULL, NULL);
103 if (info->tagger_date > 0)
104 cgit_print_age(info->tagger_date, -1, NULL);
109 cgit_object_link(tag->tagged);
110 html("</td></tr>\n");
116 html("</td><td colspan='2'/><td>");
117 cgit_object_link(ref->object);
118 html("</td></tr>\n");
123 static int cgit_print_archive_cb(const char *refname, const unsigned char *sha1,
124 int flags, void *cb_data)
127 struct taginfo *info;
130 unsigned char fileid[20];
132 if (prefixcmp(refname, "refs/archives"))
134 strncpy(buf, refname+14, sizeof(buf));
135 obj = parse_object(sha1);
138 if (obj->type == OBJ_TAG) {
139 tag = lookup_tag(sha1);
140 if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag)))
142 hashcpy(fileid, tag->tagged->sha1);
143 } else if (obj->type != OBJ_BLOB) {
146 hashcpy(fileid, sha1);
149 html("<table id='downloads'>");
150 html("<tr><th>Downloads</th></tr>");
154 url = cgit_pageurl(cgit_query_repo, "blob",
155 fmt("id=%s&path=%s", sha1_to_hex(fileid),
157 html_link_open(url, NULL, NULL);
164 static void print_refs_link(char *path)
166 html("<tr class='nohover'><td colspan='4'>");
167 cgit_refs_link("[...]", NULL, NULL, cgit_query_head, NULL, path);
171 void cgit_print_branches(int maxcount)
176 html("<tr class='nohover'><th class='left'>Branch</th>"
177 "<th class='left'>Idle</th>"
178 "<th class='left'>Author</th>"
179 "<th class='left'>Head commit</th></tr>\n");
182 list.alloc = list.count = 0;
183 for_each_branch_ref(cgit_refs_cb, &list);
185 if (maxcount == 0 || maxcount > list.count)
186 maxcount = list.count;
188 if (maxcount < list.count) {
189 qsort(list.refs, list.count, sizeof(*list.refs), cmp_branch_age);
190 qsort(list.refs, maxcount, sizeof(*list.refs), cmp_ref_name);
193 for(i=0; i<maxcount; i++)
194 print_branch(list.refs[i]);
196 if (maxcount < list.count)
197 print_refs_link("heads");
200 void cgit_print_tags(int maxcount)
207 list.alloc = list.count = 0;
208 for_each_tag_ref(cgit_refs_cb, &list);
211 qsort(list.refs, list.count, sizeof(*list.refs), cmp_tag_age);
213 maxcount = list.count;
214 else if (maxcount > list.count)
215 maxcount = list.count;
217 for(i=0; i<maxcount; i++)
218 print_tag(list.refs[i]);
220 if (maxcount < list.count)
221 print_refs_link("tags");
224 static void cgit_print_archives()
227 for_each_ref(cgit_print_archive_cb, NULL);
232 void cgit_print_summary()
234 html("<div id='summary'>");
235 cgit_print_archives();
237 html_txt(cgit_repo->name);
239 html_txt(cgit_repo->desc);
241 if (cgit_repo->readme)
242 html_include(cgit_repo->readme);
244 if (cgit_summary_log > 0)
245 cgit_print_log(cgit_query_head, 0, cgit_summary_log, NULL, NULL, NULL, 0);
246 html("<table class='list nowrap'>");
247 if (cgit_summary_log > 0)
248 html("<tr class='nohover'><td colspan='4'> </td></tr>");
249 cgit_print_branches(cgit_summary_branches);
250 html("<tr class='nohover'><td colspan='4'> </td></tr>");
251 cgit_print_tags(cgit_summary_tags);