blob: 1aa5d3415947cd4b9a12c79ca4695e62a6723bfb [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 Hjemli9a8f8862006-12-16 00:19:56 +010021
Lars Hjemli42a7eb92007-06-17 14:53:02 +020022 if (!hex)
Lars Hjemlid14d77f2008-02-16 11:53:40 +010023 hex = ctx.qry.head;
Lars Hjemli42a7eb92007-06-17 14:53:02 +020024
Lars Hjemli9a8f8862006-12-16 00:19:56 +010025 if (get_sha1(hex, sha1)) {
26 cgit_print_error(fmt("Bad object id: %s", hex));
27 return;
28 }
Lars Hjemlifa82b032006-12-16 14:46:05 +010029 commit = lookup_commit_reference(sha1);
Lars Hjemli9a8f8862006-12-16 00:19:56 +010030 if (!commit) {
31 cgit_print_error(fmt("Bad commit reference: %s", hex));
32 return;
33 }
Lars Hjemli9a8f8862006-12-16 00:19:56 +010034 info = cgit_parse_commit(commit);
35
Lars Hjemli29154832007-11-11 13:04:28 +010036 html("<table summary='commit info' class='commit-info'>\n");
Lars Hjemli8960d262006-12-16 14:28:26 +010037 html("<tr><th>author</th><td>");
Lars Hjemli9a8f8862006-12-16 00:19:56 +010038 html_txt(info->author);
Lars Hjemli8960d262006-12-16 14:28:26 +010039 html(" ");
40 html_txt(info->author_email);
41 html("</td><td class='right'>");
Lars Hjemli5db39172007-05-22 23:08:46 +020042 cgit_print_date(info->author_date, FMT_LONGDATE);
Lars Hjemli9a8f8862006-12-16 00:19:56 +010043 html("</td></tr>\n");
44 html("<tr><th>committer</th><td>");
45 html_txt(info->committer);
Lars Hjemli8960d262006-12-16 14:28:26 +010046 html(" ");
47 html_txt(info->committer_email);
Lars Hjemli9a8f8862006-12-16 00:19:56 +010048 html("</td><td class='right'>");
Lars Hjemli5db39172007-05-22 23:08:46 +020049 cgit_print_date(info->committer_date, FMT_LONGDATE);
Lars Hjemli9a8f8862006-12-16 00:19:56 +010050 html("</td></tr>\n");
Lars Hjemli39912a22008-04-13 12:20:00 +020051 html("<tr><th>commit</th><td colspan='2' class='sha1'>");
52 tmp = sha1_to_hex(commit->object.sha1);
53 cgit_commit_link(tmp, NULL, NULL, ctx.qry.head, tmp);
54 html(" (");
55 cgit_patch_link("patch", NULL, NULL, NULL, tmp);
56 html(")</td></tr>\n");
Lars Hjemli44947bf2007-06-17 01:23:08 +020057 html("<tr><th>tree</th><td colspan='2' class='sha1'>");
58 tmp = xstrdup(hex);
59 cgit_tree_link(sha1_to_hex(commit->tree->object.sha1), NULL, NULL,
Lars Hjemlid14d77f2008-02-16 11:53:40 +010060 ctx.qry.head, tmp, NULL);
Lars Hjemli44947bf2007-06-17 01:23:08 +020061 html("</td></tr>\n");
Lars Hjemli9c5229e2006-12-16 19:35:31 +010062 for (p = commit->parents; p ; p = p->next) {
Lars Hjemli6a8749d2007-05-13 23:13:12 +020063 parent = lookup_commit_reference(p->item->object.sha1);
64 if (!parent) {
65 html("<tr><td colspan='3'>");
66 cgit_print_error("Error reading parent commit");
67 html("</td></tr>");
68 continue;
69 }
Lars Hjemli9c5229e2006-12-16 19:35:31 +010070 html("<tr><th>parent</th>"
Lars Hjemlifaaca442007-06-17 15:44:22 +020071 "<td colspan='2' class='sha1'>");
72 cgit_commit_link(sha1_to_hex(p->item->object.sha1), NULL, NULL,
Lars Hjemlid14d77f2008-02-16 11:53:40 +010073 ctx.qry.head, sha1_to_hex(p->item->object.sha1));
Lars Hjemli4a0be582007-06-17 18:12:03 +020074 html(" (");
Lars Hjemlid14d77f2008-02-16 11:53:40 +010075 cgit_diff_link("diff", NULL, NULL, ctx.qry.head, hex,
Lars Hjemli4a0be582007-06-17 18:12:03 +020076 sha1_to_hex(p->item->object.sha1), NULL);
77 html(")</td></tr>");
Lars Hjemli9a8f8862006-12-16 00:19:56 +010078 }
Lars Hjemlid1f3bbe2008-02-16 13:56:09 +010079 if (ctx.repo->snapshots) {
Michael Krelinf97c7072007-07-18 14:40:03 +020080 html("<tr><th>download</th><td colspan='2' class='sha1'>");
Lars Hjemlid14d77f2008-02-16 11:53:40 +010081 cgit_print_snapshot_links(ctx.qry.repo, ctx.qry.head,
Lars Hjemlid1f3bbe2008-02-16 13:56:09 +010082 hex, ctx.repo->snapshots);
Michael Krelinf97c7072007-07-18 14:40:03 +020083 html("</td></tr>");
Lars Hjemliac70cb42007-02-08 14:47:56 +010084 }
Lars Hjemli9a8f8862006-12-16 00:19:56 +010085 html("</table>\n");
86 html("<div class='commit-subject'>");
87 html_txt(info->subject);
88 html("</div>");
89 html("<div class='commit-msg'>");
90 html_txt(info->msg);
91 html("</div>");
Lars Hjemlife1230d2008-04-24 23:32:02 +020092 if (!(commit->parents && commit->parents->next &&
93 commit->parents->next->next)) {
94 tmp = sha1_to_hex(commit->parents->item->object.sha1);
95 cgit_print_diff(ctx.qry.sha1, tmp, NULL);
Lars Hjemli8a3685b2007-05-13 22:25:14 +020096 }
Lars Hjemliaaa24bd2006-12-16 14:58:20 +010097 cgit_free_commitinfo(info);
Lars Hjemli9a8f8862006-12-16 00:19:56 +010098}