all repos — cgit @ a92678b5f119811bccaca9c31b779c5ceed95572

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 Lars Hjemli
  4 *
  5 * Licensed under GNU General Public License v2
  6 *   (see COPYING for full license text)
  7 */
  8
  9#include "cgit.h"
 10#include "html.h"
 11#include "ui-shared.h"
 12#include "ui-diff.h"
 13#include "ui-log.h"
 14
 15void cgit_print_commit(char *hex, const char *prefix)
 16{
 17	struct commit *commit, *parent;
 18	struct commitinfo *info, *parent_info;
 19	struct commit_list *p;
 20	struct strbuf notes = STRBUF_INIT;
 21	unsigned char sha1[20];
 22	char *tmp, *tmp2;
 23	int parents = 0;
 24
 25	if (!hex)
 26		hex = ctx.qry.head;
 27
 28	if (get_sha1(hex, sha1)) {
 29		cgit_print_error(fmt("Bad object id: %s", hex));
 30		return;
 31	}
 32	commit = lookup_commit_reference(sha1);
 33	if (!commit) {
 34		cgit_print_error(fmt("Bad commit reference: %s", hex));
 35		return;
 36	}
 37	info = cgit_parse_commit(commit);
 38
 39	init_display_notes(NULL);
 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	html_txt(info->author);
 48	if (!ctx.cfg.noplainemail) {
 49		html(" ");
 50		html_txt(info->author_email);
 51	}
 52	html("</td><td class='right'>");
 53	cgit_print_date(info->author_date, FMT_LONGDATE, ctx.cfg.local_time);
 54	html("</td></tr>\n");
 55	html("<tr><th>committer</th><td>");
 56	html_txt(info->committer);
 57	if (!ctx.cfg.noplainemail) {
 58		html(" ");
 59		html_txt(info->committer_email);
 60	}
 61	html("</td><td class='right'>");
 62	cgit_print_date(info->committer_date, FMT_LONGDATE, ctx.cfg.local_time);
 63	html("</td></tr>\n");
 64	html("<tr><th>commit</th><td colspan='2' class='sha1'>");
 65	tmp = sha1_to_hex(commit->object.sha1);
 66	cgit_commit_link(tmp, NULL, NULL, ctx.qry.head, tmp, prefix, 0);
 67	html(" (");
 68	cgit_patch_link("patch", NULL, NULL, NULL, tmp, prefix);
 69	html(")</td></tr>\n");
 70	html("<tr><th>tree</th><td colspan='2' class='sha1'>");
 71	tmp = xstrdup(hex);
 72	cgit_tree_link(sha1_to_hex(commit->tree->object.sha1), NULL, NULL,
 73		       ctx.qry.head, tmp, NULL);
 74	if (prefix) {
 75		html(" /");
 76		cgit_tree_link(prefix, NULL, NULL, ctx.qry.head, tmp, prefix);
 77	}
 78	free(tmp);
 79	html("</td></tr>\n");
 80	for (p = commit->parents; p; p = p->next) {
 81		parent = lookup_commit_reference(p->item->object.sha1);
 82		if (!parent) {
 83			html("<tr><td colspan='3'>");
 84			cgit_print_error("Error reading parent commit");
 85			html("</td></tr>");
 86			continue;
 87		}
 88		html("<tr><th>parent</th>"
 89		     "<td colspan='2' class='sha1'>");
 90		tmp = tmp2 = sha1_to_hex(p->item->object.sha1);
 91		if (ctx.repo->enable_subject_links) {
 92			parent_info = cgit_parse_commit(parent);
 93			tmp2 = parent_info->subject;
 94		}
 95		cgit_commit_link(tmp2, NULL, NULL, ctx.qry.head, tmp, prefix, 0);
 96		html(" (");
 97		cgit_diff_link("diff", NULL, NULL, ctx.qry.head, hex,
 98			       sha1_to_hex(p->item->object.sha1), prefix, 0);
 99		html(")</td></tr>");
100		parents++;
101	}
102	if (ctx.repo->snapshots) {
103		html("<tr><th>download</th><td colspan='2' class='sha1'>");
104		cgit_print_snapshot_links(ctx.qry.repo, ctx.qry.head,
105					  hex, ctx.repo->snapshots);
106		html("</td></tr>");
107	}
108	html("</table>\n");
109	html("<div class='commit-subject'>");
110	if (ctx.repo->commit_filter)
111		cgit_open_filter(ctx.repo->commit_filter);
112	html_txt(info->subject);
113	if (ctx.repo->commit_filter)
114		cgit_close_filter(ctx.repo->commit_filter);
115	show_commit_decorations(commit);
116	html("</div>");
117	html("<div class='commit-msg'>");
118	if (ctx.repo->commit_filter)
119		cgit_open_filter(ctx.repo->commit_filter);
120	html_txt(info->msg);
121	if (ctx.repo->commit_filter)
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		if (ctx.repo->commit_filter)
128			cgit_open_filter(ctx.repo->commit_filter);
129		html_txt(notes.buf);
130		if (ctx.repo->commit_filter)
131			cgit_close_filter(ctx.repo->commit_filter);
132		html("</div>");
133		html("<div class='notes-footer'></div>");
134	}
135	if (parents < 3) {
136		if (parents)
137			tmp = sha1_to_hex(commit->parents->item->object.sha1);
138		else
139			tmp = NULL;
140		cgit_print_diff(ctx.qry.sha1, tmp, prefix, 0);
141	}
142	strbuf_release(&notes);
143	cgit_free_commitinfo(info);
144}