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;
22 unsigned char sha1[20];
29 if (get_sha1(hex, sha1)) {
30 cgit_print_error_page(400, "Bad request",
31 "Bad object id: %s", hex);
34 commit = lookup_commit_reference(sha1);
36 cgit_print_error_page(404, "Not found",
37 "Bad commit reference: %s", hex);
40 info = cgit_parse_commit(commit);
42 format_display_notes(sha1, ¬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 cgit_print_date(info->author_date, FMT_LONGDATE, ctx.cfg.local_time);
60 html("<tr><th>committer</th><td>");
61 cgit_open_filter(ctx.repo->email_filter, info->committer_email, "commit");
62 html_txt(info->committer);
63 if (!ctx.cfg.noplainemail) {
65 html_txt(info->committer_email);
67 cgit_close_filter(ctx.repo->email_filter);
68 html("</td><td class='right'>");
69 cgit_print_date(info->committer_date, FMT_LONGDATE, ctx.cfg.local_time);
71 html("<tr><th>commit</th><td colspan='2' class='sha1'>");
72 tmp = sha1_to_hex(commit->object.sha1);
73 cgit_commit_link(tmp, NULL, NULL, ctx.qry.head, tmp, prefix);
75 cgit_patch_link("patch", NULL, NULL, NULL, tmp, prefix);
76 html(")</td></tr>\n");
77 html("<tr><th>tree</th><td colspan='2' class='sha1'>");
79 cgit_tree_link(sha1_to_hex(commit->tree->object.sha1), NULL, NULL,
80 ctx.qry.head, tmp, NULL);
83 cgit_tree_link(prefix, NULL, NULL, ctx.qry.head, tmp, prefix);
87 for (p = commit->parents; p; p = p->next) {
88 parent = lookup_commit_reference(p->item->object.sha1);
90 html("<tr><td colspan='3'>");
91 cgit_print_error("Error reading parent commit");
95 html("<tr><th>parent</th>"
96 "<td colspan='2' class='sha1'>");
97 tmp = tmp2 = sha1_to_hex(p->item->object.sha1);
98 if (ctx.repo->enable_subject_links) {
99 parent_info = cgit_parse_commit(parent);
100 tmp2 = parent_info->subject;
102 cgit_commit_link(tmp2, NULL, NULL, ctx.qry.head, tmp, prefix);
104 cgit_diff_link("diff", NULL, NULL, ctx.qry.head, hex,
105 sha1_to_hex(p->item->object.sha1), prefix);
109 if (ctx.repo->snapshots) {
110 html("<tr><th>download</th><td colspan='2' class='sha1'>");
111 cgit_print_snapshot_links(ctx.qry.repo, ctx.qry.head,
112 hex, ctx.repo->snapshots);
116 html("<div class='commit-subject'>");
117 cgit_open_filter(ctx.repo->commit_filter);
118 html_txt(info->subject);
119 cgit_close_filter(ctx.repo->commit_filter);
120 show_commit_decorations(commit);
122 html("<div class='commit-msg'>");
123 cgit_open_filter(ctx.repo->commit_filter);
125 cgit_close_filter(ctx.repo->commit_filter);
127 if (notes.len != 0) {
128 html("<div class='notes-header'>Notes</div>");
129 html("<div class='notes'>");
130 cgit_open_filter(ctx.repo->commit_filter);
132 cgit_close_filter(ctx.repo->commit_filter);
134 html("<div class='notes-footer'></div>");
138 tmp = sha1_to_hex(commit->parents->item->object.sha1);
141 cgit_print_diff(ctx.qry.sha1, tmp, prefix, 0, 0);
143 strbuf_release(¬es);
144 cgit_free_commitinfo(info);
145 cgit_print_layout_end();