diff options
author | Lars Hjemli <hjemli@gmail.com> | 2006-12-16 08:19:56 (JST) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2006-12-16 08:19:56 (JST) |
commit | 9a8f88658d51aeb86a79ac1121de13562ad2601f (patch) | |
tree | 8724d9477efe887e0b851b567e74554e75761cc7 /ui-commit.c | |
parent | 2101e26fd68f816e77de62b93df4c32fd1110d0c (diff) | |
download | cgit-9a8f88658d51aeb86a79ac1121de13562ad2601f.zip cgit-9a8f88658d51aeb86a79ac1121de13562ad2601f.tar.gz |
Add ui-commit.c + misc ui cleanups
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
Diffstat (limited to 'ui-commit.c')
-rw-r--r-- | ui-commit.c | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/ui-commit.c b/ui-commit.c new file mode 100644 index 0000000..1c0e7e5 --- /dev/null +++ b/ui-commit.c | |||
@@ -0,0 +1,80 @@ | |||
1 | #include "cgit.h" | ||
2 | |||
3 | void cgit_print_date(unsigned long secs) | ||
4 | { | ||
5 | char buf[32]; | ||
6 | struct tm *time; | ||
7 | |||
8 | time = gmtime(&secs); | ||
9 | strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", time); | ||
10 | html_txt(buf); | ||
11 | |||
12 | } | ||
13 | |||
14 | void cgit_print_commit(const char *hex) | ||
15 | { | ||
16 | struct commit *commit; | ||
17 | struct commitinfo *info; | ||
18 | struct commit_list *p; | ||
19 | unsigned long size; | ||
20 | char type[20]; | ||
21 | char *buf; | ||
22 | |||
23 | unsigned char sha1[20]; | ||
24 | |||
25 | if (get_sha1(hex, sha1)) { | ||
26 | cgit_print_error(fmt("Bad object id: %s", hex)); | ||
27 | return; | ||
28 | } | ||
29 | |||
30 | buf = read_sha1_file(sha1, type, &size); | ||
31 | if (!buf) { | ||
32 | cgit_print_error(fmt("Bad object reference: %s", hex)); | ||
33 | return; | ||
34 | } | ||
35 | |||
36 | commit = lookup_commit(sha1); | ||
37 | if (!commit) { | ||
38 | cgit_print_error(fmt("Bad commit reference: %s", hex)); | ||
39 | return; | ||
40 | } | ||
41 | |||
42 | commit->buffer = buf; | ||
43 | if (parse_commit_buffer(commit, buf, size)) { | ||
44 | cgit_print_error(fmt("Malformed commit buffer: %s", hex)); | ||
45 | return; | ||
46 | } | ||
47 | |||
48 | info = cgit_parse_commit(commit); | ||
49 | |||
50 | html("<table class='commit-info'>\n"); | ||
51 | html("<tr><th>author</th><td colspan='2'>"); | ||
52 | html_txt(info->author); | ||
53 | html("</td></tr>\n"); | ||
54 | html("<tr><th>committer</th><td>"); | ||
55 | html_txt(info->committer); | ||
56 | html("</td><td class='right'>"); | ||
57 | cgit_print_date(commit->date); | ||
58 | html("</td></tr>\n"); | ||
59 | html("<tr><th>tree</th><td colspan='2' class='sha1'><a href='"); | ||
60 | html_attr(cgit_pageurl(cgit_query_repo, "tree", fmt("id=%s", sha1_to_hex(commit->tree->object.sha1)))); | ||
61 | htmlf("'>%s</a></td></tr>\n", sha1_to_hex(commit->tree->object.sha1)); | ||
62 | |||
63 | for (p = commit->parents; p ; p = p->next) { | ||
64 | html("<tr><th>parent</th><td colspan='2' class='sha1'><a href='"); | ||
65 | html_attr(cgit_pageurl(cgit_query_repo, "commit", fmt("id=%s", sha1_to_hex(p->item->object.sha1)))); | ||
66 | htmlf("'>%s</a></td></tr>\n", | ||
67 | sha1_to_hex(p->item->object.sha1)); | ||
68 | } | ||
69 | html("</table>\n"); | ||
70 | html("<div class='commit-subject'>"); | ||
71 | html_txt(info->subject); | ||
72 | html("</div>"); | ||
73 | html("<div class='commit-msg'>"); | ||
74 | html_txt(info->msg); | ||
75 | html("</div>"); | ||
76 | free(info->author); | ||
77 | free(info->committer); | ||
78 | free(info->subject); | ||
79 | free(info); | ||
80 | } | ||