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;
20 strncpy(buf, refname, sizeof(buf));
21 commit = lookup_commit(sha1);
22 // object is not really parsed at this point, because of some fallout
23 // from previous calls to git functions in cgit_print_log()
24 commit->object.parsed = 0;
25 if (commit && !parse_commit(commit)){
26 info = cgit_parse_commit(commit);
28 url = cgit_pageurl(cgit_query_repo, "log",
29 fmt("h=%s", refname));
30 html_link_open(url, NULL, NULL);
34 cgit_print_age(commit->date, -1, NULL);
36 html_txt(info->author);
38 url = cgit_pageurl(cgit_query_repo, "commit",
39 fmt("h=%s", sha1_to_hex(sha1)));
40 html_link_open(url, NULL, NULL);
41 html_ntxt(cgit_max_msg_len, info->subject);
44 cgit_free_commitinfo(info);
48 html("</td><td colspan='3'>");
49 htmlf("*** bad ref %s ***", sha1_to_hex(sha1));
56 static void cgit_print_object_ref(struct object *obj)
58 char *page, *arg, *url;
60 if (obj->type == OBJ_COMMIT) {
63 } else if (obj->type == OBJ_TREE) {
71 url = cgit_pageurl(cgit_query_repo, page,
72 fmt("%s=%s", arg, sha1_to_hex(obj->sha1)));
73 html_link_open(url, NULL, NULL);
74 htmlf("%s %s", typename(obj->type),
75 sha1_to_hex(obj->sha1));
79 static void print_tag_header()
81 html("<tr class='nohover'><th class='left'>Tag</th>"
82 "<th class='left'>Age</th>"
83 "<th class='left'>Author</th>"
84 "<th class='left'>Reference</th></tr>\n");
88 static int cgit_print_tag_cb(const char *refname, const unsigned char *sha1,
89 int flags, void *cb_data)
96 strncpy(buf, refname, sizeof(buf));
97 obj = parse_object(sha1);
100 if (obj->type == OBJ_TAG) {
101 tag = lookup_tag(sha1);
102 if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag)))
107 url = cgit_pageurl(cgit_query_repo, "view",
108 fmt("id=%s", sha1_to_hex(sha1)));
109 html_link_open(url, NULL, NULL);
113 if (info->tagger_date > 0)
114 cgit_print_age(info->tagger_date, -1, NULL);
119 cgit_print_object_ref(tag->tagged);
120 html("</td></tr>\n");
126 html("</td><td colspan='2'/><td>");
127 cgit_print_object_ref(obj);
128 html("</td></tr>\n");
133 static int cgit_print_archive_cb(const char *refname, const unsigned char *sha1,
134 int flags, void *cb_data)
137 struct taginfo *info;
140 unsigned char fileid[20];
142 if (prefixcmp(refname, "refs/archives"))
144 strncpy(buf, refname+14, sizeof(buf));
145 obj = parse_object(sha1);
148 if (obj->type == OBJ_TAG) {
149 tag = lookup_tag(sha1);
150 if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag)))
152 hashcpy(fileid, tag->tagged->sha1);
153 } else if (obj->type != OBJ_BLOB) {
156 hashcpy(fileid, sha1);
159 html("<table id='downloads'>");
160 html("<tr><th>Downloads</th></tr>");
164 url = cgit_pageurl(cgit_query_repo, "blob",
165 fmt("id=%s&path=%s", sha1_to_hex(fileid),
167 html_link_open(url, NULL, NULL);
174 static void cgit_print_branches()
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");
180 for_each_branch_ref(cgit_print_branch_cb, NULL);
183 static void cgit_print_tags()
186 for_each_tag_ref(cgit_print_tag_cb, NULL);
189 static void cgit_print_archives()
192 for_each_ref(cgit_print_archive_cb, NULL);
197 void cgit_print_summary()
199 html("<div id='summary'>");
200 cgit_print_archives();
202 html_txt(cgit_repo->name);
204 html_txt(cgit_repo->desc);
206 if (cgit_repo->readme)
207 html_include(cgit_repo->readme);
209 if (cgit_summary_log > 0)
210 cgit_print_log(cgit_query_head, 0, cgit_summary_log, NULL, NULL, 0);
211 html("<table class='list nowrap'>");
212 if (cgit_summary_log > 0)
213 html("<tr class='nohover'><td colspan='4'> </td></tr>");
214 cgit_print_branches();
215 html("<tr class='nohover'><td colspan='4'> </td></tr>");