]> git.cameronkatri.com Git - cgit.git/blob - ui-commit.c
Merge branch 'lh/clone-url'
[cgit.git] / ui-commit.c
1 /* ui-commit.c: generate commit view
2 *
3 * Copyright (C) 2006 Lars Hjemli
4 *
5 * Licensed under GNU General Public License v2
6 * (see COPYING for full license text)
7 */
8
9 #include "cgit.h"
10 #include "html.h"
11 #include "ui-shared.h"
12 #include "ui-diff.h"
13 #include "ui-log.h"
14
15 void cgit_print_commit(char *hex, const char *prefix)
16 {
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];
22 char *tmp, *tmp2;
23 int parents = 0;
24
25 if (!hex)
26 hex = ctx.qry.head;
27
28 if (get_sha1(hex, sha1)) {
29 cgit_print_error(fmt("Bad object id: %s", hex));
30 return;
31 }
32 commit = lookup_commit_reference(sha1);
33 if (!commit) {
34 cgit_print_error(fmt("Bad commit reference: %s", hex));
35 return;
36 }
37 info = cgit_parse_commit(commit);
38
39 format_note(NULL, sha1, &notes, PAGE_ENCODING, 0);
40
41 load_ref_decorations(DECORATE_FULL_REFS);
42
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) {
48 html(" ");
49 html_txt(info->author_email);
50 }
51 html("</td><td class='right'>");
52 cgit_print_date(info->author_date, FMT_LONGDATE, ctx.cfg.local_time);
53 html("</td></tr>\n");
54 html("<tr><th>committer</th><td>");
55 html_txt(info->committer);
56 if (!ctx.cfg.noplainemail) {
57 html(" ");
58 html_txt(info->committer_email);
59 }
60 html("</td><td class='right'>");
61 cgit_print_date(info->committer_date, FMT_LONGDATE, ctx.cfg.local_time);
62 html("</td></tr>\n");
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);
66 html(" (");
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'>");
70 tmp = xstrdup(hex);
71 cgit_tree_link(sha1_to_hex(commit->tree->object.sha1), NULL, NULL,
72 ctx.qry.head, tmp, NULL);
73 if (prefix) {
74 html(" /");
75 cgit_tree_link(prefix, NULL, NULL, ctx.qry.head, tmp, prefix);
76 }
77 html("</td></tr>\n");
78 for (p = commit->parents; p ; p = p->next) {
79 parent = lookup_commit_reference(p->item->object.sha1);
80 if (!parent) {
81 html("<tr><td colspan='3'>");
82 cgit_print_error("Error reading parent commit");
83 html("</td></tr>");
84 continue;
85 }
86 html("<tr><th>parent</th>"
87 "<td colspan='2' class='sha1'>");
88 tmp = tmp2 = sha1_to_hex(p->item->object.sha1);
89 if (ctx.repo->enable_subject_links) {
90 parent_info = cgit_parse_commit(parent);
91 tmp2 = parent_info->subject;
92 }
93 cgit_commit_link(tmp2, NULL, NULL, ctx.qry.head, tmp, prefix, 0);
94 html(" (");
95 cgit_diff_link("diff", NULL, NULL, ctx.qry.head, hex,
96 sha1_to_hex(p->item->object.sha1), prefix, 0);
97 html(")</td></tr>");
98 parents++;
99 }
100 if (ctx.repo->snapshots) {
101 html("<tr><th>download</th><td colspan='2' class='sha1'>");
102 cgit_print_snapshot_links(ctx.qry.repo, ctx.qry.head,
103 hex, ctx.repo->snapshots);
104 html("</td></tr>");
105 }
106 html("</table>\n");
107 html("<div class='commit-subject'>");
108 if (ctx.repo->commit_filter)
109 cgit_open_filter(ctx.repo->commit_filter);
110 html_txt(info->subject);
111 if (ctx.repo->commit_filter)
112 cgit_close_filter(ctx.repo->commit_filter);
113 show_commit_decorations(commit);
114 html("</div>");
115 html("<div class='commit-msg'>");
116 if (ctx.repo->commit_filter)
117 cgit_open_filter(ctx.repo->commit_filter);
118 html_txt(info->msg);
119 if (ctx.repo->commit_filter)
120 cgit_close_filter(ctx.repo->commit_filter);
121 html("</div>");
122 if (notes.len != 0) {
123 html("<div class='notes-header'>Notes</div>");
124 html("<div class='notes'>");
125 if (ctx.repo->commit_filter)
126 cgit_open_filter(ctx.repo->commit_filter);
127 html_txt(notes.buf);
128 if (ctx.repo->commit_filter)
129 cgit_close_filter(ctx.repo->commit_filter);
130 html("</div>");
131 html("<div class='notes-footer'></div>");
132 }
133 if (parents < 3) {
134 if (parents)
135 tmp = sha1_to_hex(commit->parents->item->object.sha1);
136 else
137 tmp = NULL;
138 cgit_print_diff(ctx.qry.sha1, tmp, prefix, 0);
139 }
140 strbuf_release(&notes);
141 cgit_free_commitinfo(info);
142 }