]> git.cameronkatri.com Git - cgit.git/blob - ui-commit.c
Move cgit_print_date into ui-shared, reuse in ui-summary
[cgit.git] / ui-commit.c
1 #include "cgit.h"
2
3 void cgit_print_commit(const char *hex)
4 {
5 struct commit *commit;
6 struct commitinfo *info;
7 struct commit_list *p;
8 unsigned long size;
9 char type[20];
10 char *buf;
11
12 unsigned char sha1[20];
13
14 if (get_sha1(hex, sha1)) {
15 cgit_print_error(fmt("Bad object id: %s", hex));
16 return;
17 }
18
19 buf = read_sha1_file(sha1, type, &size);
20 if (!buf) {
21 cgit_print_error(fmt("Bad object reference: %s", hex));
22 return;
23 }
24
25 commit = lookup_commit(sha1);
26 if (!commit) {
27 cgit_print_error(fmt("Bad commit reference: %s", hex));
28 return;
29 }
30
31 commit->buffer = buf;
32 if (parse_commit_buffer(commit, buf, size)) {
33 cgit_print_error(fmt("Malformed commit buffer: %s", hex));
34 return;
35 }
36
37 info = cgit_parse_commit(commit);
38
39 html("<table class='commit-info'>\n");
40 html("<tr><th>author</th><td colspan='2'>");
41 html_txt(info->author);
42 html("</td></tr>\n");
43 html("<tr><th>committer</th><td>");
44 html_txt(info->committer);
45 html("</td><td class='right'>");
46 cgit_print_date(commit->date);
47 html("</td></tr>\n");
48 html("<tr><th>tree</th><td colspan='2' class='sha1'><a href='");
49 html_attr(cgit_pageurl(cgit_query_repo, "tree", fmt("id=%s", sha1_to_hex(commit->tree->object.sha1))));
50 htmlf("'>%s</a></td></tr>\n", sha1_to_hex(commit->tree->object.sha1));
51
52 for (p = commit->parents; p ; p = p->next) {
53 html("<tr><th>parent</th><td colspan='2' class='sha1'><a href='");
54 html_attr(cgit_pageurl(cgit_query_repo, "commit", fmt("id=%s", sha1_to_hex(p->item->object.sha1))));
55 htmlf("'>%s</a></td></tr>\n",
56 sha1_to_hex(p->item->object.sha1));
57 }
58 html("</table>\n");
59 html("<div class='commit-subject'>");
60 html_txt(info->subject);
61 html("</div>");
62 html("<div class='commit-msg'>");
63 html_txt(info->msg);
64 html("</div>");
65 free(info->author);
66 free(info->committer);
67 free(info->subject);
68 free(info);
69 }