blob: 9fdb8eed4d2118c968571db50839bac55f0f7c3f [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
Lars Hjemli4a0be582007-06-17 18:12:03 +020015void cgit_print_commit(char *hex)
Lars Hjemli9a8f8862006-12-16 00:19:56 +010016{
Lars Hjemli6a8749d2007-05-13 23:13:12 +020017 struct commit *commit, *parent;
Lars Hjemli9a8f8862006-12-16 00:19:56 +010018 struct commitinfo *info;
19 struct commit_list *p;
Lars Hjemli9a8f8862006-12-16 00:19:56 +010020 unsigned char sha1[20];
Lars Hjemli44947bf2007-06-17 01:23:08 +020021 char *tmp;
Lars Hjemli502d5752008-05-18 21:09:26 +020022 int parents = 0;
Lars Hjemli9a8f8862006-12-16 00:19:56 +010023
Lars Hjemli42a7eb92007-06-17 14:53:02 +020024 if (!hex)
Lars Hjemlid14d77f2008-02-16 11:53:40 +010025 hex = ctx.qry.head;
Lars Hjemli42a7eb92007-06-17 14:53:02 +020026
Lars Hjemli9a8f8862006-12-16 00:19:56 +010027 if (get_sha1(hex, sha1)) {
28 cgit_print_error(fmt("Bad object id: %s", hex));
29 return;
30 }
Lars Hjemlifa82b032006-12-16 14:46:05 +010031 commit = lookup_commit_reference(sha1);
Lars Hjemli9a8f8862006-12-16 00:19:56 +010032 if (!commit) {
33 cgit_print_error(fmt("Bad commit reference: %s", hex));
34 return;
35 }
Lars Hjemli9a8f8862006-12-16 00:19:56 +010036 info = cgit_parse_commit(commit);
37
Justin Waters0027e382009-01-12 10:23:28 -050038 load_ref_decorations();
39
Lars Hjemli29154832007-11-11 13:04:28 +010040 html("<table summary='commit info' class='commit-info'>\n");
Lars Hjemli8960d262006-12-16 14:28:26 +010041 html("<tr><th>author</th><td>");
Lars Hjemli9a8f8862006-12-16 00:19:56 +010042 html_txt(info->author);
Martin Szulecki2f56e392009-08-07 14:05:17 +020043 if (!ctx.cfg.noplainemail) {
44 html(" ");
45 html_txt(info->author_email);
46 }
Lars Hjemli8960d262006-12-16 14:28:26 +010047 html("</td><td class='right'>");
Stefan Naewe0f0ab142008-08-01 14:54:38 +020048 cgit_print_date(info->author_date, FMT_LONGDATE, ctx.cfg.local_time);
Lars Hjemli9a8f8862006-12-16 00:19:56 +010049 html("</td></tr>\n");
50 html("<tr><th>committer</th><td>");
51 html_txt(info->committer);
Martin Szulecki2f56e392009-08-07 14:05:17 +020052 if (!ctx.cfg.noplainemail) {
53 html(" ");
54 html_txt(info->committer_email);
55 }
Lars Hjemli9a8f8862006-12-16 00:19:56 +010056 html("</td><td class='right'>");
Stefan Naewe0f0ab142008-08-01 14:54:38 +020057 cgit_print_date(info->committer_date, FMT_LONGDATE, ctx.cfg.local_time);
Lars Hjemli9a8f8862006-12-16 00:19:56 +010058 html("</td></tr>\n");
Lars Hjemli39912a22008-04-13 12:20:00 +020059 html("<tr><th>commit</th><td colspan='2' class='sha1'>");
60 tmp = sha1_to_hex(commit->object.sha1);
61 cgit_commit_link(tmp, NULL, NULL, ctx.qry.head, tmp);
62 html(" (");
63 cgit_patch_link("patch", NULL, NULL, NULL, tmp);
64 html(")</td></tr>\n");
Lars Hjemli44947bf2007-06-17 01:23:08 +020065 html("<tr><th>tree</th><td colspan='2' class='sha1'>");
66 tmp = xstrdup(hex);
67 cgit_tree_link(sha1_to_hex(commit->tree->object.sha1), NULL, NULL,
Lars Hjemlid14d77f2008-02-16 11:53:40 +010068 ctx.qry.head, tmp, NULL);
Lars Hjemli44947bf2007-06-17 01:23:08 +020069 html("</td></tr>\n");
Lars Hjemli9c5229e2006-12-16 19:35:31 +010070 for (p = commit->parents; p ; p = p->next) {
Lars Hjemli6a8749d2007-05-13 23:13:12 +020071 parent = lookup_commit_reference(p->item->object.sha1);
72 if (!parent) {
73 html("<tr><td colspan='3'>");
74 cgit_print_error("Error reading parent commit");
75 html("</td></tr>");
76 continue;
77 }
Lars Hjemli9c5229e2006-12-16 19:35:31 +010078 html("<tr><th>parent</th>"
Lars Hjemlifaaca442007-06-17 15:44:22 +020079 "<td colspan='2' class='sha1'>");
80 cgit_commit_link(sha1_to_hex(p->item->object.sha1), NULL, NULL,
Lars Hjemlid14d77f2008-02-16 11:53:40 +010081 ctx.qry.head, sha1_to_hex(p->item->object.sha1));
Lars Hjemli4a0be582007-06-17 18:12:03 +020082 html(" (");
Lars Hjemlid14d77f2008-02-16 11:53:40 +010083 cgit_diff_link("diff", NULL, NULL, ctx.qry.head, hex,
Lars Hjemli4a0be582007-06-17 18:12:03 +020084 sha1_to_hex(p->item->object.sha1), NULL);
85 html(")</td></tr>");
Lars Hjemli502d5752008-05-18 21:09:26 +020086 parents++;
Lars Hjemli9a8f8862006-12-16 00:19:56 +010087 }
Lars Hjemlid1f3bbe2008-02-16 13:56:09 +010088 if (ctx.repo->snapshots) {
Michael Krelinf97c7072007-07-18 14:40:03 +020089 html("<tr><th>download</th><td colspan='2' class='sha1'>");
Lars Hjemlid14d77f2008-02-16 11:53:40 +010090 cgit_print_snapshot_links(ctx.qry.repo, ctx.qry.head,
Lars Hjemlid1f3bbe2008-02-16 13:56:09 +010091 hex, ctx.repo->snapshots);
Michael Krelinf97c7072007-07-18 14:40:03 +020092 html("</td></tr>");
Lars Hjemliac70cb42007-02-08 14:47:56 +010093 }
Lars Hjemli9a8f8862006-12-16 00:19:56 +010094 html("</table>\n");
95 html("<div class='commit-subject'>");
96 html_txt(info->subject);
Justin Waters0027e382009-01-12 10:23:28 -050097 show_commit_decorations(commit);
Lars Hjemli9a8f8862006-12-16 00:19:56 +010098 html("</div>");
99 html("<div class='commit-msg'>");
100 html_txt(info->msg);
101 html("</div>");
Lars Hjemli502d5752008-05-18 21:09:26 +0200102 if (parents < 3) {
103 if (parents)
104 tmp = sha1_to_hex(commit->parents->item->object.sha1);
105 else
106 tmp = NULL;
Lars Hjemlife1230d2008-04-24 23:32:02 +0200107 cgit_print_diff(ctx.qry.sha1, tmp, NULL);
Lars Hjemli8a3685b2007-05-13 22:25:14 +0200108 }
Lars Hjemliaaa24bd2006-12-16 14:58:20 +0100109 cgit_free_commitinfo(info);
Lars Hjemli9a8f8862006-12-16 00:19:56 +0100110}