blob: 099d294fa8fba261168cdc3091ebda97d6f97ab7 [file] [log] [blame]
Lars Hjemli6c14f5e2006-12-16 01:11:55 +01001/* ui-commit.c: generate commit view
2 *
Lukas Fleischerf7f26f82014-01-08 15:10:49 +01003 * Copyright (C) 2006-2014 cgit Development Team <cgit@lists.zx2c4.com>
Lars Hjemli6c14f5e2006-12-16 01:11:55 +01004 *
5 * Licensed under GNU General Public License v2
6 * (see COPYING for full license text)
7 */
8
Lars Hjemli9a8f8862006-12-16 00:19:56 +01009#include "cgit.h"
John Keeping8f208792013-04-06 11:37:59 +010010#include "ui-commit.h"
Lars Hjemlib1f9b9c2008-02-23 22:45:33 +010011#include "html.h"
Lars Hjemlia4d1ca12008-03-24 16:50:57 +010012#include "ui-shared.h"
Lars Hjemli89aa3c02008-04-12 15:53:53 +020013#include "ui-diff.h"
Justin Waters0027e382009-01-12 10:23:28 -050014#include "ui-log.h"
Lars Hjemli9a8f8862006-12-16 00:19:56 +010015
Johan Herlandab427412010-06-10 01:09:32 +020016void cgit_print_commit(char *hex, const char *prefix)
Lars Hjemli9a8f8862006-12-16 00:19:56 +010017{
Lars Hjemli6a8749d2007-05-13 23:13:12 +020018 struct commit *commit, *parent;
Stefan Naewee15842a2010-02-15 09:57:50 +010019 struct commitinfo *info, *parent_info;
Lars Hjemli9a8f8862006-12-16 00:19:56 +010020 struct commit_list *p;
Jeff Smith059b3932010-07-29 09:32:30 -050021 struct strbuf notes = STRBUF_INIT;
Lars Hjemli9a8f8862006-12-16 00:19:56 +010022 unsigned char sha1[20];
Lars Hjemli581a0c22010-02-27 13:12:55 +010023 char *tmp, *tmp2;
Lars Hjemli502d5752008-05-18 21:09:26 +020024 int parents = 0;
Lars Hjemli9a8f8862006-12-16 00:19:56 +010025
Lars Hjemli42a7eb92007-06-17 14:53:02 +020026 if (!hex)
Lars Hjemlid14d77f2008-02-16 11:53:40 +010027 hex = ctx.qry.head;
Lars Hjemli42a7eb92007-06-17 14:53:02 +020028
Lars Hjemli9a8f8862006-12-16 00:19:56 +010029 if (get_sha1(hex, sha1)) {
John Keepingc53a15c2015-08-14 12:47:13 +010030 cgit_print_error_page(400, "Bad request",
31 "Bad object id: %s", hex);
Lars Hjemli9a8f8862006-12-16 00:19:56 +010032 return;
33 }
Lars Hjemlifa82b032006-12-16 14:46:05 +010034 commit = lookup_commit_reference(sha1);
Lars Hjemli9a8f8862006-12-16 00:19:56 +010035 if (!commit) {
John Keepingc53a15c2015-08-14 12:47:13 +010036 cgit_print_error_page(404, "Not found",
37 "Bad commit reference: %s", hex);
Lars Hjemli9a8f8862006-12-16 00:19:56 +010038 return;
39 }
Lars Hjemli9a8f8862006-12-16 00:19:56 +010040 info = cgit_parse_commit(commit);
41
John Keeping849ecd92013-04-08 09:00:22 +010042 format_display_notes(sha1, &notes, PAGE_ENCODING, 0);
Jeff Smith059b3932010-07-29 09:32:30 -050043
Lars Hjemli45c49d62009-09-13 21:56:45 +020044 load_ref_decorations(DECORATE_FULL_REFS);
Lukas Fleischer53bc7472013-03-03 16:04:29 +010045
John Keepingc53a15c2015-08-14 12:47:13 +010046 cgit_print_layout_start();
Lars Hjemli962a2482011-03-06 23:59:56 +010047 cgit_print_diff_ctrls();
Lars Hjemli29154832007-11-11 13:04:28 +010048 html("<table summary='commit info' class='commit-info'>\n");
Lars Hjemli8960d262006-12-16 14:28:26 +010049 html("<tr><th>author</th><td>");
Jason A. Donenfeld786609b2014-01-13 16:24:40 +010050 cgit_open_filter(ctx.repo->email_filter, info->author_email, "commit");
Lars Hjemli9a8f8862006-12-16 00:19:56 +010051 html_txt(info->author);
Martin Szulecki2f56e392009-08-07 14:05:17 +020052 if (!ctx.cfg.noplainemail) {
53 html(" ");
54 html_txt(info->author_email);
55 }
Jason A. Donenfelda5e15532014-01-13 04:04:52 +010056 cgit_close_filter(ctx.repo->email_filter);
Lars Hjemli8960d262006-12-16 14:28:26 +010057 html("</td><td class='right'>");
John Keeping21dcf102016-01-19 19:33:04 +000058 html_txt(show_date(info->author_date, info->author_tz,
John Keeping9c15f3c2016-02-08 15:05:54 +000059 cgit_date_mode(DATE_ISO8601)));
Lars Hjemli9a8f8862006-12-16 00:19:56 +010060 html("</td></tr>\n");
61 html("<tr><th>committer</th><td>");
Jason A. Donenfeld786609b2014-01-13 16:24:40 +010062 cgit_open_filter(ctx.repo->email_filter, info->committer_email, "commit");
Lars Hjemli9a8f8862006-12-16 00:19:56 +010063 html_txt(info->committer);
Martin Szulecki2f56e392009-08-07 14:05:17 +020064 if (!ctx.cfg.noplainemail) {
65 html(" ");
66 html_txt(info->committer_email);
67 }
Jason A. Donenfelda5e15532014-01-13 04:04:52 +010068 cgit_close_filter(ctx.repo->email_filter);
Lars Hjemli9a8f8862006-12-16 00:19:56 +010069 html("</td><td class='right'>");
John Keeping21dcf102016-01-19 19:33:04 +000070 html_txt(show_date(info->committer_date, info->committer_tz,
John Keeping9c15f3c2016-02-08 15:05:54 +000071 cgit_date_mode(DATE_ISO8601)));
Lars Hjemli9a8f8862006-12-16 00:19:56 +010072 html("</td></tr>\n");
Lars Hjemli39912a22008-04-13 12:20:00 +020073 html("<tr><th>commit</th><td colspan='2' class='sha1'>");
Christian Hesse559ab5e2016-01-05 07:38:53 +010074 tmp = oid_to_hex(&commit->object.oid);
John Keepingeeddb5b2014-10-05 10:59:02 +010075 cgit_commit_link(tmp, NULL, NULL, ctx.qry.head, tmp, prefix);
Lars Hjemli39912a22008-04-13 12:20:00 +020076 html(" (");
Johan Herlandeac1b672010-06-10 01:09:33 +020077 cgit_patch_link("patch", NULL, NULL, NULL, tmp, prefix);
Lars Hjemli39912a22008-04-13 12:20:00 +020078 html(")</td></tr>\n");
Lars Hjemli44947bf2007-06-17 01:23:08 +020079 html("<tr><th>tree</th><td colspan='2' class='sha1'>");
80 tmp = xstrdup(hex);
Christian Hesse559ab5e2016-01-05 07:38:53 +010081 cgit_tree_link(oid_to_hex(&commit->tree->object.oid), NULL, NULL,
Lars Hjemlid14d77f2008-02-16 11:53:40 +010082 ctx.qry.head, tmp, NULL);
Johan Herland34c23312010-06-10 01:09:34 +020083 if (prefix) {
84 html(" /");
85 cgit_tree_link(prefix, NULL, NULL, ctx.qry.head, tmp, prefix);
86 }
Lukas Fleischerbc2f5a62013-03-04 13:25:37 +010087 free(tmp);
Lars Hjemli44947bf2007-06-17 01:23:08 +020088 html("</td></tr>\n");
Lukas Fleischer53bc7472013-03-03 16:04:29 +010089 for (p = commit->parents; p; p = p->next) {
Christian Hesse559ab5e2016-01-05 07:38:53 +010090 parent = lookup_commit_reference(p->item->object.oid.hash);
Lars Hjemli6a8749d2007-05-13 23:13:12 +020091 if (!parent) {
92 html("<tr><td colspan='3'>");
93 cgit_print_error("Error reading parent commit");
94 html("</td></tr>");
95 continue;
96 }
Lars Hjemli9c5229e2006-12-16 19:35:31 +010097 html("<tr><th>parent</th>"
Lars Hjemlifaaca442007-06-17 15:44:22 +020098 "<td colspan='2' class='sha1'>");
Christian Hesse559ab5e2016-01-05 07:38:53 +010099 tmp = tmp2 = oid_to_hex(&p->item->object.oid);
Lars Hjemli581a0c22010-02-27 13:12:55 +0100100 if (ctx.repo->enable_subject_links) {
101 parent_info = cgit_parse_commit(parent);
102 tmp2 = parent_info->subject;
103 }
John Keepingeeddb5b2014-10-05 10:59:02 +0100104 cgit_commit_link(tmp2, NULL, NULL, ctx.qry.head, tmp, prefix);
Lars Hjemli4a0be582007-06-17 18:12:03 +0200105 html(" (");
Lars Hjemlid14d77f2008-02-16 11:53:40 +0100106 cgit_diff_link("diff", NULL, NULL, ctx.qry.head, hex,
Christian Hesse559ab5e2016-01-05 07:38:53 +0100107 oid_to_hex(&p->item->object.oid), prefix);
Lars Hjemli4a0be582007-06-17 18:12:03 +0200108 html(")</td></tr>");
Lars Hjemli502d5752008-05-18 21:09:26 +0200109 parents++;
Lars Hjemli9a8f8862006-12-16 00:19:56 +0100110 }
Lars Hjemlid1f3bbe2008-02-16 13:56:09 +0100111 if (ctx.repo->snapshots) {
Michael Krelinf97c7072007-07-18 14:40:03 +0200112 html("<tr><th>download</th><td colspan='2' class='sha1'>");
Lars Hjemlid14d77f2008-02-16 11:53:40 +0100113 cgit_print_snapshot_links(ctx.qry.repo, ctx.qry.head,
Lars Hjemlid1f3bbe2008-02-16 13:56:09 +0100114 hex, ctx.repo->snapshots);
Michael Krelinf97c7072007-07-18 14:40:03 +0200115 html("</td></tr>");
Lars Hjemliac70cb42007-02-08 14:47:56 +0100116 }
Lars Hjemli9a8f8862006-12-16 00:19:56 +0100117 html("</table>\n");
118 html("<div class='commit-subject'>");
Jason A. Donenfeld800380d2014-01-13 03:56:50 +0100119 cgit_open_filter(ctx.repo->commit_filter);
Lars Hjemli9a8f8862006-12-16 00:19:56 +0100120 html_txt(info->subject);
Jason A. Donenfeld800380d2014-01-13 03:56:50 +0100121 cgit_close_filter(ctx.repo->commit_filter);
Justin Waters0027e382009-01-12 10:23:28 -0500122 show_commit_decorations(commit);
Lars Hjemli9a8f8862006-12-16 00:19:56 +0100123 html("</div>");
124 html("<div class='commit-msg'>");
Jason A. Donenfeld800380d2014-01-13 03:56:50 +0100125 cgit_open_filter(ctx.repo->commit_filter);
Lars Hjemli9a8f8862006-12-16 00:19:56 +0100126 html_txt(info->msg);
Jason A. Donenfeld800380d2014-01-13 03:56:50 +0100127 cgit_close_filter(ctx.repo->commit_filter);
Lars Hjemli9a8f8862006-12-16 00:19:56 +0100128 html("</div>");
Jeff Smith059b3932010-07-29 09:32:30 -0500129 if (notes.len != 0) {
130 html("<div class='notes-header'>Notes</div>");
131 html("<div class='notes'>");
Jason A. Donenfeld800380d2014-01-13 03:56:50 +0100132 cgit_open_filter(ctx.repo->commit_filter);
Jeff Smith059b3932010-07-29 09:32:30 -0500133 html_txt(notes.buf);
Jason A. Donenfeld800380d2014-01-13 03:56:50 +0100134 cgit_close_filter(ctx.repo->commit_filter);
Jeff Smith059b3932010-07-29 09:32:30 -0500135 html("</div>");
136 html("<div class='notes-footer'></div>");
137 }
Lars Hjemli502d5752008-05-18 21:09:26 +0200138 if (parents < 3) {
139 if (parents)
Christian Hesse559ab5e2016-01-05 07:38:53 +0100140 tmp = oid_to_hex(&commit->parents->item->object.oid);
Lars Hjemli502d5752008-05-18 21:09:26 +0200141 else
142 tmp = NULL;
Lukas Fleischer9003cc12013-08-14 10:50:32 +0200143 cgit_print_diff(ctx.qry.sha1, tmp, prefix, 0, 0);
Lars Hjemli8a3685b2007-05-13 22:25:14 +0200144 }
Jeff Smith059b3932010-07-29 09:32:30 -0500145 strbuf_release(&notes);
Lars Hjemliaaa24bd2006-12-16 14:58:20 +0100146 cgit_free_commitinfo(info);
John Keepingc53a15c2015-08-14 12:47:13 +0100147 cgit_print_layout_end();
Lars Hjemli9a8f8862006-12-16 00:19:56 +0100148}