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 cgit_print_branch_cb(const char *refname, const unsigned char *sha1,
14 int flags, void *cb_data)
16 struct commit *commit;
17 struct commitinfo *info;
21 ref = xstrdup(refname);
22 strncpy(buf, refname, sizeof(buf));
23 commit = lookup_commit(sha1);
24 // object is not really parsed at this point, because of some fallout
25 // from previous calls to git functions in cgit_print_log()
26 commit->object.parsed = 0;
27 if (commit && !parse_commit(commit)){
28 info = cgit_parse_commit(commit);
30 cgit_log_link(ref, NULL, NULL, ref, NULL, NULL, 0);
32 cgit_print_age(commit->date, -1, NULL);
34 html_txt(info->author);
36 cgit_commit_link(info->subject, NULL, NULL, ref, NULL);
38 cgit_free_commitinfo(info);
42 html("</td><td colspan='3'>");
43 htmlf("*** bad ref %s ***", sha1_to_hex(sha1));
50 static void print_tag_header()
52 html("<tr class='nohover'><th class='left'>Tag</th>"
53 "<th class='left'>Age</th>"
54 "<th class='left'>Author</th>"
55 "<th class='left'>Reference</th></tr>\n");
59 static int cgit_print_tag_cb(const char *refname, const unsigned char *sha1,
60 int flags, void *cb_data)
67 strncpy(buf, refname, sizeof(buf));
68 obj = parse_object(sha1);
71 if (obj->type == OBJ_TAG) {
72 tag = lookup_tag(sha1);
73 if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag)))
78 url = cgit_pageurl(cgit_query_repo, "tag",
79 fmt("id=%s", refname));
80 html_link_open(url, NULL, NULL);
84 if (info->tagger_date > 0)
85 cgit_print_age(info->tagger_date, -1, NULL);
90 cgit_object_link(tag->tagged);
97 html("</td><td colspan='2'/><td>");
98 cgit_object_link(obj);
104 static int cgit_print_archive_cb(const char *refname, const unsigned char *sha1,
105 int flags, void *cb_data)
108 struct taginfo *info;
111 unsigned char fileid[20];
113 if (prefixcmp(refname, "refs/archives"))
115 strncpy(buf, refname+14, sizeof(buf));
116 obj = parse_object(sha1);
119 if (obj->type == OBJ_TAG) {
120 tag = lookup_tag(sha1);
121 if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag)))
123 hashcpy(fileid, tag->tagged->sha1);
124 } else if (obj->type != OBJ_BLOB) {
127 hashcpy(fileid, sha1);
130 html("<table id='downloads'>");
131 html("<tr><th>Downloads</th></tr>");
135 url = cgit_pageurl(cgit_query_repo, "blob",
136 fmt("id=%s&path=%s", sha1_to_hex(fileid),
138 html_link_open(url, NULL, NULL);
145 static void cgit_print_branches()
147 html("<tr class='nohover'><th class='left'>Branch</th>"
148 "<th class='left'>Idle</th>"
149 "<th class='left'>Author</th>"
150 "<th class='left'>Head commit</th></tr>\n");
151 for_each_branch_ref(cgit_print_branch_cb, NULL);
154 static void cgit_print_tags()
157 for_each_tag_ref(cgit_print_tag_cb, NULL);
160 static void cgit_print_archives()
163 for_each_ref(cgit_print_archive_cb, NULL);
168 void cgit_print_summary()
170 html("<div id='summary'>");
171 cgit_print_archives();
173 html_txt(cgit_repo->name);
175 html_txt(cgit_repo->desc);
177 if (cgit_repo->readme)
178 html_include(cgit_repo->readme);
180 if (cgit_summary_log > 0)
181 cgit_print_log(cgit_query_head, 0, cgit_summary_log, NULL, NULL, 0);
182 html("<table class='list nowrap'>");
183 if (cgit_summary_log > 0)
184 html("<tr class='nohover'><td colspan='4'> </td></tr>");
185 cgit_print_branches();
186 html("<tr class='nohover'><td colspan='4'> </td></tr>");