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.hash);
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.hash, ¬es, PAGE_ENCODING, 0);
44 load_ref_decorations(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->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.hash);
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.qry.repo, ctx.qry.head,
114 hex, ctx.repo->snapshots);
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.sha1, tmp, prefix, 0, 0);
145 strbuf_release(¬es);
146 cgit_free_commitinfo(info);
147 cgit_print_layout_end();