]> gitweb.ps.run Git - ps-cgit/blob - ui-commit.c
git: update to v2.46.0
[ps-cgit] / ui-commit.c
1 /* ui-commit.c: generate commit view
2  *
3  * Copyright (C) 2006-2014 cgit Development Team <cgit@lists.zx2c4.com>
4  *
5  * Licensed under GNU General Public License v2
6  *   (see COPYING for full license text)
7  */
8
9 #define USE_THE_REPOSITORY_VARIABLE
10
11 #include "cgit.h"
12 #include "ui-commit.h"
13 #include "html.h"
14 #include "ui-shared.h"
15 #include "ui-diff.h"
16 #include "ui-log.h"
17
18 void cgit_print_commit(char *hex, const char *prefix)
19 {
20         struct commit *commit, *parent;
21         struct commitinfo *info, *parent_info;
22         struct commit_list *p;
23         struct strbuf notes = STRBUF_INIT;
24         struct object_id oid;
25         char *tmp, *tmp2;
26         int parents = 0;
27
28         if (!hex)
29                 hex = ctx.qry.head;
30
31         if (repo_get_oid(the_repository, hex, &oid)) {
32                 cgit_print_error_page(400, "Bad request",
33                                 "Bad object id: %s", hex);
34                 return;
35         }
36         commit = lookup_commit_reference(the_repository, &oid);
37         if (!commit) {
38                 cgit_print_error_page(404, "Not found",
39                                 "Bad commit reference: %s", hex);
40                 return;
41         }
42         info = cgit_parse_commit(commit);
43
44         format_display_notes(&oid, &notes, PAGE_ENCODING, 1);
45
46         load_ref_decorations(NULL, DECORATE_FULL_REFS);
47
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) {
56                 html(" ");
57                 html_txt(info->author_email);
58         }
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)));
63         html("</td></tr>\n");
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) {
68                 html(" ");
69                 html_txt(info->committer_email);
70         }
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)));
75         html("</td></tr>\n");
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);
79         html(" (");
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'>");
83         tmp = xstrdup(hex);
84         cgit_tree_link(oid_to_hex(get_commit_tree_oid(commit)), NULL, NULL,
85                        ctx.qry.head, tmp, NULL);
86         if (prefix) {
87                 html(" /");
88                 cgit_tree_link(prefix, NULL, NULL, ctx.qry.head, tmp, prefix);
89         }
90         free(tmp);
91         html("</td></tr>\n");
92         for (p = commit->parents; p; p = p->next) {
93                 parent = lookup_commit_reference(the_repository, &p->item->object.oid);
94                 if (!parent) {
95                         html("<tr><td colspan='3'>");
96                         cgit_print_error("Error reading parent commit");
97                         html("</td></tr>");
98                         continue;
99                 }
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;
106                 }
107                 cgit_commit_link(tmp2, NULL, NULL, ctx.qry.head, tmp, prefix);
108                 html(" (");
109                 cgit_diff_link("diff", NULL, NULL, ctx.qry.head, hex,
110                                oid_to_hex(&p->item->object.oid), prefix);
111                 html(")</td></tr>");
112                 parents++;
113         }
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/>");
117                 html("</td></tr>");
118         }
119         html("</table>\n");
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);
125         html("</div>");
126         html("<div class='commit-msg'>");
127         cgit_open_filter(ctx.repo->commit_filter);
128         html_txt(info->msg);
129         cgit_close_filter(ctx.repo->commit_filter);
130         html("</div>");
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);
135                 html_txt(notes.buf);
136                 cgit_close_filter(ctx.repo->commit_filter);
137                 html("</div>");
138                 html("<div class='notes-footer'></div>");
139         }
140         if (parents < 3) {
141                 if (parents)
142                         tmp = oid_to_hex(&commit->parents->item->object.oid);
143                 else
144                         tmp = NULL;
145                 cgit_print_diff(ctx.qry.oid, tmp, prefix, 0, 0);
146         }
147         strbuf_release(&notes);
148         cgit_free_commitinfo(info);
149         cgit_print_layout_end();
150 }