]>
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)
11 #include "ui-shared.h"
15 void cgit_print_commit(char *hex
, const char *prefix
)
17 struct commit
*commit
, *parent
;
18 struct commitinfo
*info
, *parent_info
;
19 struct commit_list
*p
;
20 struct strbuf notes
= STRBUF_INIT
;
21 unsigned char sha1
[20];
28 if (get_sha1(hex
, sha1
)) {
29 cgit_print_error(fmt("Bad object id: %s", hex
));
32 commit
= lookup_commit_reference(sha1
);
34 cgit_print_error(fmt("Bad commit reference: %s", hex
));
37 info
= cgit_parse_commit(commit
);
39 format_note(NULL
, sha1
, ¬es
, PAGE_ENCODING
, 0);
41 load_ref_decorations(DECORATE_FULL_REFS
);
43 cgit_print_diff_ctrls();
44 html("<table summary='commit info' class='commit-info'>\n");
45 html("<tr><th>author</th><td>");
46 html_txt(info
->author
);
47 if (!ctx
.cfg
.noplainemail
) {
49 html_txt(info
->author_email
);
51 html("</td><td class='right'>");
52 cgit_print_date(info
->author_date
, FMT_LONGDATE
, ctx
.cfg
.local_time
);
54 html("<tr><th>committer</th><td>");
55 html_txt(info
->committer
);
56 if (!ctx
.cfg
.noplainemail
) {
58 html_txt(info
->committer_email
);
60 html("</td><td class='right'>");
61 cgit_print_date(info
->committer_date
, FMT_LONGDATE
, ctx
.cfg
.local_time
);
63 html("<tr><th>commit</th><td colspan='2' class='sha1'>");
64 tmp
= sha1_to_hex(commit
->object
.sha1
);
65 cgit_commit_link(tmp
, NULL
, NULL
, ctx
.qry
.head
, tmp
, prefix
, 0);
67 cgit_patch_link("patch", NULL
, NULL
, NULL
, tmp
, prefix
);
68 html(")</td></tr>\n");
69 html("<tr><th>tree</th><td colspan='2' class='sha1'>");
71 cgit_tree_link(sha1_to_hex(commit
->tree
->object
.sha1
), NULL
, NULL
,
72 ctx
.qry
.head
, tmp
, NULL
);
75 cgit_tree_link(prefix
, NULL
, NULL
, ctx
.qry
.head
, tmp
, prefix
);
78 for (p
= commit
->parents
; p
; p
= p
->next
) {
79 parent
= lookup_commit_reference(p
->item
->object
.sha1
);
81 html("<tr><td colspan='3'>");
82 cgit_print_error("Error reading parent commit");
86 html("<tr><th>parent</th>"
87 "<td colspan='2' class='sha1'>");
88 tmp
= tmp2
= sha1_to_hex(p
->item
->object
.sha1
);
89 if (ctx
.repo
->enable_subject_links
) {
90 parent_info
= cgit_parse_commit(parent
);
91 tmp2
= parent_info
->subject
;
93 cgit_commit_link(tmp2
, NULL
, NULL
, ctx
.qry
.head
, tmp
, prefix
, 0);
95 cgit_diff_link("diff", NULL
, NULL
, ctx
.qry
.head
, hex
,
96 sha1_to_hex(p
->item
->object
.sha1
), prefix
, 0);
100 if (ctx
.repo
->snapshots
) {
101 html("<tr><th>download</th><td colspan='2' class='sha1'>");
102 cgit_print_snapshot_links(ctx
.qry
.repo
, ctx
.qry
.head
,
103 hex
, ctx
.repo
->snapshots
);
107 html("<div class='commit-subject'>");
108 if (ctx
.repo
->commit_filter
)
109 cgit_open_filter(ctx
.repo
->commit_filter
, ctx
.repo
);
110 html_txt(info
->subject
);
111 if (ctx
.repo
->commit_filter
)
112 cgit_close_filter(ctx
.repo
->commit_filter
);
113 show_commit_decorations(commit
);
115 html("<div class='commit-msg'>");
116 if (ctx
.repo
->commit_filter
)
117 cgit_open_filter(ctx
.repo
->commit_filter
, ctx
.repo
);
119 if (ctx
.repo
->commit_filter
)
120 cgit_close_filter(ctx
.repo
->commit_filter
);
122 if (notes
.len
!= 0) {
123 html("<div class='notes-header'>Notes</div>");
124 html("<div class='notes'>");
125 if (ctx
.repo
->commit_filter
)
126 cgit_open_filter(ctx
.repo
->commit_filter
, ctx
.repo
);
128 if (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);
140 strbuf_release(¬es
);
141 cgit_free_commitinfo(info
);