blob: 45af45046a1d48e1759a18d04c51a6a77c693ae8 [file] [log] [blame]
Lars Hjemli6c14f5e2006-12-16 01:11:55 +01001/* 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
Lars Hjemli9a8f8862006-12-16 00:19:56 +01009#include "cgit.h"
Lars Hjemlib1f9b9c2008-02-23 22:45:33 +010010#include "html.h"
Lars Hjemlia4d1ca12008-03-24 16:50:57 +010011#include "ui-shared.h"
Lars Hjemli89aa3c02008-04-12 15:53:53 +020012#include "ui-diff.h"
Justin Waters0027e382009-01-12 10:23:28 -050013#include "ui-log.h"
Lars Hjemli9a8f8862006-12-16 00:19:56 +010014
Johan Herlandab427412010-06-10 01:09:32 +020015void cgit_print_commit(char *hex, const char *prefix)
Lars Hjemli9a8f8862006-12-16 00:19:56 +010016{
Lars Hjemli6a8749d2007-05-13 23:13:12 +020017 struct commit *commit, *parent;
Stefan Naewee15842a2010-02-15 09:57:50 +010018 struct commitinfo *info, *parent_info;
Lars Hjemli9a8f8862006-12-16 00:19:56 +010019 struct commit_list *p;
Jeff Smith059b3932010-07-29 09:32:30 -050020 struct strbuf notes = STRBUF_INIT;
Lars Hjemli9a8f8862006-12-16 00:19:56 +010021 unsigned char sha1[20];
Lars Hjemli581a0c22010-02-27 13:12:55 +010022 char *tmp, *tmp2;
Lars Hjemli502d5752008-05-18 21:09:26 +020023 int parents = 0;
Lars Hjemli9a8f8862006-12-16 00:19:56 +010024
Lars Hjemli42a7eb92007-06-17 14:53:02 +020025 if (!hex)
Lars Hjemlid14d77f2008-02-16 11:53:40 +010026 hex = ctx.qry.head;
Lars Hjemli42a7eb92007-06-17 14:53:02 +020027
Lars Hjemli9a8f8862006-12-16 00:19:56 +010028 if (get_sha1(hex, sha1)) {
29 cgit_print_error(fmt("Bad object id: %s", hex));
30 return;
31 }
Lars Hjemlifa82b032006-12-16 14:46:05 +010032 commit = lookup_commit_reference(sha1);
Lars Hjemli9a8f8862006-12-16 00:19:56 +010033 if (!commit) {
34 cgit_print_error(fmt("Bad commit reference: %s", hex));
35 return;
36 }
Lars Hjemli9a8f8862006-12-16 00:19:56 +010037 info = cgit_parse_commit(commit);
38
Jeff Smith059b3932010-07-29 09:32:30 -050039 get_commit_notes(commit, &notes, PAGE_ENCODING, 0);
40
Lars Hjemli45c49d62009-09-13 21:56:45 +020041 load_ref_decorations(DECORATE_FULL_REFS);
Justin Waters0027e382009-01-12 10:23:28 -050042
Lars Hjemli29154832007-11-11 13:04:28 +010043 html("<table summary='commit info' class='commit-info'>\n");
Lars Hjemli8960d262006-12-16 14:28:26 +010044 html("<tr><th>author</th><td>");
Lars Hjemli9a8f8862006-12-16 00:19:56 +010045 html_txt(info->author);
Martin Szulecki2f56e392009-08-07 14:05:17 +020046 if (!ctx.cfg.noplainemail) {
47 html(" ");
48 html_txt(info->author_email);
49 }
Lars Hjemli8960d262006-12-16 14:28:26 +010050 html("</td><td class='right'>");
Stefan Naewe0f0ab142008-08-01 14:54:38 +020051 cgit_print_date(info->author_date, FMT_LONGDATE, ctx.cfg.local_time);
Lars Hjemli9a8f8862006-12-16 00:19:56 +010052 html("</td></tr>\n");
53 html("<tr><th>committer</th><td>");
54 html_txt(info->committer);
Martin Szulecki2f56e392009-08-07 14:05:17 +020055 if (!ctx.cfg.noplainemail) {
56 html(" ");
57 html_txt(info->committer_email);
58 }
Lars Hjemli9a8f8862006-12-16 00:19:56 +010059 html("</td><td class='right'>");
Stefan Naewe0f0ab142008-08-01 14:54:38 +020060 cgit_print_date(info->committer_date, FMT_LONGDATE, ctx.cfg.local_time);
Lars Hjemli9a8f8862006-12-16 00:19:56 +010061 html("</td></tr>\n");
Lars Hjemli39912a22008-04-13 12:20:00 +020062 html("<tr><th>commit</th><td colspan='2' class='sha1'>");
63 tmp = sha1_to_hex(commit->object.sha1);
Johan Herland685872b2010-06-10 01:09:35 +020064 cgit_commit_link(tmp, NULL, NULL, ctx.qry.head, tmp, prefix, 0);
Lars Hjemli39912a22008-04-13 12:20:00 +020065 html(" (");
Johan Herlandeac1b672010-06-10 01:09:33 +020066 cgit_patch_link("patch", NULL, NULL, NULL, tmp, prefix);
Ragnar Ouchterlonyc358aa32009-09-14 20:19:02 +020067 html(") (");
68 if ((ctx.qry.ssdiff && !ctx.cfg.ssdiff) || (!ctx.qry.ssdiff && ctx.cfg.ssdiff))
Johan Herland685872b2010-06-10 01:09:35 +020069 cgit_commit_link("unidiff", NULL, NULL, ctx.qry.head, tmp, prefix, 1);
Ragnar Ouchterlonyc358aa32009-09-14 20:19:02 +020070 else
Johan Herland685872b2010-06-10 01:09:35 +020071 cgit_commit_link("side-by-side diff", NULL, NULL, ctx.qry.head, tmp, prefix, 1);
Lars Hjemli39912a22008-04-13 12:20:00 +020072 html(")</td></tr>\n");
Lars Hjemli44947bf2007-06-17 01:23:08 +020073 html("<tr><th>tree</th><td colspan='2' class='sha1'>");
74 tmp = xstrdup(hex);
75 cgit_tree_link(sha1_to_hex(commit->tree->object.sha1), NULL, NULL,
Lars Hjemlid14d77f2008-02-16 11:53:40 +010076 ctx.qry.head, tmp, NULL);
Johan Herland34c23312010-06-10 01:09:34 +020077 if (prefix) {
78 html(" /");
79 cgit_tree_link(prefix, NULL, NULL, ctx.qry.head, tmp, prefix);
80 }
Lars Hjemli44947bf2007-06-17 01:23:08 +020081 html("</td></tr>\n");
Lars Hjemli9c5229e2006-12-16 19:35:31 +010082 for (p = commit->parents; p ; p = p->next) {
Lars Hjemli6a8749d2007-05-13 23:13:12 +020083 parent = lookup_commit_reference(p->item->object.sha1);
84 if (!parent) {
85 html("<tr><td colspan='3'>");
86 cgit_print_error("Error reading parent commit");
87 html("</td></tr>");
88 continue;
89 }
Lars Hjemli9c5229e2006-12-16 19:35:31 +010090 html("<tr><th>parent</th>"
Lars Hjemlifaaca442007-06-17 15:44:22 +020091 "<td colspan='2' class='sha1'>");
Lars Hjemli581a0c22010-02-27 13:12:55 +010092 tmp = tmp2 = sha1_to_hex(p->item->object.sha1);
93 if (ctx.repo->enable_subject_links) {
94 parent_info = cgit_parse_commit(parent);
95 tmp2 = parent_info->subject;
96 }
Lars Hjemli37a24e42010-06-22 16:15:48 +020097 cgit_commit_link(tmp2, NULL, NULL, ctx.qry.head, tmp, prefix, 0);
Lars Hjemli4a0be582007-06-17 18:12:03 +020098 html(" (");
Lars Hjemlid14d77f2008-02-16 11:53:40 +010099 cgit_diff_link("diff", NULL, NULL, ctx.qry.head, hex,
Johan Herland34c23312010-06-10 01:09:34 +0200100 sha1_to_hex(p->item->object.sha1), prefix, 0);
Lars Hjemli4a0be582007-06-17 18:12:03 +0200101 html(")</td></tr>");
Lars Hjemli502d5752008-05-18 21:09:26 +0200102 parents++;
Lars Hjemli9a8f8862006-12-16 00:19:56 +0100103 }
Lars Hjemlid1f3bbe2008-02-16 13:56:09 +0100104 if (ctx.repo->snapshots) {
Michael Krelinf97c7072007-07-18 14:40:03 +0200105 html("<tr><th>download</th><td colspan='2' class='sha1'>");
Lars Hjemlid14d77f2008-02-16 11:53:40 +0100106 cgit_print_snapshot_links(ctx.qry.repo, ctx.qry.head,
Lars Hjemlid1f3bbe2008-02-16 13:56:09 +0100107 hex, ctx.repo->snapshots);
Michael Krelinf97c7072007-07-18 14:40:03 +0200108 html("</td></tr>");
Lars Hjemliac70cb42007-02-08 14:47:56 +0100109 }
Lars Hjemli9a8f8862006-12-16 00:19:56 +0100110 html("</table>\n");
111 html("<div class='commit-subject'>");
Lars Hjemlie976df22009-08-09 13:22:00 +0200112 if (ctx.repo->commit_filter)
113 cgit_open_filter(ctx.repo->commit_filter);
Lars Hjemli9a8f8862006-12-16 00:19:56 +0100114 html_txt(info->subject);
Lars Hjemlie976df22009-08-09 13:22:00 +0200115 if (ctx.repo->commit_filter)
116 cgit_close_filter(ctx.repo->commit_filter);
Justin Waters0027e382009-01-12 10:23:28 -0500117 show_commit_decorations(commit);
Lars Hjemli9a8f8862006-12-16 00:19:56 +0100118 html("</div>");
119 html("<div class='commit-msg'>");
Lars Hjemlie976df22009-08-09 13:22:00 +0200120 if (ctx.repo->commit_filter)
121 cgit_open_filter(ctx.repo->commit_filter);
Lars Hjemli9a8f8862006-12-16 00:19:56 +0100122 html_txt(info->msg);
Lars Hjemlie976df22009-08-09 13:22:00 +0200123 if (ctx.repo->commit_filter)
124 cgit_close_filter(ctx.repo->commit_filter);
Lars Hjemli9a8f8862006-12-16 00:19:56 +0100125 html("</div>");
Jeff Smith059b3932010-07-29 09:32:30 -0500126 if (notes.len != 0) {
127 html("<div class='notes-header'>Notes</div>");
128 html("<div class='notes'>");
129 if (ctx.repo->commit_filter)
130 cgit_open_filter(ctx.repo->commit_filter);
131 html_txt(notes.buf);
132 if (ctx.repo->commit_filter)
133 cgit_close_filter(ctx.repo->commit_filter);
134 html("</div>");
135 html("<div class='notes-footer'></div>");
136 }
Lars Hjemli502d5752008-05-18 21:09:26 +0200137 if (parents < 3) {
138 if (parents)
139 tmp = sha1_to_hex(commit->parents->item->object.sha1);
140 else
141 tmp = NULL;
Johan Herlandab427412010-06-10 01:09:32 +0200142 cgit_print_diff(ctx.qry.sha1, tmp, prefix);
Lars Hjemli8a3685b2007-05-13 22:25:14 +0200143 }
Jeff Smith059b3932010-07-29 09:32:30 -0500144 strbuf_release(&notes);
Lars Hjemliaaa24bd2006-12-16 14:58:20 +0100145 cgit_free_commitinfo(info);
Lars Hjemli9a8f8862006-12-16 00:19:56 +0100146}