summary: move layout into page function
[cgit.git] / ui-commit.c
blob2bca7a019ea67a9e0c63f2578ed9ff076dd6d5bd
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 unsigned char sha1[20];
23 char *tmp, *tmp2;
24 int parents = 0;
26 if (!hex)
27 hex = ctx.qry.head;
29 if (get_sha1(hex, sha1)) {
30 cgit_print_error_page(400, "Bad request",
31 "Bad object id: %s", hex);
32 return;
34 commit = lookup_commit_reference(sha1);
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(sha1, &notes, 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) {
53 html(" ");
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);
59 html("</td></tr>\n");
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) {
64 html(" ");
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);
70 html("</td></tr>\n");
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);
74 html(" (");
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'>");
78 tmp = xstrdup(hex);
79 cgit_tree_link(sha1_to_hex(commit->tree->object.sha1), NULL, NULL,
80 ctx.qry.head, tmp, NULL);
81 if (prefix) {
82 html(" /");
83 cgit_tree_link(prefix, NULL, NULL, ctx.qry.head, tmp, prefix);
85 free(tmp);
86 html("</td></tr>\n");
87 for (p = commit->parents; p; p = p->next) {
88 parent = lookup_commit_reference(p->item->object.sha1);
89 if (!parent) {
90 html("<tr><td colspan='3'>");
91 cgit_print_error("Error reading parent commit");
92 html("</td></tr>");
93 continue;
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);
103 html(" (");
104 cgit_diff_link("diff", NULL, NULL, ctx.qry.head, hex,
105 sha1_to_hex(p->item->object.sha1), prefix);
106 html(")</td></tr>");
107 parents++;
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);
113 html("</td></tr>");
115 html("</table>\n");
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);
121 html("</div>");
122 html("<div class='commit-msg'>");
123 cgit_open_filter(ctx.repo->commit_filter);
124 html_txt(info->msg);
125 cgit_close_filter(ctx.repo->commit_filter);
126 html("</div>");
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);
131 html_txt(notes.buf);
132 cgit_close_filter(ctx.repo->commit_filter);
133 html("</div>");
134 html("<div class='notes-footer'></div>");
136 if (parents < 3) {
137 if (parents)
138 tmp = sha1_to_hex(commit->parents->item->object.sha1);
139 else
140 tmp = NULL;
141 cgit_print_diff(ctx.qry.sha1, tmp, prefix, 0, 0);
143 strbuf_release(&notes);
144 cgit_free_commitinfo(info);
145 cgit_print_layout_end();