]> gitweb.ps.run Git - ps-cgit/blob - ui-commit.c
cgit_print_commit(): Free tmp variable
[ps-cgit] / 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         free(tmp);
78         html("</td></tr>\n");
79         for (p = commit->parents; p; p = p->next) {
80                 parent = lookup_commit_reference(p->item->object.sha1);
81                 if (!parent) {
82                         html("<tr><td colspan='3'>");
83                         cgit_print_error("Error reading parent commit");
84                         html("</td></tr>");
85                         continue;
86                 }
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;
93                 }
94                 cgit_commit_link(tmp2, NULL, NULL, ctx.qry.head, tmp, prefix, 0);
95                 html(" (");
96                 cgit_diff_link("diff", NULL, NULL, ctx.qry.head, hex,
97                                sha1_to_hex(p->item->object.sha1), prefix, 0);
98                 html(")</td></tr>");
99                 parents++;
100         }
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);
105                 html("</td></tr>");
106         }
107         html("</table>\n");
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);
115         html("</div>");
116         html("<div class='commit-msg'>");
117         if (ctx.repo->commit_filter)
118                 cgit_open_filter(ctx.repo->commit_filter);
119         html_txt(info->msg);
120         if (ctx.repo->commit_filter)
121                 cgit_close_filter(ctx.repo->commit_filter);
122         html("</div>");
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);
128                 html_txt(notes.buf);
129                 if (ctx.repo->commit_filter)
130                         cgit_close_filter(ctx.repo->commit_filter);
131                 html("</div>");
132                 html("<div class='notes-footer'></div>");
133         }
134         if (parents < 3) {
135                 if (parents)
136                         tmp = sha1_to_hex(commit->parents->item->object.sha1);
137                 else
138                         tmp = NULL;
139                 cgit_print_diff(ctx.qry.sha1, tmp, prefix, 0);
140         }
141         strbuf_release(&notes);
142         cgit_free_commitinfo(info);
143 }