2006-12-16 00:11:55 +00:00
|
|
|
/* ui-commit.c: generate commit view
|
|
|
|
*
|
2014-01-08 14:10:49 +00:00
|
|
|
* Copyright (C) 2006-2014 cgit Development Team <cgit@lists.zx2c4.com>
|
2006-12-16 00:11:55 +00:00
|
|
|
*
|
|
|
|
* Licensed under GNU General Public License v2
|
|
|
|
* (see COPYING for full license text)
|
|
|
|
*/
|
|
|
|
|
2006-12-15 23:19:56 +00:00
|
|
|
#include "cgit.h"
|
2013-04-06 10:37:59 +00:00
|
|
|
#include "ui-commit.h"
|
2008-02-23 21:45:33 +00:00
|
|
|
#include "html.h"
|
2008-03-24 15:50:57 +00:00
|
|
|
#include "ui-shared.h"
|
2008-04-12 13:53:53 +00:00
|
|
|
#include "ui-diff.h"
|
2009-01-12 15:23:28 +00:00
|
|
|
#include "ui-log.h"
|
2006-12-15 23:19:56 +00:00
|
|
|
|
2010-06-09 23:09:32 +00:00
|
|
|
void cgit_print_commit(char *hex, const char *prefix)
|
2006-12-15 23:19:56 +00:00
|
|
|
{
|
2007-05-13 21:13:12 +00:00
|
|
|
struct commit *commit, *parent;
|
2010-02-15 08:57:50 +00:00
|
|
|
struct commitinfo *info, *parent_info;
|
2006-12-15 23:19:56 +00:00
|
|
|
struct commit_list *p;
|
2010-07-29 14:32:30 +00:00
|
|
|
struct strbuf notes = STRBUF_INIT;
|
2016-09-29 19:41:09 +00:00
|
|
|
struct object_id oid;
|
2010-02-27 12:12:55 +00:00
|
|
|
char *tmp, *tmp2;
|
2008-05-18 19:09:26 +00:00
|
|
|
int parents = 0;
|
2006-12-15 23:19:56 +00:00
|
|
|
|
2007-06-17 12:53:02 +00:00
|
|
|
if (!hex)
|
2008-02-16 10:53:40 +00:00
|
|
|
hex = ctx.qry.head;
|
2007-06-17 12:53:02 +00:00
|
|
|
|
2023-05-16 15:02:27 +00:00
|
|
|
if (repo_get_oid(the_repository, hex, &oid)) {
|
2015-08-14 11:47:13 +00:00
|
|
|
cgit_print_error_page(400, "Bad request",
|
|
|
|
"Bad object id: %s", hex);
|
2006-12-15 23:19:56 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-08-28 16:27:00 +00:00
|
|
|
commit = lookup_commit_reference(the_repository, &oid);
|
2006-12-15 23:19:56 +00:00
|
|
|
if (!commit) {
|
2015-08-14 11:47:13 +00:00
|
|
|
cgit_print_error_page(404, "Not found",
|
|
|
|
"Bad commit reference: %s", hex);
|
2006-12-15 23:19:56 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
info = cgit_parse_commit(commit);
|
|
|
|
|
2019-05-26 16:57:01 +00:00
|
|
|
format_display_notes(&oid, ¬es, PAGE_ENCODING, 1);
|
2010-07-29 14:32:30 +00:00
|
|
|
|
2018-01-18 08:19:31 +00:00
|
|
|
load_ref_decorations(NULL, DECORATE_FULL_REFS);
|
2013-03-03 15:04:29 +00:00
|
|
|
|
2020-02-21 08:07:50 +00:00
|
|
|
ctx.page.title = fmtalloc("%s - %s", info->subject, ctx.page.title);
|
2015-08-14 11:47:13 +00:00
|
|
|
cgit_print_layout_start();
|
2011-03-06 22:59:56 +00:00
|
|
|
cgit_print_diff_ctrls();
|
2007-11-11 12:04:28 +00:00
|
|
|
html("<table summary='commit info' class='commit-info'>\n");
|
2006-12-16 13:28:26 +00:00
|
|
|
html("<tr><th>author</th><td>");
|
2014-01-13 15:24:40 +00:00
|
|
|
cgit_open_filter(ctx.repo->email_filter, info->author_email, "commit");
|
2006-12-15 23:19:56 +00:00
|
|
|
html_txt(info->author);
|
2009-08-07 12:05:17 +00:00
|
|
|
if (!ctx.cfg.noplainemail) {
|
|
|
|
html(" ");
|
|
|
|
html_txt(info->author_email);
|
|
|
|
}
|
2014-01-13 03:04:52 +00:00
|
|
|
cgit_close_filter(ctx.repo->email_filter);
|
2006-12-16 13:28:26 +00:00
|
|
|
html("</td><td class='right'>");
|
2016-01-19 19:33:04 +00:00
|
|
|
html_txt(show_date(info->author_date, info->author_tz,
|
2016-02-08 15:05:54 +00:00
|
|
|
cgit_date_mode(DATE_ISO8601)));
|
2006-12-15 23:19:56 +00:00
|
|
|
html("</td></tr>\n");
|
|
|
|
html("<tr><th>committer</th><td>");
|
2014-01-13 15:24:40 +00:00
|
|
|
cgit_open_filter(ctx.repo->email_filter, info->committer_email, "commit");
|
2006-12-15 23:19:56 +00:00
|
|
|
html_txt(info->committer);
|
2009-08-07 12:05:17 +00:00
|
|
|
if (!ctx.cfg.noplainemail) {
|
|
|
|
html(" ");
|
|
|
|
html_txt(info->committer_email);
|
|
|
|
}
|
2014-01-13 03:04:52 +00:00
|
|
|
cgit_close_filter(ctx.repo->email_filter);
|
2006-12-15 23:19:56 +00:00
|
|
|
html("</td><td class='right'>");
|
2016-01-19 19:33:04 +00:00
|
|
|
html_txt(show_date(info->committer_date, info->committer_tz,
|
2016-02-08 15:05:54 +00:00
|
|
|
cgit_date_mode(DATE_ISO8601)));
|
2006-12-15 23:19:56 +00:00
|
|
|
html("</td></tr>\n");
|
2020-10-20 21:32:45 +00:00
|
|
|
html("<tr><th>commit</th><td colspan='2' class='oid'>");
|
2016-01-05 06:38:53 +00:00
|
|
|
tmp = oid_to_hex(&commit->object.oid);
|
2014-10-05 09:59:02 +00:00
|
|
|
cgit_commit_link(tmp, NULL, NULL, ctx.qry.head, tmp, prefix);
|
2008-04-13 10:20:00 +00:00
|
|
|
html(" (");
|
2010-06-09 23:09:33 +00:00
|
|
|
cgit_patch_link("patch", NULL, NULL, NULL, tmp, prefix);
|
2008-04-13 10:20:00 +00:00
|
|
|
html(")</td></tr>\n");
|
2020-10-20 21:32:45 +00:00
|
|
|
html("<tr><th>tree</th><td colspan='2' class='oid'>");
|
2007-06-16 23:23:08 +00:00
|
|
|
tmp = xstrdup(hex);
|
2020-03-13 02:52:35 +00:00
|
|
|
cgit_tree_link(oid_to_hex(get_commit_tree_oid(commit)), NULL, NULL,
|
2008-02-16 10:53:40 +00:00
|
|
|
ctx.qry.head, tmp, NULL);
|
2010-06-09 23:09:34 +00:00
|
|
|
if (prefix) {
|
|
|
|
html(" /");
|
|
|
|
cgit_tree_link(prefix, NULL, NULL, ctx.qry.head, tmp, prefix);
|
|
|
|
}
|
2013-03-04 12:25:37 +00:00
|
|
|
free(tmp);
|
2007-06-16 23:23:08 +00:00
|
|
|
html("</td></tr>\n");
|
2013-03-03 15:04:29 +00:00
|
|
|
for (p = commit->parents; p; p = p->next) {
|
2018-08-28 16:27:00 +00:00
|
|
|
parent = lookup_commit_reference(the_repository, &p->item->object.oid);
|
2007-05-13 21:13:12 +00:00
|
|
|
if (!parent) {
|
|
|
|
html("<tr><td colspan='3'>");
|
|
|
|
cgit_print_error("Error reading parent commit");
|
|
|
|
html("</td></tr>");
|
|
|
|
continue;
|
|
|
|
}
|
2006-12-16 18:35:31 +00:00
|
|
|
html("<tr><th>parent</th>"
|
2020-10-20 21:32:45 +00:00
|
|
|
"<td colspan='2' class='oid'>");
|
2016-01-05 06:38:53 +00:00
|
|
|
tmp = tmp2 = oid_to_hex(&p->item->object.oid);
|
2010-02-27 12:12:55 +00:00
|
|
|
if (ctx.repo->enable_subject_links) {
|
|
|
|
parent_info = cgit_parse_commit(parent);
|
|
|
|
tmp2 = parent_info->subject;
|
|
|
|
}
|
2014-10-05 09:59:02 +00:00
|
|
|
cgit_commit_link(tmp2, NULL, NULL, ctx.qry.head, tmp, prefix);
|
2007-06-17 16:12:03 +00:00
|
|
|
html(" (");
|
2008-02-16 10:53:40 +00:00
|
|
|
cgit_diff_link("diff", NULL, NULL, ctx.qry.head, hex,
|
2016-01-05 06:38:53 +00:00
|
|
|
oid_to_hex(&p->item->object.oid), prefix);
|
2007-06-17 16:12:03 +00:00
|
|
|
html(")</td></tr>");
|
2008-05-18 19:09:26 +00:00
|
|
|
parents++;
|
2006-12-15 23:19:56 +00:00
|
|
|
}
|
2008-02-16 12:56:09 +00:00
|
|
|
if (ctx.repo->snapshots) {
|
2020-10-20 21:32:45 +00:00
|
|
|
html("<tr><th>download</th><td colspan='2' class='oid'>");
|
2018-03-31 14:08:59 +00:00
|
|
|
cgit_print_snapshot_links(ctx.repo, hex, "<br/>");
|
2007-07-18 12:40:03 +00:00
|
|
|
html("</td></tr>");
|
2007-02-08 13:47:56 +00:00
|
|
|
}
|
2006-12-15 23:19:56 +00:00
|
|
|
html("</table>\n");
|
|
|
|
html("<div class='commit-subject'>");
|
2014-01-13 02:56:50 +00:00
|
|
|
cgit_open_filter(ctx.repo->commit_filter);
|
2006-12-15 23:19:56 +00:00
|
|
|
html_txt(info->subject);
|
2014-01-13 02:56:50 +00:00
|
|
|
cgit_close_filter(ctx.repo->commit_filter);
|
2009-01-12 15:23:28 +00:00
|
|
|
show_commit_decorations(commit);
|
2006-12-15 23:19:56 +00:00
|
|
|
html("</div>");
|
|
|
|
html("<div class='commit-msg'>");
|
2014-01-13 02:56:50 +00:00
|
|
|
cgit_open_filter(ctx.repo->commit_filter);
|
2006-12-15 23:19:56 +00:00
|
|
|
html_txt(info->msg);
|
2014-01-13 02:56:50 +00:00
|
|
|
cgit_close_filter(ctx.repo->commit_filter);
|
2006-12-15 23:19:56 +00:00
|
|
|
html("</div>");
|
2010-07-29 14:32:30 +00:00
|
|
|
if (notes.len != 0) {
|
|
|
|
html("<div class='notes-header'>Notes</div>");
|
|
|
|
html("<div class='notes'>");
|
2014-01-13 02:56:50 +00:00
|
|
|
cgit_open_filter(ctx.repo->commit_filter);
|
2010-07-29 14:32:30 +00:00
|
|
|
html_txt(notes.buf);
|
2014-01-13 02:56:50 +00:00
|
|
|
cgit_close_filter(ctx.repo->commit_filter);
|
2010-07-29 14:32:30 +00:00
|
|
|
html("</div>");
|
|
|
|
html("<div class='notes-footer'></div>");
|
|
|
|
}
|
2008-05-18 19:09:26 +00:00
|
|
|
if (parents < 3) {
|
|
|
|
if (parents)
|
2016-01-05 06:38:53 +00:00
|
|
|
tmp = oid_to_hex(&commit->parents->item->object.oid);
|
2008-05-18 19:09:26 +00:00
|
|
|
else
|
|
|
|
tmp = NULL;
|
2020-10-20 21:32:45 +00:00
|
|
|
cgit_print_diff(ctx.qry.oid, tmp, prefix, 0, 0);
|
2007-05-13 20:25:14 +00:00
|
|
|
}
|
2010-07-29 14:32:30 +00:00
|
|
|
strbuf_release(¬es);
|
2006-12-16 13:58:20 +00:00
|
|
|
cgit_free_commitinfo(info);
|
2015-08-14 11:47:13 +00:00
|
|
|
cgit_print_layout_end();
|
2006-12-15 23:19:56 +00:00
|
|
|
}
|