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_tag_age(const void *a, const void *b)
29 struct refinfo *r1 = *(struct refinfo **)a;
30 struct refinfo *r2 = *(struct refinfo **)b;
32 return cmp_age(r1->tag->tagger_date, r2->tag->tagger_date);
35 static void cgit_print_branch(struct refinfo *ref)
37 struct commit *commit;
38 struct commitinfo *info;
39 char *name = (char *)ref->refname;
41 commit = lookup_commit(ref->object->sha1);
42 // object is not really parsed at this point, because of some fallout
43 // from previous calls to git functions in cgit_print_log()
44 commit->object.parsed = 0;
45 if (commit && !parse_commit(commit)){
46 info = cgit_parse_commit(commit);
48 cgit_log_link(name, NULL, NULL, name, NULL, NULL, 0);
50 cgit_print_age(commit->date, -1, NULL);
52 html_txt(info->author);
54 cgit_commit_link(info->subject, NULL, NULL, name, NULL);
56 cgit_free_commitinfo(info);
60 html("</td><td colspan='3'>");
61 htmlf("*** bad ref %s ***", sha1_to_hex(ref->object->sha1));
66 static void print_tag_header()
68 html("<tr class='nohover'><th class='left'>Tag</th>"
69 "<th class='left'>Age</th>"
70 "<th class='left'>Author</th>"
71 "<th class='left'>Reference</th></tr>\n");
75 static int print_tag(struct refinfo *ref)
79 char *url, *name = (char *)ref->refname;
81 if (ref->object->type == OBJ_TAG) {
82 tag = lookup_tag(ref->object->sha1);
83 if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag)))
86 url = cgit_pageurl(cgit_query_repo, "tag",
88 html_link_open(url, NULL, NULL);
92 if (info->tagger_date > 0)
93 cgit_print_age(info->tagger_date, -1, NULL);
98 cgit_object_link(tag->tagged);
105 html("</td><td colspan='2'/><td>");
106 cgit_object_link(ref->object);
107 html("</td></tr>\n");
112 static int cgit_print_archive_cb(const char *refname, const unsigned char *sha1,
113 int flags, void *cb_data)
116 struct taginfo *info;
119 unsigned char fileid[20];
121 if (prefixcmp(refname, "refs/archives"))
123 strncpy(buf, refname+14, sizeof(buf));
124 obj = parse_object(sha1);
127 if (obj->type == OBJ_TAG) {
128 tag = lookup_tag(sha1);
129 if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag)))
131 hashcpy(fileid, tag->tagged->sha1);
132 } else if (obj->type != OBJ_BLOB) {
135 hashcpy(fileid, sha1);
138 html("<table id='downloads'>");
139 html("<tr><th>Downloads</th></tr>");
143 url = cgit_pageurl(cgit_query_repo, "blob",
144 fmt("id=%s&path=%s", sha1_to_hex(fileid),
146 html_link_open(url, NULL, NULL);
153 static void cgit_print_branches()
158 html("<tr class='nohover'><th class='left'>Branch</th>"
159 "<th class='left'>Idle</th>"
160 "<th class='left'>Author</th>"
161 "<th class='left'>Head commit</th></tr>\n");
164 list.alloc = list.count = 0;
165 for_each_branch_ref(cgit_refs_cb, &list);
166 for(i=0; i<list.count; i++)
167 cgit_print_branch(list.refs[i]);
170 static void cgit_print_tags(int maxcount)
177 list.alloc = list.count = 0;
178 for_each_tag_ref(cgit_refs_cb, &list);
181 qsort(list.refs, list.count, sizeof(*list.refs), cmp_tag_age);
183 maxcount = list.count;
184 else if (maxcount > list.count)
185 maxcount = list.count;
187 for(i=0; i<maxcount; i++)
188 print_tag(list.refs[i]);
191 static void cgit_print_archives()
194 for_each_ref(cgit_print_archive_cb, NULL);
199 void cgit_print_summary()
201 html("<div id='summary'>");
202 cgit_print_archives();
204 html_txt(cgit_repo->name);
206 html_txt(cgit_repo->desc);
208 if (cgit_repo->readme)
209 html_include(cgit_repo->readme);
211 if (cgit_summary_log > 0)
212 cgit_print_log(cgit_query_head, 0, cgit_summary_log, NULL, NULL, 0);
213 html("<table class='list nowrap'>");
214 if (cgit_summary_log > 0)
215 html("<tr class='nohover'><td colspan='4'> </td></tr>");
216 cgit_print_branches();
217 html("<tr class='nohover'><td colspan='4'> </td></tr>");
218 cgit_print_tags(cgit_summary_tags);