1 /* ui-commit.c: generate commit view
3 * Copyright (C) 2006 Lars Hjemli
5 * Licensed under GNU General Public License v2
6 * (see COPYING for full license text)
11 #include "ui-shared.h"
15 void cgit_print_commit(char *hex, const char *prefix)
17 struct commit *commit, *parent;
18 struct commitinfo *info, *parent_info;
19 struct commit_list *p;
20 struct strbuf notes = STRBUF_INIT;
21 unsigned char sha1[20];
28 if (get_sha1(hex, sha1)) {
29 cgit_print_error(fmt("Bad object id: %s", hex));
32 commit = lookup_commit_reference(sha1);
34 cgit_print_error(fmt("Bad commit reference: %s", hex));
37 info = cgit_parse_commit(commit);
39 format_note(NULL, sha1, ¬es, PAGE_ENCODING, 0);
41 load_ref_decorations(DECORATE_FULL_REFS);
43 cgit_print_diff_ctrls();
44 html("<table summary='commit info' class='commit-info'>\n");
45 html("<tr><th>author</th><td>");
46 html_txt(info->author);
47 if (!ctx.cfg.noplainemail) {
49 html_txt(info->author_email);
51 html("</td><td class='right'>");
52 cgit_print_date(info->author_date, FMT_LONGDATE, ctx.cfg.local_time);
54 html("<tr><th>committer</th><td>");
55 html_txt(info->committer);
56 if (!ctx.cfg.noplainemail) {
58 html_txt(info->committer_email);
60 html("</td><td class='right'>");
61 cgit_print_date(info->committer_date, FMT_LONGDATE, ctx.cfg.local_time);
63 html("<tr><th>commit</th><td colspan='2' class='sha1'>");
64 tmp = sha1_to_hex(commit->object.sha1);
65 cgit_commit_link(tmp, NULL, NULL, ctx.qry.head, tmp, prefix, 0);
67 cgit_patch_link("patch", NULL, NULL, NULL, tmp, prefix);
68 html(")</td></tr>\n");
69 html("<tr><th>tree</th><td colspan='2' class='sha1'>");
71 cgit_tree_link(sha1_to_hex(commit->tree->object.sha1), NULL, NULL,
72 ctx.qry.head, tmp, NULL);
75 cgit_tree_link(prefix, NULL, NULL, ctx.qry.head, tmp, prefix);
79 for (p = commit->parents; p; p = p->next) {
80 parent = lookup_commit_reference(p->item->object.sha1);
82 html("<tr><td colspan='3'>");
83 cgit_print_error("Error reading parent commit");
87 html("<tr><th>parent</th>"
88 "<td colspan='2' class='sha1'>");
89 tmp = tmp2 = sha1_to_hex(p->item->object.sha1);
90 if (ctx.repo->enable_subject_links) {
91 parent_info = cgit_parse_commit(parent);
92 tmp2 = parent_info->subject;
94 cgit_commit_link(tmp2, NULL, NULL, ctx.qry.head, tmp, prefix, 0);
96 cgit_diff_link("diff", NULL, NULL, ctx.qry.head, hex,
97 sha1_to_hex(p->item->object.sha1), prefix, 0);
101 if (ctx.repo->snapshots) {
102 html("<tr><th>download</th><td colspan='2' class='sha1'>");
103 cgit_print_snapshot_links(ctx.qry.repo, ctx.qry.head,
104 hex, ctx.repo->snapshots);
108 html("<div class='commit-subject'>");
109 if (ctx.repo->commit_filter)
110 cgit_open_filter(ctx.repo->commit_filter);
111 html_txt(info->subject);
112 if (ctx.repo->commit_filter)
113 cgit_close_filter(ctx.repo->commit_filter);
114 show_commit_decorations(commit);
116 html("<div class='commit-msg'>");
117 if (ctx.repo->commit_filter)
118 cgit_open_filter(ctx.repo->commit_filter);
120 if (ctx.repo->commit_filter)
121 cgit_close_filter(ctx.repo->commit_filter);
123 if (notes.len != 0) {
124 html("<div class='notes-header'>Notes</div>");
125 html("<div class='notes'>");
126 if (ctx.repo->commit_filter)
127 cgit_open_filter(ctx.repo->commit_filter);
129 if (ctx.repo->commit_filter)
130 cgit_close_filter(ctx.repo->commit_filter);
132 html("<div class='notes-footer'></div>");
136 tmp = sha1_to_hex(commit->parents->item->object.sha1);
139 cgit_print_diff(ctx.qry.sha1, tmp, prefix, 0);
141 strbuf_release(¬es);
142 cgit_free_commitinfo(info);