blob: 4bbb391602771810eca26cbb00ef148b593f2893 [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"
Lars Hjemli9a8f8862006-12-16 00:19:56 +010013
Lars Hjemli4a0be582007-06-17 18:12:03 +020014void cgit_print_commit(char *hex)
Lars Hjemli9a8f8862006-12-16 00:19:56 +010015{
Lars Hjemli6a8749d2007-05-13 23:13:12 +020016 struct commit *commit, *parent;
Lars Hjemli9a8f8862006-12-16 00:19:56 +010017 struct commitinfo *info;
18 struct commit_list *p;
Lars Hjemli9a8f8862006-12-16 00:19:56 +010019 unsigned char sha1[20];
Lars Hjemli44947bf2007-06-17 01:23:08 +020020 char *tmp;
Lars Hjemli502d5752008-05-18 21:09:26 +020021 int parents = 0;
Lars Hjemli9a8f8862006-12-16 00:19:56 +010022
Lars Hjemli42a7eb92007-06-17 14:53:02 +020023 if (!hex)
Lars Hjemlid14d77f2008-02-16 11:53:40 +010024 hex = ctx.qry.head;
Lars Hjemli42a7eb92007-06-17 14:53:02 +020025
Lars Hjemli9a8f8862006-12-16 00:19:56 +010026 if (get_sha1(hex, sha1)) {
27 cgit_print_error(fmt("Bad object id: %s", hex));
28 return;
29 }
Lars Hjemlifa82b032006-12-16 14:46:05 +010030 commit = lookup_commit_reference(sha1);
Lars Hjemli9a8f8862006-12-16 00:19:56 +010031 if (!commit) {
32 cgit_print_error(fmt("Bad commit reference: %s", hex));
33 return;
34 }
Lars Hjemli9a8f8862006-12-16 00:19:56 +010035 info = cgit_parse_commit(commit);
36
Lars Hjemli29154832007-11-11 13:04:28 +010037 html("<table summary='commit info' class='commit-info'>\n");
Lars Hjemli8960d262006-12-16 14:28:26 +010038 html("<tr><th>author</th><td>");
Lars Hjemli9a8f8862006-12-16 00:19:56 +010039 html_txt(info->author);
Lars Hjemli8960d262006-12-16 14:28:26 +010040 html(" ");
41 html_txt(info->author_email);
42 html("</td><td class='right'>");
Lars Hjemli5db39172007-05-22 23:08:46 +020043 cgit_print_date(info->author_date, FMT_LONGDATE);
Lars Hjemli9a8f8862006-12-16 00:19:56 +010044 html("</td></tr>\n");
45 html("<tr><th>committer</th><td>");
46 html_txt(info->committer);
Lars Hjemli8960d262006-12-16 14:28:26 +010047 html(" ");
48 html_txt(info->committer_email);
Lars Hjemli9a8f8862006-12-16 00:19:56 +010049 html("</td><td class='right'>");
Lars Hjemli5db39172007-05-22 23:08:46 +020050 cgit_print_date(info->committer_date, FMT_LONGDATE);
Lars Hjemli9a8f8862006-12-16 00:19:56 +010051 html("</td></tr>\n");
Lars Hjemli39912a22008-04-13 12:20:00 +020052 html("<tr><th>commit</th><td colspan='2' class='sha1'>");
53 tmp = sha1_to_hex(commit->object.sha1);
54 cgit_commit_link(tmp, NULL, NULL, ctx.qry.head, tmp);
55 html(" (");
56 cgit_patch_link("patch", NULL, NULL, NULL, tmp);
57 html(")</td></tr>\n");
Lars Hjemli44947bf2007-06-17 01:23:08 +020058 html("<tr><th>tree</th><td colspan='2' class='sha1'>");
59 tmp = xstrdup(hex);
60 cgit_tree_link(sha1_to_hex(commit->tree->object.sha1), NULL, NULL,
Lars Hjemlid14d77f2008-02-16 11:53:40 +010061 ctx.qry.head, tmp, NULL);
Lars Hjemli44947bf2007-06-17 01:23:08 +020062 html("</td></tr>\n");
Lars Hjemli9c5229e2006-12-16 19:35:31 +010063 for (p = commit->parents; p ; p = p->next) {
Lars Hjemli6a8749d2007-05-13 23:13:12 +020064 parent = lookup_commit_reference(p->item->object.sha1);
65 if (!parent) {
66 html("<tr><td colspan='3'>");
67 cgit_print_error("Error reading parent commit");
68 html("</td></tr>");
69 continue;
70 }
Lars Hjemli9c5229e2006-12-16 19:35:31 +010071 html("<tr><th>parent</th>"
Lars Hjemlifaaca442007-06-17 15:44:22 +020072 "<td colspan='2' class='sha1'>");
73 cgit_commit_link(sha1_to_hex(p->item->object.sha1), NULL, NULL,
Lars Hjemlid14d77f2008-02-16 11:53:40 +010074 ctx.qry.head, sha1_to_hex(p->item->object.sha1));
Lars Hjemli4a0be582007-06-17 18:12:03 +020075 html(" (");
Lars Hjemlid14d77f2008-02-16 11:53:40 +010076 cgit_diff_link("diff", NULL, NULL, ctx.qry.head, hex,
Lars Hjemli4a0be582007-06-17 18:12:03 +020077 sha1_to_hex(p->item->object.sha1), NULL);
78 html(")</td></tr>");
Lars Hjemli502d5752008-05-18 21:09:26 +020079 parents++;
Lars Hjemli9a8f8862006-12-16 00:19:56 +010080 }
Lars Hjemlid1f3bbe2008-02-16 13:56:09 +010081 if (ctx.repo->snapshots) {
Michael Krelinf97c7072007-07-18 14:40:03 +020082 html("<tr><th>download</th><td colspan='2' class='sha1'>");
Lars Hjemlid14d77f2008-02-16 11:53:40 +010083 cgit_print_snapshot_links(ctx.qry.repo, ctx.qry.head,
Lars Hjemlid1f3bbe2008-02-16 13:56:09 +010084 hex, ctx.repo->snapshots);
Michael Krelinf97c7072007-07-18 14:40:03 +020085 html("</td></tr>");
Lars Hjemliac70cb42007-02-08 14:47:56 +010086 }
Lars Hjemli9a8f8862006-12-16 00:19:56 +010087 html("</table>\n");
88 html("<div class='commit-subject'>");
89 html_txt(info->subject);
90 html("</div>");
91 html("<div class='commit-msg'>");
92 html_txt(info->msg);
93 html("</div>");
Lars Hjemli502d5752008-05-18 21:09:26 +020094 if (parents < 3) {
95 if (parents)
96 tmp = sha1_to_hex(commit->parents->item->object.sha1);
97 else
98 tmp = NULL;
Lars Hjemlife1230d2008-04-24 23:32:02 +020099 cgit_print_diff(ctx.qry.sha1, tmp, NULL);
Lars Hjemli8a3685b2007-05-13 22:25:14 +0200100 }
Lars Hjemliaaa24bd2006-12-16 14:58:20 +0100101 cgit_free_commitinfo(info);
Lars Hjemli9a8f8862006-12-16 00:19:56 +0100102}