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 if (commit && !parse_commit(commit)){
23 info = cgit_parse_commit(commit);
25 url = cgit_pageurl(cgit_query_repo, "log",
26 fmt("h=%s", refname));
27 html_link_open(url, NULL, NULL);
31 cgit_print_age(commit->date, -1, NULL);
33 html_txt(info->author);
35 url = cgit_pageurl(cgit_query_repo, "commit",
36 fmt("h=%s", sha1_to_hex(sha1)));
37 html_link_open(url, NULL, NULL);
38 html_ntxt(cgit_max_msg_len, info->subject);
41 cgit_free_commitinfo(info);
45 html("</td><td colspan='3'>");
46 htmlf("*** bad ref %s ***", sha1_to_hex(sha1));
53 static void cgit_print_object_ref(struct object *obj)
55 char *page, *arg, *url;
57 if (obj->type == OBJ_COMMIT) {
60 } else if (obj->type == OBJ_TREE) {
68 url = cgit_pageurl(cgit_query_repo, page,
69 fmt("%s=%s", arg, sha1_to_hex(obj->sha1)));
70 html_link_open(url, NULL, NULL);
71 htmlf("%s %s", typename(obj->type),
72 sha1_to_hex(obj->sha1));
76 static void print_tag_header()
78 html("<tr class='nohover'><th class='left'>Tag</th>"
79 "<th class='left'>Age</th>"
80 "<th class='left'>Author</th>"
81 "<th class='left'>Reference</th></tr>\n");
85 static int cgit_print_tag_cb(const char *refname, const unsigned char *sha1,
86 int flags, void *cb_data)
93 strncpy(buf, refname, sizeof(buf));
94 obj = parse_object(sha1);
97 if (obj->type == OBJ_TAG) {
98 tag = lookup_tag(sha1);
99 if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag)))
104 url = cgit_pageurl(cgit_query_repo, "view",
105 fmt("id=%s", sha1_to_hex(sha1)));
106 html_link_open(url, NULL, NULL);
110 if (info->tagger_date > 0)
111 cgit_print_age(info->tagger_date, -1, NULL);
116 cgit_print_object_ref(tag->tagged);
117 html("</td></tr>\n");
123 html("</td><td colspan='2'/><td>");
124 cgit_print_object_ref(obj);
125 html("</td></tr>\n");
130 static int cgit_print_archive_cb(const char *refname, const unsigned char *sha1,
131 int flags, void *cb_data)
134 struct taginfo *info;
137 unsigned char fileid[20];
139 if (prefixcmp(refname, "refs/archives"))
141 strncpy(buf, refname+14, sizeof(buf));
142 obj = parse_object(sha1);
145 if (obj->type == OBJ_TAG) {
146 tag = lookup_tag(sha1);
147 if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag)))
149 hashcpy(fileid, tag->tagged->sha1);
150 } else if (obj->type != OBJ_BLOB) {
153 hashcpy(fileid, sha1);
157 html("<tr><th>Downloads</th></tr>");
161 url = cgit_pageurl(cgit_query_repo, "blob",
162 fmt("id=%s&path=%s", sha1_to_hex(fileid),
164 html_link_open(url, NULL, NULL);
171 static void cgit_print_branches()
173 html("<tr class='nohover'><th class='left'>Branch</th>"
174 "<th class='left'>Idle</th>"
175 "<th class='left'>Author</th>"
176 "<th class='left'>Head commit</th></tr>\n");
177 for_each_branch_ref(cgit_print_branch_cb, NULL);
180 static void cgit_print_tags()
183 for_each_tag_ref(cgit_print_tag_cb, NULL);
186 static void cgit_print_archives()
189 for_each_ref(cgit_print_archive_cb, NULL);
194 void cgit_print_summary()
196 html("<table class='list nowrap'>");
197 html("<tr class='nohover'><td id='summary' colspan='3'>");
199 html_txt(cgit_repo->name);
201 html_txt(cgit_repo->desc);
203 html("</td><td id='archivelist'>");
204 cgit_print_archives();
206 cgit_print_branches();
207 html("<tr class='nohover'><td colspan='4'> </td></tr>");