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)
9 #define USE_THE_REPOSITORY_VARIABLE
12 #include "ui-commit.h"
14 #include "ui-shared.h"
18 void cgit_print_commit(char *hex, const char *prefix)
20 struct commit *commit, *parent;
21 struct commitinfo *info, *parent_info;
22 struct commit_list *p;
23 struct strbuf notes = STRBUF_INIT;
31 if (repo_get_oid(the_repository, hex, &oid)) {
32 cgit_print_error_page(400, "Bad request",
33 "Bad object id: %s", hex);
36 commit = lookup_commit_reference(the_repository, &oid);
38 cgit_print_error_page(404, "Not found",
39 "Bad commit reference: %s", hex);
42 info = cgit_parse_commit(commit);
44 format_display_notes(&oid, ¬es, PAGE_ENCODING, 1);
46 load_ref_decorations(NULL, DECORATE_FULL_REFS);
48 ctx.page.title = fmtalloc("%s - %s", info->subject, ctx.page.title);
49 cgit_print_layout_start();
50 cgit_print_diff_ctrls();
51 html("<table summary='commit info' class='commit-info'>\n");
52 html("<tr><th>author</th><td>");
53 cgit_open_filter(ctx.repo->email_filter, info->author_email, "commit");
54 html_txt(info->author);
55 if (!ctx.cfg.noplainemail) {
57 html_txt(info->author_email);
59 cgit_close_filter(ctx.repo->email_filter);
60 html("</td><td class='right'>");
61 html_txt(show_date(info->author_date, info->author_tz,
62 cgit_date_mode(DATE_ISO8601)));
64 html("<tr><th>committer</th><td>");
65 cgit_open_filter(ctx.repo->email_filter, info->committer_email, "commit");
66 html_txt(info->committer);
67 if (!ctx.cfg.noplainemail) {
69 html_txt(info->committer_email);
71 cgit_close_filter(ctx.repo->email_filter);
72 html("</td><td class='right'>");
73 html_txt(show_date(info->committer_date, info->committer_tz,
74 cgit_date_mode(DATE_ISO8601)));
76 html("<tr><th>commit</th><td colspan='2' class='oid'>");
77 tmp = oid_to_hex(&commit->object.oid);
78 cgit_commit_link(tmp, NULL, NULL, ctx.qry.head, tmp, prefix);
80 cgit_patch_link("patch", NULL, NULL, NULL, tmp, prefix);
81 html(")</td></tr>\n");
82 html("<tr><th>tree</th><td colspan='2' class='oid'>");
84 cgit_tree_link(oid_to_hex(get_commit_tree_oid(commit)), NULL, NULL,
85 ctx.qry.head, tmp, NULL);
88 cgit_tree_link(prefix, NULL, NULL, ctx.qry.head, tmp, prefix);
92 for (p = commit->parents; p; p = p->next) {
93 parent = lookup_commit_reference(the_repository, &p->item->object.oid);
95 html("<tr><td colspan='3'>");
96 cgit_print_error("Error reading parent commit");
100 html("<tr><th>parent</th>"
101 "<td colspan='2' class='oid'>");
102 tmp = tmp2 = oid_to_hex(&p->item->object.oid);
103 if (ctx.repo->enable_subject_links) {
104 parent_info = cgit_parse_commit(parent);
105 tmp2 = parent_info->subject;
107 cgit_commit_link(tmp2, NULL, NULL, ctx.qry.head, tmp, prefix);
109 cgit_diff_link("diff", NULL, NULL, ctx.qry.head, hex,
110 oid_to_hex(&p->item->object.oid), prefix);
114 if (ctx.repo->snapshots) {
115 html("<tr><th>download</th><td colspan='2' class='oid'>");
116 cgit_print_snapshot_links(ctx.repo, hex, "<br/>");
120 html("<div class='commit-subject'>");
121 cgit_open_filter(ctx.repo->commit_filter);
122 html_txt(info->subject);
123 cgit_close_filter(ctx.repo->commit_filter);
124 show_commit_decorations(commit);
126 html("<div class='commit-msg'>");
127 cgit_open_filter(ctx.repo->commit_filter);
129 cgit_close_filter(ctx.repo->commit_filter);
131 if (notes.len != 0) {
132 html("<div class='notes-header'>Notes</div>");
133 html("<div class='notes'>");
134 cgit_open_filter(ctx.repo->commit_filter);
136 cgit_close_filter(ctx.repo->commit_filter);
138 html("<div class='notes-footer'></div>");
142 tmp = oid_to_hex(&commit->parents->item->object.oid);
145 cgit_print_diff(ctx.qry.oid, tmp, prefix, 0, 0);
147 strbuf_release(¬es);
148 cgit_free_commitinfo(info);
149 cgit_print_layout_end();