all repos — cgit @ 1e039ada8554c7e2fc65524827c61613a24256fb

a hyperfast web frontend for git written in c

ui-commit.c (view raw)

  1/* ui-commit.c: generate commit view
  2 *
  3 * Copyright (C) 2006-2014 cgit Development Team <cgit@lists.zx2c4.com>
  4 *
  5 * Licensed under GNU General Public License v2
  6 *   (see COPYING for full license text)
  7 */
  8
  9#include "cgit.h"
 10#include "ui-commit.h"
 11#include "html.h"
 12#include "ui-shared.h"
 13#include "ui-diff.h"
 14#include "ui-log.h"
 15
 16void cgit_print_commit(char *hex, const char *prefix)
 17{
 18	struct commit *commit, *parent;
 19	struct commitinfo *info, *parent_info;
 20	struct commit_list *p;
 21	struct strbuf notes = STRBUF_INIT;
 22	unsigned char sha1[20];
 23	char *tmp, *tmp2;
 24	int parents = 0;
 25
 26	if (!hex)
 27		hex = ctx.qry.head;
 28
 29	if (get_sha1(hex, sha1)) {
 30		cgit_print_error_page(400, "Bad request",
 31				"Bad object id: %s", hex);
 32		return;
 33	}
 34	commit = lookup_commit_reference(sha1);
 35	if (!commit) {
 36		cgit_print_error_page(404, "Not found",
 37				"Bad commit reference: %s", hex);
 38		return;
 39	}
 40	info = cgit_parse_commit(commit);
 41
 42	format_display_notes(sha1, &notes, PAGE_ENCODING, 0);
 43
 44	load_ref_decorations(DECORATE_FULL_REFS);
 45
 46	cgit_print_layout_start();
 47	cgit_print_diff_ctrls();
 48	html("<table summary='commit info' class='commit-info'>\n");
 49	html("<tr><th>author</th><td>");
 50	cgit_open_filter(ctx.repo->email_filter, info->author_email, "commit");
 51	html_txt(info->author);
 52	if (!ctx.cfg.noplainemail) {
 53		html(" ");
 54		html_txt(info->author_email);
 55	}
 56	cgit_close_filter(ctx.repo->email_filter);
 57	html("</td><td class='right'>");
 58	html_txt(show_date(info->author_date, info->author_tz,
 59				cgit_date_mode(DATE_ISO8601)));
 60	html("</td></tr>\n");
 61	html("<tr><th>committer</th><td>");
 62	cgit_open_filter(ctx.repo->email_filter, info->committer_email, "commit");
 63	html_txt(info->committer);
 64	if (!ctx.cfg.noplainemail) {
 65		html(" ");
 66		html_txt(info->committer_email);
 67	}
 68	cgit_close_filter(ctx.repo->email_filter);
 69	html("</td><td class='right'>");
 70	html_txt(show_date(info->committer_date, info->committer_tz,
 71				cgit_date_mode(DATE_ISO8601)));
 72	html("</td></tr>\n");
 73	html("<tr><th>commit</th><td colspan='2' class='sha1'>");
 74	tmp = oid_to_hex(&commit->object.oid);
 75	cgit_commit_link(tmp, NULL, NULL, ctx.qry.head, tmp, prefix);
 76	html(" (");
 77	cgit_patch_link("patch", NULL, NULL, NULL, tmp, prefix);
 78	html(")</td></tr>\n");
 79	html("<tr><th>tree</th><td colspan='2' class='sha1'>");
 80	tmp = xstrdup(hex);
 81	cgit_tree_link(oid_to_hex(&commit->tree->object.oid), NULL, NULL,
 82		       ctx.qry.head, tmp, NULL);
 83	if (prefix) {
 84		html(" /");
 85		cgit_tree_link(prefix, NULL, NULL, ctx.qry.head, tmp, prefix);
 86	}
 87	free(tmp);
 88	html("</td></tr>\n");
 89	for (p = commit->parents; p; p = p->next) {
 90		parent = lookup_commit_reference(p->item->object.oid.hash);
 91		if (!parent) {
 92			html("<tr><td colspan='3'>");
 93			cgit_print_error("Error reading parent commit");
 94			html("</td></tr>");
 95			continue;
 96		}
 97		html("<tr><th>parent</th>"
 98		     "<td colspan='2' class='sha1'>");
 99		tmp = tmp2 = oid_to_hex(&p->item->object.oid);
100		if (ctx.repo->enable_subject_links) {
101			parent_info = cgit_parse_commit(parent);
102			tmp2 = parent_info->subject;
103		}
104		cgit_commit_link(tmp2, NULL, NULL, ctx.qry.head, tmp, prefix);
105		html(" (");
106		cgit_diff_link("diff", NULL, NULL, ctx.qry.head, hex,
107			       oid_to_hex(&p->item->object.oid), prefix);
108		html(")</td></tr>");
109		parents++;
110	}
111	if (ctx.repo->snapshots) {
112		html("<tr><th>download</th><td colspan='2' class='sha1'>");
113		cgit_print_snapshot_links(ctx.qry.repo, ctx.qry.head,
114					  hex, ctx.repo->snapshots);
115		html("</td></tr>");
116	}
117	html("</table>\n");
118	html("<div class='commit-subject'>");
119	cgit_open_filter(ctx.repo->commit_filter);
120	html_txt(info->subject);
121	cgit_close_filter(ctx.repo->commit_filter);
122	show_commit_decorations(commit);
123	html("</div>");
124	html("<div class='commit-msg'>");
125	cgit_open_filter(ctx.repo->commit_filter);
126	html_txt(info->msg);
127	cgit_close_filter(ctx.repo->commit_filter);
128	html("</div>");
129	if (notes.len != 0) {
130		html("<div class='notes-header'>Notes</div>");
131		html("<div class='notes'>");
132		cgit_open_filter(ctx.repo->commit_filter);
133		html_txt(notes.buf);
134		cgit_close_filter(ctx.repo->commit_filter);
135		html("</div>");
136		html("<div class='notes-footer'></div>");
137	}
138	if (parents < 3) {
139		if (parents)
140			tmp = oid_to_hex(&commit->parents->item->object.oid);
141		else
142			tmp = NULL;
143		cgit_print_diff(ctx.qry.sha1, tmp, prefix, 0, 0);
144	}
145	strbuf_release(&notes);
146	cgit_free_commitinfo(info);
147	cgit_print_layout_end();
148}