all repos — cgit @ ded9393b173853d2e960f9b176aeb0bc4ed35be2

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_ntxt(cgit_max_msg_len, 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, char *grep)
36{
37	struct rev_info rev;
38	struct commit *commit;
39	const char *argv[3] = {NULL, tip, NULL};
40	int argc = 2;
41	int i;
42	
43	if (grep)
44		argv[argc++] = fmt("--grep=%s", grep);
45	init_revisions(&rev, NULL);
46	rev.abbrev = DEFAULT_ABBREV;
47	rev.commit_format = CMIT_FMT_DEFAULT;
48	rev.verbose_header = 1;
49	rev.show_root_diff = 0;
50	setup_revisions(argc, argv, &rev, NULL);
51	if (rev.grep_filter) {
52		rev.grep_filter->regflags |= REG_ICASE;
53		compile_grep_patterns(rev.grep_filter);
54	}
55	prepare_revision_walk(&rev);
56
57	html("<table class='list nowrap'>");
58	html("<tr class='nohover'><th class='left'>Date</th>"
59	     "<th class='left'>Message</th>"
60	     "<th class='left'>Author</th></tr>\n");
61
62	if (ofs<0)
63		ofs = 0;
64
65	for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; i++) {
66		free(commit->buffer);
67		commit->buffer = NULL;
68		free_commit_list(commit->parents);
69		commit->parents = NULL;
70	}
71
72	for (i = 0; i < cnt && (commit = get_revision(&rev)) != NULL; i++) {
73		print_commit(commit);
74		free(commit->buffer);
75		commit->buffer = NULL;
76		free_commit_list(commit->parents);
77		commit->parents = NULL;
78	}
79	html("</table>\n");
80
81	html("<div class='pager'>");
82	if (ofs > 0) {
83		html("&nbsp;<a href='");
84		html(cgit_pageurl(cgit_query_repo, cgit_query_page,
85				  fmt("h=%s&ofs=%d", tip, ofs-cnt)));
86		html("'>[prev]</a>&nbsp;");
87       	}
88
89	if ((commit = get_revision(&rev)) != NULL) {
90		html("&nbsp;<a href='");
91		html(cgit_pageurl(cgit_query_repo, "log",
92				  fmt("h=%s&ofs=%d", tip, ofs+cnt)));
93		html("'>[next]</a>&nbsp;");
94	}
95	html("</div>");
96}
97