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)
11 static int cgit_print_branch_cb(const char *refname, const unsigned char *sha1,
12 int flags, void *cb_data)
14 struct commit *commit;
15 struct commitinfo *info;
18 strncpy(buf, refname, sizeof(buf));
19 commit = lookup_commit(sha1);
20 if (commit && !parse_commit(commit)){
21 info = cgit_parse_commit(commit);
23 url = cgit_pageurl(cgit_query_repo, "log",
24 fmt("h=%s", refname));
25 html_link_open(url, NULL, NULL);
29 cgit_print_date(commit->date);
31 html_txt(info->author);
33 url = cgit_pageurl(cgit_query_repo, "commit",
34 fmt("id=%s", sha1_to_hex(sha1)));
35 html_link_open(url, NULL, NULL);
36 html_ntxt(cgit_max_msg_len, info->subject);
39 cgit_free_commitinfo(info);
43 html("</td><td colspan='3'>");
44 htmlf("*** bad ref %s ***", sha1_to_hex(sha1));
51 static void cgit_print_object_ref(struct object *obj)
55 if (obj->type == OBJ_COMMIT)
57 else if (obj->type == OBJ_TREE)
62 url = cgit_pageurl(cgit_query_repo, page,
63 fmt("id=%s", sha1_to_hex(obj->sha1)));
64 html_link_open(url, NULL, NULL);
65 htmlf("%s %s", type_names[obj->type],
66 sha1_to_hex(obj->sha1));
70 static int cgit_print_tag_cb(const char *refname, const unsigned char *sha1,
71 int flags, void *cb_data)
78 strncpy(buf, refname, sizeof(buf));
79 obj = parse_object(sha1);
82 if (obj->type == OBJ_TAG) {
83 tag = lookup_tag(sha1);
84 if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag)))
87 url = cgit_pageurl(cgit_query_repo, "view",
88 fmt("id=%s", sha1_to_hex(sha1)));
89 html_link_open(url, NULL, NULL);
93 if (info->tagger_date > 0)
94 cgit_print_date(info->tagger_date);
99 cgit_print_object_ref(tag->tagged);
100 html("</td></tr>\n");
104 html("</td><td colspan='2'/><td>");
105 cgit_print_object_ref(obj);
106 html("</td></tr>\n");
111 static void cgit_print_branches()
113 html("<tr class='nohover'><th class='left'>Branch</th>"
114 "<th class='left'>Updated</th>"
115 "<th class='left'>Author</th>"
116 "<th class='left'>Head commit</th></tr>\n");
117 for_each_branch_ref(cgit_print_branch_cb, NULL);
120 static void cgit_print_tags()
122 html("<tr class='nohover'><th class='left'>Tag</th>"
123 "<th class='left'>Created</th>"
124 "<th class='left'>Author</th>"
125 "<th class='left'>Reference</th></tr>\n");
126 for_each_tag_ref(cgit_print_tag_cb, NULL);
129 void cgit_print_summary()
132 html(cgit_repo->name);
134 html(cgit_repo->desc);
136 html("<table class='list nowrap'>");
137 cgit_print_branches();
138 html("<tr class='nohover'><td colspan='4'> </td></tr>");