config: make empty js= omit script tag
[cgit.git] / ui-commit.c
blob078723756a6197051d8dffa3bab8d19b85a6e8f7
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)
7 */
9 #include "cgit.h"
10 #include "ui-commit.h"
11 #include "html.h"
12 #include "ui-shared.h"
13 #include "ui-diff.h"
14 #include "ui-log.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 struct object_id oid;
23 char *tmp, *tmp2;
24 int parents = 0;
26 if (!hex)
27 hex = ctx.qry.head;
29 if (get_oid(hex, &oid)) {
30 cgit_print_error_page(400, "Bad request",
31 "Bad object id: %s", hex);
32 return;
34 commit = lookup_commit_reference(the_repository, &oid);
35 if (!commit) {
36 cgit_print_error_page(404, "Not found",
37 "Bad commit reference: %s", hex);
38 return;
40 info = cgit_parse_commit(commit);
42 format_display_notes(&oid, &notes, PAGE_ENCODING, 1);
44 load_ref_decorations(NULL, DECORATE_FULL_REFS);
46 ctx.page.title = fmtalloc("%s - %s", info->subject, ctx.page.title);
47 cgit_print_layout_start();
48 cgit_print_diff_ctrls();
49 html("<table summary='commit info' class='commit-info'>\n");
50 html("<tr><th>author</th><td>");
51 cgit_open_filter(ctx.repo->email_filter, info->author_email, "commit");
52 html_txt(info->author);
53 if (!ctx.cfg.noplainemail) {
54 html(" ");
55 html_txt(info->author_email);
57 cgit_close_filter(ctx.repo->email_filter);
58 html("</td><td class='right'>");
59 html_txt(show_date(info->author_date, info->author_tz,
60 cgit_date_mode(DATE_ISO8601)));
61 html("</td></tr>\n");
62 html("<tr><th>committer</th><td>");
63 cgit_open_filter(ctx.repo->email_filter, info->committer_email, "commit");
64 html_txt(info->committer);
65 if (!ctx.cfg.noplainemail) {
66 html(" ");
67 html_txt(info->committer_email);
69 cgit_close_filter(ctx.repo->email_filter);
70 html("</td><td class='right'>");
71 html_txt(show_date(info->committer_date, info->committer_tz,
72 cgit_date_mode(DATE_ISO8601)));
73 html("</td></tr>\n");
74 html("<tr><th>commit</th><td colspan='2' class='oid'>");
75 tmp = oid_to_hex(&commit->object.oid);
76 cgit_commit_link(tmp, NULL, NULL, ctx.qry.head, tmp, prefix);
77 html(" (");
78 cgit_patch_link("patch", NULL, NULL, NULL, tmp, prefix);
79 html(")</td></tr>\n");
80 html("<tr><th>tree</th><td colspan='2' class='oid'>");
81 tmp = xstrdup(hex);
82 cgit_tree_link(oid_to_hex(get_commit_tree_oid(commit)), NULL, NULL,
83 ctx.qry.head, tmp, NULL);
84 if (prefix) {
85 html(" /");
86 cgit_tree_link(prefix, NULL, NULL, ctx.qry.head, tmp, prefix);
88 free(tmp);
89 html("</td></tr>\n");
90 for (p = commit->parents; p; p = p->next) {
91 parent = lookup_commit_reference(the_repository, &p->item->object.oid);
92 if (!parent) {
93 html("<tr><td colspan='3'>");
94 cgit_print_error("Error reading parent commit");
95 html("</td></tr>");
96 continue;
98 html("<tr><th>parent</th>"
99 "<td colspan='2' class='oid'>");
100 tmp = tmp2 = oid_to_hex(&p->item->object.oid);
101 if (ctx.repo->enable_subject_links) {
102 parent_info = cgit_parse_commit(parent);
103 tmp2 = parent_info->subject;
105 cgit_commit_link(tmp2, NULL, NULL, ctx.qry.head, tmp, prefix);
106 html(" (");
107 cgit_diff_link("diff", NULL, NULL, ctx.qry.head, hex,
108 oid_to_hex(&p->item->object.oid), prefix);
109 html(")</td></tr>");
110 parents++;
112 if (ctx.repo->snapshots) {
113 html("<tr><th>download</th><td colspan='2' class='oid'>");
114 cgit_print_snapshot_links(ctx.repo, hex, "<br/>");
115 html("</td></tr>");
117 html("</table>\n");
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);
123 html("</div>");
124 html("<div class='commit-msg'>");
125 cgit_open_filter(ctx.repo->commit_filter);
126 html_txt(info->msg);
127 cgit_close_filter(ctx.repo->commit_filter);
128 html("</div>");
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);
133 html_txt(notes.buf);
134 cgit_close_filter(ctx.repo->commit_filter);
135 html("</div>");
136 html("<div class='notes-footer'></div>");
138 if (parents < 3) {
139 if (parents)
140 tmp = oid_to_hex(&commit->parents->item->object.oid);
141 else
142 tmp = NULL;
143 cgit_print_diff(ctx.qry.oid, tmp, prefix, 0, 0);
145 strbuf_release(&notes);
146 cgit_free_commitinfo(info);
147 cgit_print_layout_end();