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));
51 static void cgit_print_object_ref(struct object *obj)
53 char *page, *arg, *url;
55 if (obj->type == OBJ_COMMIT) {
56 cgit_commit_link(fmt("commit %s", sha1_to_hex(obj->sha1)), NULL, NULL,
57 cgit_query_head, sha1_to_hex(obj->sha1));
59 } else if (obj->type == OBJ_TREE) {
67 url = cgit_pageurl(cgit_query_repo, page,
68 fmt("%s=%s", arg, sha1_to_hex(obj->sha1)));
69 html_link_open(url, NULL, NULL);
70 htmlf("%s %s", typename(obj->type),
71 sha1_to_hex(obj->sha1));
75 static void print_tag_header()
77 html("<tr class='nohover'><th class='left'>Tag</th>"
78 "<th class='left'>Age</th>"
79 "<th class='left'>Author</th>"
80 "<th class='left'>Reference</th></tr>\n");
84 static int cgit_print_tag_cb(const char *refname, const unsigned char *sha1,
85 int flags, void *cb_data)
92 strncpy(buf, refname, sizeof(buf));
93 obj = parse_object(sha1);
96 if (obj->type == OBJ_TAG) {
97 tag = lookup_tag(sha1);
98 if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag)))
103 url = cgit_pageurl(cgit_query_repo, "view",
104 fmt("id=%s", sha1_to_hex(sha1)));
105 html_link_open(url, NULL, NULL);
109 if (info->tagger_date > 0)
110 cgit_print_age(info->tagger_date, -1, NULL);
115 cgit_print_object_ref(tag->tagged);
116 html("</td></tr>\n");
122 html("</td><td colspan='2'/><td>");
123 cgit_print_object_ref(obj);
124 html("</td></tr>\n");
129 static int cgit_print_archive_cb(const char *refname, const unsigned char *sha1,
130 int flags, void *cb_data)
133 struct taginfo *info;
136 unsigned char fileid[20];
138 if (prefixcmp(refname, "refs/archives"))
140 strncpy(buf, refname+14, sizeof(buf));
141 obj = parse_object(sha1);
144 if (obj->type == OBJ_TAG) {
145 tag = lookup_tag(sha1);
146 if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag)))
148 hashcpy(fileid, tag->tagged->sha1);
149 } else if (obj->type != OBJ_BLOB) {
152 hashcpy(fileid, sha1);
155 html("<table id='downloads'>");
156 html("<tr><th>Downloads</th></tr>");
160 url = cgit_pageurl(cgit_query_repo, "blob",
161 fmt("id=%s&path=%s", sha1_to_hex(fileid),
163 html_link_open(url, NULL, NULL);
170 static void cgit_print_branches()
172 html("<tr class='nohover'><th class='left'>Branch</th>"
173 "<th class='left'>Idle</th>"
174 "<th class='left'>Author</th>"
175 "<th class='left'>Head commit</th></tr>\n");
176 for_each_branch_ref(cgit_print_branch_cb, NULL);
179 static void cgit_print_tags()
182 for_each_tag_ref(cgit_print_tag_cb, NULL);
185 static void cgit_print_archives()
188 for_each_ref(cgit_print_archive_cb, NULL);
193 void cgit_print_summary()
195 html("<div id='summary'>");
196 cgit_print_archives();
198 html_txt(cgit_repo->name);
200 html_txt(cgit_repo->desc);
202 if (cgit_repo->readme)
203 html_include(cgit_repo->readme);
205 if (cgit_summary_log > 0)
206 cgit_print_log(cgit_query_head, 0, cgit_summary_log, NULL, NULL, 0);
207 html("<table class='list nowrap'>");
208 if (cgit_summary_log > 0)
209 html("<tr class='nohover'><td colspan='4'> </td></tr>");
210 cgit_print_branches();
211 html("<tr class='nohover'><td colspan='4'> </td></tr>");