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_tag_age(void *a, void *b)
15 struct refinfo *r1 = *(struct refinfo **)a;
16 struct refinfo *r2 = *(struct refinfo **)b;
18 if (r1->tag->tagger_date != 0 && r2->tag->tagger_date != 0)
19 return r2->tag->tagger_date - r1->tag->tagger_date;
21 if (r1->tag->tagger_date == 0 && r2->tag->tagger_date == 0)
30 static void cgit_print_branch(struct refinfo *ref)
32 struct commit *commit;
33 struct commitinfo *info;
34 char *name = (char *)ref->refname;
36 commit = lookup_commit(ref->object->sha1);
37 // object is not really parsed at this point, because of some fallout
38 // from previous calls to git functions in cgit_print_log()
39 commit->object.parsed = 0;
40 if (commit && !parse_commit(commit)){
41 info = cgit_parse_commit(commit);
43 cgit_log_link(name, NULL, NULL, name, NULL, NULL, 0);
45 cgit_print_age(commit->date, -1, NULL);
47 html_txt(info->author);
49 cgit_commit_link(info->subject, NULL, NULL, name, NULL);
51 cgit_free_commitinfo(info);
55 html("</td><td colspan='3'>");
56 htmlf("*** bad ref %s ***", sha1_to_hex(ref->object->sha1));
61 static void print_tag_header()
63 html("<tr class='nohover'><th class='left'>Tag</th>"
64 "<th class='left'>Age</th>"
65 "<th class='left'>Author</th>"
66 "<th class='left'>Reference</th></tr>\n");
70 static int print_tag(struct refinfo *ref)
74 char *url, *name = (char *)ref->refname;
76 if (ref->object->type == OBJ_TAG) {
77 tag = lookup_tag(ref->object->sha1);
78 if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag)))
81 url = cgit_pageurl(cgit_query_repo, "tag",
83 html_link_open(url, NULL, NULL);
87 if (info->tagger_date > 0)
88 cgit_print_age(info->tagger_date, -1, NULL);
93 cgit_object_link(tag->tagged);
100 html("</td><td colspan='2'/><td>");
101 cgit_object_link(ref->object);
102 html("</td></tr>\n");
107 static int cgit_print_archive_cb(const char *refname, const unsigned char *sha1,
108 int flags, void *cb_data)
111 struct taginfo *info;
114 unsigned char fileid[20];
116 if (prefixcmp(refname, "refs/archives"))
118 strncpy(buf, refname+14, sizeof(buf));
119 obj = parse_object(sha1);
122 if (obj->type == OBJ_TAG) {
123 tag = lookup_tag(sha1);
124 if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag)))
126 hashcpy(fileid, tag->tagged->sha1);
127 } else if (obj->type != OBJ_BLOB) {
130 hashcpy(fileid, sha1);
133 html("<table id='downloads'>");
134 html("<tr><th>Downloads</th></tr>");
138 url = cgit_pageurl(cgit_query_repo, "blob",
139 fmt("id=%s&path=%s", sha1_to_hex(fileid),
141 html_link_open(url, NULL, NULL);
148 static void cgit_print_branches()
153 html("<tr class='nohover'><th class='left'>Branch</th>"
154 "<th class='left'>Idle</th>"
155 "<th class='left'>Author</th>"
156 "<th class='left'>Head commit</th></tr>\n");
159 list.alloc = list.count = 0;
160 for_each_branch_ref(cgit_refs_cb, &list);
161 for(i=0; i<list.count; i++)
162 cgit_print_branch(list.refs[i]);
165 static void cgit_print_tags(int maxcount)
172 list.alloc = list.count = 0;
173 for_each_tag_ref(cgit_refs_cb, &list);
176 qsort(list.refs, list.count, sizeof(*list.refs), cmp_tag_age);
178 maxcount = list.count;
179 else if (maxcount > list.count)
180 maxcount = list.count;
182 for(i=0; i<maxcount; i++)
183 print_tag(list.refs[i]);
186 static void cgit_print_archives()
189 for_each_ref(cgit_print_archive_cb, NULL);
194 void cgit_print_summary()
196 html("<div id='summary'>");
197 cgit_print_archives();
199 html_txt(cgit_repo->name);
201 html_txt(cgit_repo->desc);
203 if (cgit_repo->readme)
204 html_include(cgit_repo->readme);
206 if (cgit_summary_log > 0)
207 cgit_print_log(cgit_query_head, 0, cgit_summary_log, NULL, NULL, 0);
208 html("<table class='list nowrap'>");
209 if (cgit_summary_log > 0)
210 html("<tr class='nohover'><td colspan='4'> </td></tr>");
211 cgit_print_branches();
212 html("<tr class='nohover'><td colspan='4'> </td></tr>");
213 cgit_print_tags(cgit_summary_tags);