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 void cgit_print_branch(struct refinfo *ref)
53 struct commit *commit;
54 struct commitinfo *info;
55 char *name = (char *)ref->refname;
57 commit = lookup_commit(ref->object->sha1);
58 // object is not really parsed at this point, because of some fallout
59 // from previous calls to git functions in cgit_print_log()
60 commit->object.parsed = 0;
61 if (commit && !parse_commit(commit)){
62 info = cgit_parse_commit(commit);
64 cgit_log_link(name, NULL, NULL, name, NULL, NULL, 0);
66 cgit_print_age(commit->date, -1, NULL);
68 html_txt(info->author);
70 cgit_commit_link(info->subject, NULL, NULL, name, NULL);
72 cgit_free_commitinfo(info);
76 html("</td><td colspan='3'>");
77 htmlf("*** bad ref %s ***", sha1_to_hex(ref->object->sha1));
82 static void print_tag_header()
84 html("<tr class='nohover'><th class='left'>Tag</th>"
85 "<th class='left'>Age</th>"
86 "<th class='left'>Author</th>"
87 "<th class='left'>Reference</th></tr>\n");
91 static int print_tag(struct refinfo *ref)
95 char *url, *name = (char *)ref->refname;
97 if (ref->object->type == OBJ_TAG) {
98 tag = lookup_tag(ref->object->sha1);
99 if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag)))
102 url = cgit_pageurl(cgit_query_repo, "tag",
104 html_link_open(url, NULL, NULL);
108 if (info->tagger_date > 0)
109 cgit_print_age(info->tagger_date, -1, NULL);
114 cgit_object_link(tag->tagged);
115 html("</td></tr>\n");
121 html("</td><td colspan='2'/><td>");
122 cgit_object_link(ref->object);
123 html("</td></tr>\n");
128 static int cgit_print_archive_cb(const char *refname, const unsigned char *sha1,
129 int flags, void *cb_data)
132 struct taginfo *info;
135 unsigned char fileid[20];
137 if (prefixcmp(refname, "refs/archives"))
139 strncpy(buf, refname+14, sizeof(buf));
140 obj = parse_object(sha1);
143 if (obj->type == OBJ_TAG) {
144 tag = lookup_tag(sha1);
145 if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag)))
147 hashcpy(fileid, tag->tagged->sha1);
148 } else if (obj->type != OBJ_BLOB) {
151 hashcpy(fileid, sha1);
154 html("<table id='downloads'>");
155 html("<tr><th>Downloads</th></tr>");
159 url = cgit_pageurl(cgit_query_repo, "blob",
160 fmt("id=%s&path=%s", sha1_to_hex(fileid),
162 html_link_open(url, NULL, NULL);
169 static void cgit_print_branches(int maxcount)
174 html("<tr class='nohover'><th class='left'>Branch</th>"
175 "<th class='left'>Idle</th>"
176 "<th class='left'>Author</th>"
177 "<th class='left'>Head commit</th></tr>\n");
180 list.alloc = list.count = 0;
181 for_each_branch_ref(cgit_refs_cb, &list);
183 if (maxcount == 0 || maxcount > list.count)
184 maxcount = list.count;
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);
191 for(i=0; i<maxcount; i++)
192 cgit_print_branch(list.refs[i]);
195 static void cgit_print_tags(int maxcount)
202 list.alloc = list.count = 0;
203 for_each_tag_ref(cgit_refs_cb, &list);
206 qsort(list.refs, list.count, sizeof(*list.refs), cmp_tag_age);
208 maxcount = list.count;
209 else if (maxcount > list.count)
210 maxcount = list.count;
212 for(i=0; i<maxcount; i++)
213 print_tag(list.refs[i]);
216 static void cgit_print_archives()
219 for_each_ref(cgit_print_archive_cb, NULL);
224 void cgit_print_summary()
226 html("<div id='summary'>");
227 cgit_print_archives();
229 html_txt(cgit_repo->name);
231 html_txt(cgit_repo->desc);
233 if (cgit_repo->readme)
234 html_include(cgit_repo->readme);
236 if (cgit_summary_log > 0)
237 cgit_print_log(cgit_query_head, 0, cgit_summary_log, NULL, NULL, 0);
238 html("<table class='list nowrap'>");
239 if (cgit_summary_log > 0)
240 html("<tr class='nohover'><td colspan='4'> </td></tr>");
241 cgit_print_branches(cgit_summary_branches);
242 html("<tr class='nohover'><td colspan='4'> </td></tr>");
243 cgit_print_tags(cgit_summary_tags);