]>
git.cameronkatri.com Git - cgit.git/blob - ui-commit.c
1 /* ui-commit.c: generate commit view
3 * Copyright (C) 2006 Lars Hjemli
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 html_txt(info
->author
);
48 if (!ctx
.cfg
.noplainemail
) {
50 html_txt(info
->author_email
);
52 html("</td><td class='right'>");
53 cgit_print_date(info
->author_date
, FMT_LONGDATE
, ctx
.cfg
.local_time
);
55 html("<tr><th>committer</th><td>");
56 html_txt(info
->committer
);
57 if (!ctx
.cfg
.noplainemail
) {
59 html_txt(info
->committer_email
);
61 html("</td><td class='right'>");
62 cgit_print_date(info
->committer_date
, FMT_LONGDATE
, ctx
.cfg
.local_time
);
64 html("<tr><th>commit</th><td colspan='2' class='sha1'>");
65 tmp
= sha1_to_hex(commit
->object
.sha1
);
66 cgit_commit_link(tmp
, NULL
, NULL
, ctx
.qry
.head
, tmp
, prefix
, 0);
68 cgit_patch_link("patch", NULL
, NULL
, NULL
, tmp
, prefix
);
69 html(")</td></tr>\n");
70 html("<tr><th>tree</th><td colspan='2' class='sha1'>");
72 cgit_tree_link(sha1_to_hex(commit
->tree
->object
.sha1
), NULL
, NULL
,
73 ctx
.qry
.head
, tmp
, NULL
);
76 cgit_tree_link(prefix
, NULL
, NULL
, ctx
.qry
.head
, tmp
, prefix
);
80 for (p
= commit
->parents
; p
; p
= p
->next
) {
81 parent
= lookup_commit_reference(p
->item
->object
.sha1
);
83 html("<tr><td colspan='3'>");
84 cgit_print_error("Error reading parent commit");
88 html("<tr><th>parent</th>"
89 "<td colspan='2' class='sha1'>");
90 tmp
= tmp2
= sha1_to_hex(p
->item
->object
.sha1
);
91 if (ctx
.repo
->enable_subject_links
) {
92 parent_info
= cgit_parse_commit(parent
);
93 tmp2
= parent_info
->subject
;
95 cgit_commit_link(tmp2
, NULL
, NULL
, ctx
.qry
.head
, tmp
, prefix
, 0);
97 cgit_diff_link("diff", NULL
, NULL
, ctx
.qry
.head
, hex
,
98 sha1_to_hex(p
->item
->object
.sha1
), prefix
, 0);
102 if (ctx
.repo
->snapshots
) {
103 html("<tr><th>download</th><td colspan='2' class='sha1'>");
104 cgit_print_snapshot_links(ctx
.qry
.repo
, ctx
.qry
.head
,
105 hex
, ctx
.repo
->snapshots
);
109 html("<div class='commit-subject'>");
110 if (ctx
.repo
->commit_filter
)
111 cgit_open_filter(ctx
.repo
->commit_filter
);
112 html_txt(info
->subject
);
113 if (ctx
.repo
->commit_filter
)
114 cgit_close_filter(ctx
.repo
->commit_filter
);
115 show_commit_decorations(commit
);
117 html("<div class='commit-msg'>");
118 if (ctx
.repo
->commit_filter
)
119 cgit_open_filter(ctx
.repo
->commit_filter
);
121 if (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 if (ctx
.repo
->commit_filter
)
128 cgit_open_filter(ctx
.repo
->commit_filter
);
130 if (ctx
.repo
->commit_filter
)
131 cgit_close_filter(ctx
.repo
->commit_filter
);
133 html("<div class='notes-footer'></div>");
137 tmp
= sha1_to_hex(commit
->parents
->item
->object
.sha1
);
140 cgit_print_diff(ctx
.qry
.sha1
, tmp
, prefix
, 0);
142 strbuf_release(¬es
);
143 cgit_free_commitinfo(info
);