all repos — cgit @ aaa24bdd30303128bded8487cd9f63b54c3b8dcd

a hyperfast web frontend for git written in c

ui-log.c (view raw)

 1/* ui-log.c: functions for log output
 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
11void print_commit(struct commit *commit)
12{
13	char buf[32];
14	struct commitinfo *info;
15	struct tm *time;
16
17	info = cgit_parse_commit(commit);
18	time = gmtime(&commit->date);
19	html("<tr><td>");
20	strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", time);
21	html_txt(buf);
22	html("</td><td>");
23	char *qry = fmt("id=%s", sha1_to_hex(commit->object.sha1));
24	char *url = cgit_pageurl(cgit_query_repo, "commit", qry);
25	html_link_open(url, NULL, NULL);
26	html_txt(info->subject);
27	html_link_close();
28	html("</td><td>");
29	html_txt(info->author);
30	html("</td></tr>\n");
31	cgit_free_commitinfo(info);
32}
33
34
35void cgit_print_log(const char *tip, int ofs, int cnt)
36{
37	struct rev_info rev;
38	struct commit *commit;
39	const char *argv[2] = {NULL, tip};
40	int i;
41	
42	init_revisions(&rev, NULL);
43	rev.abbrev = DEFAULT_ABBREV;
44	rev.commit_format = CMIT_FMT_DEFAULT;
45	rev.verbose_header = 1;
46	rev.show_root_diff = 0;
47	setup_revisions(2, argv, &rev, NULL);
48	prepare_revision_walk(&rev);
49
50	html("<h2>Log</h2>");
51	html("<table class='list log'>");
52	html("<tr><th class='left'>Date</th><th class='left'>Message</th><th class='left'>Author</th></tr>\n");
53
54	if (ofs<0)
55		ofs = 0;
56
57	for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; i++) {
58		free(commit->buffer);
59		commit->buffer = NULL;
60		free_commit_list(commit->parents);
61		commit->parents = NULL;
62	}
63
64	for (i = 0; i < cnt && (commit = get_revision(&rev)) != NULL; i++) {
65		print_commit(commit);
66		free(commit->buffer);
67		commit->buffer = NULL;
68		free_commit_list(commit->parents);
69		commit->parents = NULL;
70	}
71	html("</table>\n");
72
73	html("<div class='pager'>");
74	if (ofs > 0) {
75		html("&nbsp;<a href='");
76		html(cgit_pageurl(cgit_query_repo, cgit_query_page,
77				  fmt("h=%s&ofs=%d", tip, ofs-cnt)));
78		html("'>[prev]</a>&nbsp;");
79       	}
80
81	if ((commit = get_revision(&rev)) != NULL) {
82		html("&nbsp;<a href='");
83		html(cgit_pageurl(cgit_query_repo, "log",
84				  fmt("h=%s&ofs=%d", tip, ofs+cnt)));
85		html("'>[next]</a>&nbsp;");
86	}
87	html("</div>");
88}
89