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 void cgit_print_branch(struct refinfo *ref)
15 struct commit *commit;
16 struct commitinfo *info;
17 char *name = (char *)ref->refname;
19 commit = lookup_commit(ref->object->sha1);
20 // object is not really parsed at this point, because of some fallout
21 // from previous calls to git functions in cgit_print_log()
22 commit->object.parsed = 0;
23 if (commit && !parse_commit(commit)){
24 info = cgit_parse_commit(commit);
26 cgit_log_link(name, NULL, NULL, name, NULL, NULL, 0);
28 cgit_print_age(commit->date, -1, NULL);
30 html_txt(info->author);
32 cgit_commit_link(info->subject, NULL, NULL, name, NULL);
34 cgit_free_commitinfo(info);
38 html("</td><td colspan='3'>");
39 htmlf("*** bad ref %s ***", sha1_to_hex(ref->object->sha1));
44 static void print_tag_header()
46 html("<tr class='nohover'><th class='left'>Tag</th>"
47 "<th class='left'>Age</th>"
48 "<th class='left'>Author</th>"
49 "<th class='left'>Reference</th></tr>\n");
53 static int cgit_print_tag_cb(const char *refname, const unsigned char *sha1,
54 int flags, void *cb_data)
61 strncpy(buf, refname, sizeof(buf));
62 obj = parse_object(sha1);
65 if (obj->type == OBJ_TAG) {
66 tag = lookup_tag(sha1);
67 if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag)))
72 url = cgit_pageurl(cgit_query_repo, "tag",
73 fmt("id=%s", refname));
74 html_link_open(url, NULL, NULL);
78 if (info->tagger_date > 0)
79 cgit_print_age(info->tagger_date, -1, NULL);
84 cgit_object_link(tag->tagged);
91 html("</td><td colspan='2'/><td>");
92 cgit_object_link(obj);
98 static int cgit_print_archive_cb(const char *refname, const unsigned char *sha1,
99 int flags, void *cb_data)
102 struct taginfo *info;
105 unsigned char fileid[20];
107 if (prefixcmp(refname, "refs/archives"))
109 strncpy(buf, refname+14, sizeof(buf));
110 obj = parse_object(sha1);
113 if (obj->type == OBJ_TAG) {
114 tag = lookup_tag(sha1);
115 if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag)))
117 hashcpy(fileid, tag->tagged->sha1);
118 } else if (obj->type != OBJ_BLOB) {
121 hashcpy(fileid, sha1);
124 html("<table id='downloads'>");
125 html("<tr><th>Downloads</th></tr>");
129 url = cgit_pageurl(cgit_query_repo, "blob",
130 fmt("id=%s&path=%s", sha1_to_hex(fileid),
132 html_link_open(url, NULL, NULL);
139 static void cgit_print_branches()
144 html("<tr class='nohover'><th class='left'>Branch</th>"
145 "<th class='left'>Idle</th>"
146 "<th class='left'>Author</th>"
147 "<th class='left'>Head commit</th></tr>\n");
150 list.alloc = list.count = 0;
151 for_each_branch_ref(cgit_refs_cb, &list);
152 for(i=0; i<list.count; i++)
153 cgit_print_branch(list.refs[i]);
156 static void cgit_print_tags()
159 for_each_tag_ref(cgit_print_tag_cb, NULL);
162 static void cgit_print_archives()
165 for_each_ref(cgit_print_archive_cb, NULL);
170 void cgit_print_summary()
172 html("<div id='summary'>");
173 cgit_print_archives();
175 html_txt(cgit_repo->name);
177 html_txt(cgit_repo->desc);
179 if (cgit_repo->readme)
180 html_include(cgit_repo->readme);
182 if (cgit_summary_log > 0)
183 cgit_print_log(cgit_query_head, 0, cgit_summary_log, NULL, NULL, 0);
184 html("<table class='list nowrap'>");
185 if (cgit_summary_log > 0)
186 html("<tr class='nohover'><td colspan='4'> </td></tr>");
187 cgit_print_branches();
188 html("<tr class='nohover'><td colspan='4'> </td></tr>");