all repos — cgit @ aa6d5b105de9de6d01855c15217e46fd36890dbc

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("Bad object id: %s", hex);
 31		return;
 32	}
 33	commit = lookup_commit_reference(sha1);
 34	if (!commit) {
 35		cgit_print_error("Bad commit reference: %s", hex);
 36		return;
 37	}
 38	info = cgit_parse_commit(commit);
 39
 40	format_display_notes(sha1, &notes, PAGE_ENCODING, 0);
 41
 42	load_ref_decorations(DECORATE_FULL_REFS);
 43
 44	cgit_print_diff_ctrls();
 45	html("<table summary='commit info' class='commit-info'>\n");
 46	html("<tr><th>author</th><td>");
 47	cgit_open_filter(ctx.repo->email_filter, info->author_email, "commit");
 48	html_txt(info->author);
 49	if (!ctx.cfg.noplainemail) {
 50		html(" ");
 51		html_txt(info->author_email);
 52	}
 53	cgit_close_filter(ctx.repo->email_filter);
 54	html("</td><td class='right'>");
 55	cgit_print_date(info->author_date, FMT_LONGDATE, ctx.cfg.local_time);
 56	html("</td></tr>\n");
 57	html("<tr><th>committer</th><td>");
 58	cgit_open_filter(ctx.repo->email_filter, info->committer_email, "commit");
 59	html_txt(info->committer);
 60	if (!ctx.cfg.noplainemail) {
 61		html(" ");
 62		html_txt(info->committer_email);
 63	}
 64	cgit_close_filter(ctx.repo->email_filter);
 65	html("</td><td class='right'>");
 66	cgit_print_date(info->committer_date, FMT_LONGDATE, ctx.cfg.local_time);
 67	html("</td></tr>\n");
 68	html("<tr><th>commit</th><td colspan='2' class='sha1'>");
 69	tmp = sha1_to_hex(commit->object.sha1);
 70	cgit_commit_link(tmp, NULL, NULL, ctx.qry.head, tmp, prefix, 0);
 71	html(" (");
 72	cgit_patch_link("patch", NULL, NULL, NULL, tmp, prefix);
 73	html(")</td></tr>\n");
 74	html("<tr><th>tree</th><td colspan='2' class='sha1'>");
 75	tmp = xstrdup(hex);
 76	cgit_tree_link(sha1_to_hex(commit->tree->object.sha1), NULL, NULL,
 77		       ctx.qry.head, tmp, NULL);
 78	if (prefix) {
 79		html(" /");
 80		cgit_tree_link(prefix, NULL, NULL, ctx.qry.head, tmp, prefix);
 81	}
 82	free(tmp);
 83	html("</td></tr>\n");
 84	for (p = commit->parents; p; p = p->next) {
 85		parent = lookup_commit_reference(p->item->object.sha1);
 86		if (!parent) {
 87			html("<tr><td colspan='3'>");
 88			cgit_print_error("Error reading parent commit");
 89			html("</td></tr>");
 90			continue;
 91		}
 92		html("<tr><th>parent</th>"
 93		     "<td colspan='2' class='sha1'>");
 94		tmp = tmp2 = sha1_to_hex(p->item->object.sha1);
 95		if (ctx.repo->enable_subject_links) {
 96			parent_info = cgit_parse_commit(parent);
 97			tmp2 = parent_info->subject;
 98		}
 99		cgit_commit_link(tmp2, NULL, NULL, ctx.qry.head, tmp, prefix, 0);
100		html(" (");
101		cgit_diff_link("diff", NULL, NULL, ctx.qry.head, hex,
102			       sha1_to_hex(p->item->object.sha1), prefix, 0);
103		html(")</td></tr>");
104		parents++;
105	}
106	if (ctx.repo->snapshots) {
107		html("<tr><th>download</th><td colspan='2' class='sha1'>");
108		cgit_print_snapshot_links(ctx.qry.repo, ctx.qry.head,
109					  hex, ctx.repo->snapshots);
110		html("</td></tr>");
111	}
112	html("</table>\n");
113	html("<div class='commit-subject'>");
114	cgit_open_filter(ctx.repo->commit_filter);
115	html_txt(info->subject);
116	cgit_close_filter(ctx.repo->commit_filter);
117	show_commit_decorations(commit);
118	html("</div>");
119	html("<div class='commit-msg'>");
120	cgit_open_filter(ctx.repo->commit_filter);
121	html_txt(info->msg);
122	cgit_close_filter(ctx.repo->commit_filter);
123	html("</div>");
124	if (notes.len != 0) {
125		html("<div class='notes-header'>Notes</div>");
126		html("<div class='notes'>");
127		cgit_open_filter(ctx.repo->commit_filter);
128		html_txt(notes.buf);
129		cgit_close_filter(ctx.repo->commit_filter);
130		html("</div>");
131		html("<div class='notes-footer'></div>");
132	}
133	if (parents < 3) {
134		if (parents)
135			tmp = sha1_to_hex(commit->parents->item->object.sha1);
136		else
137			tmp = NULL;
138		cgit_print_diff(ctx.qry.sha1, tmp, prefix, 0, 0);
139	}
140	strbuf_release(&notes);
141	cgit_free_commitinfo(info);
142}