]>
git.cameronkatri.com Git - cgit.git/blob - ui-commit.c
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(&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
, 0);
44 load_ref_decorations(NULL
, DECORATE_FULL_REFS
);
46 cgit_print_layout_start();
47 cgit_print_diff_ctrls();
48 html("<table summary='commit info' class='commit-info'>\n");
49 html("<tr><th>author</th><td>");
50 cgit_open_filter(ctx
.repo
->email_filter
, info
->author_email
, "commit");
51 html_txt(info
->author
);
52 if (!ctx
.cfg
.noplainemail
) {
54 html_txt(info
->author_email
);
56 cgit_close_filter(ctx
.repo
->email_filter
);
57 html("</td><td class='right'>");
58 html_txt(show_date(info
->author_date
, info
->author_tz
,
59 cgit_date_mode(DATE_ISO8601
)));
61 html("<tr><th>committer</th><td>");
62 cgit_open_filter(ctx
.repo
->email_filter
, info
->committer_email
, "commit");
63 html_txt(info
->committer
);
64 if (!ctx
.cfg
.noplainemail
) {
66 html_txt(info
->committer_email
);
68 cgit_close_filter(ctx
.repo
->email_filter
);
69 html("</td><td class='right'>");
70 html_txt(show_date(info
->committer_date
, info
->committer_tz
,
71 cgit_date_mode(DATE_ISO8601
)));
73 html("<tr><th>commit</th><td colspan='2' class='sha1'>");
74 tmp
= oid_to_hex(&commit
->object
.oid
);
75 cgit_commit_link(tmp
, NULL
, NULL
, ctx
.qry
.head
, tmp
, prefix
);
77 cgit_patch_link("patch", NULL
, NULL
, NULL
, tmp
, prefix
);
78 html(")</td></tr>\n");
79 html("<tr><th>tree</th><td colspan='2' class='sha1'>");
81 cgit_tree_link(oid_to_hex(&commit
->maybe_tree
->object
.oid
), NULL
, NULL
,
82 ctx
.qry
.head
, tmp
, NULL
);
85 cgit_tree_link(prefix
, NULL
, NULL
, ctx
.qry
.head
, tmp
, prefix
);
89 for (p
= commit
->parents
; p
; p
= p
->next
) {
90 parent
= lookup_commit_reference(&p
->item
->object
.oid
);
92 html("<tr><td colspan='3'>");
93 cgit_print_error("Error reading parent commit");
97 html("<tr><th>parent</th>"
98 "<td colspan='2' class='sha1'>");
99 tmp
= tmp2
= oid_to_hex(&p
->item
->object
.oid
);
100 if (ctx
.repo
->enable_subject_links
) {
101 parent_info
= cgit_parse_commit(parent
);
102 tmp2
= parent_info
->subject
;
104 cgit_commit_link(tmp2
, NULL
, NULL
, ctx
.qry
.head
, tmp
, prefix
);
106 cgit_diff_link("diff", NULL
, NULL
, ctx
.qry
.head
, hex
,
107 oid_to_hex(&p
->item
->object
.oid
), prefix
);
111 if (ctx
.repo
->snapshots
) {
112 html("<tr><th>download</th><td colspan='2' class='sha1'>");
113 cgit_print_snapshot_links(ctx
.repo
, hex
, "<br/>");
117 html("<div class='commit-subject'>");
118 cgit_open_filter(ctx
.repo
->commit_filter
);
119 html_txt(info
->subject
);
120 cgit_close_filter(ctx
.repo
->commit_filter
);
121 show_commit_decorations(commit
);
123 html("<div class='commit-msg'>");
124 cgit_open_filter(ctx
.repo
->commit_filter
);
126 cgit_close_filter(ctx
.repo
->commit_filter
);
128 if (notes
.len
!= 0) {
129 html("<div class='notes-header'>Notes</div>");
130 html("<div class='notes'>");
131 cgit_open_filter(ctx
.repo
->commit_filter
);
133 cgit_close_filter(ctx
.repo
->commit_filter
);
135 html("<div class='notes-footer'></div>");
139 tmp
= oid_to_hex(&commit
->parents
->item
->object
.oid
);
142 cgit_print_diff(ctx
.qry
.sha1
, tmp
, prefix
, 0, 0);
144 strbuf_release(¬es
);
145 cgit_free_commitinfo(info
);
146 cgit_print_layout_end();