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
;
29 if (get_oid(hex
, &oid
)) {
30 cgit_print_error_page(400, "Bad request",
31 "Bad object id: %s", hex
);
34 commit
= lookup_commit_reference(the_repository
, &oid
);
36 cgit_print_error_page(404, "Not found",
37 "Bad commit reference: %s", hex
);
40 info
= cgit_parse_commit(commit
);
42 format_display_notes(&oid
, ¬es
, PAGE_ENCODING
, 1);
44 load_ref_decorations(NULL
, DECORATE_FULL_REFS
);
46 ctx
.page
.title
= fmtalloc("%s - %s", info
->subject
, ctx
.page
.title
);
47 cgit_print_layout_start();
48 cgit_print_diff_ctrls();
49 html("<table summary='commit info' class='commit-info'>\n");
50 html("<tr><th>author</th><td>");
51 cgit_open_filter(ctx
.repo
->email_filter
, info
->author_email
, "commit");
52 html_txt(info
->author
);
53 if (!ctx
.cfg
.noplainemail
) {
55 html_txt(info
->author_email
);
57 cgit_close_filter(ctx
.repo
->email_filter
);
58 html("</td><td class='right'>");
59 html_txt(show_date(info
->author_date
, info
->author_tz
,
60 cgit_date_mode(DATE_ISO8601
)));
62 html("<tr><th>committer</th><td>");
63 cgit_open_filter(ctx
.repo
->email_filter
, info
->committer_email
, "commit");
64 html_txt(info
->committer
);
65 if (!ctx
.cfg
.noplainemail
) {
67 html_txt(info
->committer_email
);
69 cgit_close_filter(ctx
.repo
->email_filter
);
70 html("</td><td class='right'>");
71 html_txt(show_date(info
->committer_date
, info
->committer_tz
,
72 cgit_date_mode(DATE_ISO8601
)));
74 html("<tr><th>commit</th><td colspan='2' class='oid'>");
75 tmp
= oid_to_hex(&commit
->object
.oid
);
76 cgit_commit_link(tmp
, NULL
, NULL
, ctx
.qry
.head
, tmp
, prefix
);
78 cgit_patch_link("patch", NULL
, NULL
, NULL
, tmp
, prefix
);
79 html(")</td></tr>\n");
80 html("<tr><th>tree</th><td colspan='2' class='oid'>");
82 cgit_tree_link(oid_to_hex(get_commit_tree_oid(commit
)), NULL
, NULL
,
83 ctx
.qry
.head
, tmp
, NULL
);
86 cgit_tree_link(prefix
, NULL
, NULL
, ctx
.qry
.head
, tmp
, prefix
);
90 for (p
= commit
->parents
; p
; p
= p
->next
) {
91 parent
= lookup_commit_reference(the_repository
, &p
->item
->object
.oid
);
93 html("<tr><td colspan='3'>");
94 cgit_print_error("Error reading parent commit");
98 html("<tr><th>parent</th>"
99 "<td colspan='2' class='oid'>");
100 tmp
= tmp2
= oid_to_hex(&p
->item
->object
.oid
);
101 if (ctx
.repo
->enable_subject_links
) {
102 parent_info
= cgit_parse_commit(parent
);
103 tmp2
= parent_info
->subject
;
105 cgit_commit_link(tmp2
, NULL
, NULL
, ctx
.qry
.head
, tmp
, prefix
);
107 cgit_diff_link("diff", NULL
, NULL
, ctx
.qry
.head
, hex
,
108 oid_to_hex(&p
->item
->object
.oid
), prefix
);
112 if (ctx
.repo
->snapshots
) {
113 html("<tr><th>download</th><td colspan='2' class='oid'>");
114 cgit_print_snapshot_links(ctx
.repo
, hex
, "<br/>");
118 html("<div class='commit-subject'>");
119 cgit_open_filter(ctx
.repo
->commit_filter
);
120 html_txt(info
->subject
);
121 cgit_close_filter(ctx
.repo
->commit_filter
);
122 show_commit_decorations(commit
);
124 html("<div class='commit-msg'>");
125 cgit_open_filter(ctx
.repo
->commit_filter
);
127 cgit_close_filter(ctx
.repo
->commit_filter
);
129 if (notes
.len
!= 0) {
130 html("<div class='notes-header'>Notes</div>");
131 html("<div class='notes'>");
132 cgit_open_filter(ctx
.repo
->commit_filter
);
134 cgit_close_filter(ctx
.repo
->commit_filter
);
136 html("<div class='notes-footer'></div>");
140 tmp
= oid_to_hex(&commit
->parents
->item
->object
.oid
);
143 cgit_print_diff(ctx
.qry
.oid
, tmp
, prefix
, 0, 0);
145 strbuf_release(¬es
);
146 cgit_free_commitinfo(info
);
147 cgit_print_layout_end();