1 /* ui-commit.c: generate commit view
3 * Copyright (C) 2006-2014 cgit Development Team <cgit@lists.zx2c4.com>
5 * Licensed under GNU General Public License v2
6 * (see COPYING for full license text)
10 #include "ui-commit.h"
12 #include "ui-shared.h"
16 void cgit_print_commit(char *hex
, const char *prefix
)
18 struct commit
*commit
, *parent
;
19 struct commitinfo
*info
, *parent_info
;
20 struct commit_list
*p
;
21 struct strbuf notes
= STRBUF_INIT
;
22 unsigned char sha1
[20];
29 if (get_sha1(hex
, sha1
)) {
30 cgit_print_error("Bad object id: %s", hex
);
33 commit
= lookup_commit_reference(sha1
);
35 cgit_print_error("Bad commit reference: %s", hex
);
38 info
= cgit_parse_commit(commit
);
40 format_display_notes(sha1
, ¬es
, PAGE_ENCODING
, 0);
42 load_ref_decorations(DECORATE_FULL_REFS
);
44 cgit_print_diff_ctrls();
45 html("<table summary='commit info' class='commit-info'>\n");
46 html("<tr><th>author</th><td>");
47 cgit_open_filter(ctx
.repo
->email_filter
, info
->author_email
);
48 html_txt(info
->author
);
49 if (!ctx
.cfg
.noplainemail
) {
51 html_txt(info
->author_email
);
53 cgit_close_filter(ctx
.repo
->email_filter
);
54 html("</td><td class='right'>");
55 cgit_print_date(info
->author_date
, FMT_LONGDATE
, ctx
.cfg
.local_time
);
57 html("<tr><th>committer</th><td>");
58 cgit_open_filter(ctx
.repo
->email_filter
, info
->committer_email
);
59 html_txt(info
->committer
);
60 if (!ctx
.cfg
.noplainemail
) {
62 html_txt(info
->committer_email
);
64 cgit_close_filter(ctx
.repo
->email_filter
);
65 html("</td><td class='right'>");
66 cgit_print_date(info
->committer_date
, FMT_LONGDATE
, ctx
.cfg
.local_time
);
68 html("<tr><th>commit</th><td colspan='2' class='sha1'>");
69 tmp
= sha1_to_hex(commit
->object
.sha1
);
70 cgit_commit_link(tmp
, NULL
, NULL
, ctx
.qry
.head
, tmp
, prefix
, 0);
72 cgit_patch_link("patch", NULL
, NULL
, NULL
, tmp
, prefix
);
73 html(")</td></tr>\n");
74 html("<tr><th>tree</th><td colspan='2' class='sha1'>");
76 cgit_tree_link(sha1_to_hex(commit
->tree
->object
.sha1
), NULL
, NULL
,
77 ctx
.qry
.head
, tmp
, NULL
);
80 cgit_tree_link(prefix
, NULL
, NULL
, ctx
.qry
.head
, tmp
, prefix
);
84 for (p
= commit
->parents
; p
; p
= p
->next
) {
85 parent
= lookup_commit_reference(p
->item
->object
.sha1
);
87 html("<tr><td colspan='3'>");
88 cgit_print_error("Error reading parent commit");
92 html("<tr><th>parent</th>"
93 "<td colspan='2' class='sha1'>");
94 tmp
= tmp2
= sha1_to_hex(p
->item
->object
.sha1
);
95 if (ctx
.repo
->enable_subject_links
) {
96 parent_info
= cgit_parse_commit(parent
);
97 tmp2
= parent_info
->subject
;
99 cgit_commit_link(tmp2
, NULL
, NULL
, ctx
.qry
.head
, tmp
, prefix
, 0);
101 cgit_diff_link("diff", NULL
, NULL
, ctx
.qry
.head
, hex
,
102 sha1_to_hex(p
->item
->object
.sha1
), prefix
, 0);
106 if (ctx
.repo
->snapshots
) {
107 html("<tr><th>download</th><td colspan='2' class='sha1'>");
108 cgit_print_snapshot_links(ctx
.qry
.repo
, ctx
.qry
.head
,
109 hex
, ctx
.repo
->snapshots
);
113 html("<div class='commit-subject'>");
114 cgit_open_filter(ctx
.repo
->commit_filter
);
115 html_txt(info
->subject
);
116 cgit_close_filter(ctx
.repo
->commit_filter
);
117 show_commit_decorations(commit
);
119 html("<div class='commit-msg'>");
120 cgit_open_filter(ctx
.repo
->commit_filter
);
122 cgit_close_filter(ctx
.repo
->commit_filter
);
124 if (notes
.len
!= 0) {
125 html("<div class='notes-header'>Notes</div>");
126 html("<div class='notes'>");
127 cgit_open_filter(ctx
.repo
->commit_filter
);
129 cgit_close_filter(ctx
.repo
->commit_filter
);
131 html("<div class='notes-footer'></div>");
135 tmp
= sha1_to_hex(commit
->parents
->item
->object
.sha1
);
138 cgit_print_diff(ctx
.qry
.sha1
, tmp
, prefix
, 0, 0);
140 strbuf_release(¬es
);
141 cgit_free_commitinfo(info
);