all repos — cgit @ v0.4

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
 11int files, lines;
 12
 13void count_lines(char *line, int size)
 14{
 15	if (size>0 && (line[0] == '+' || line[0] == '-'))
 16		lines++;
 17}
 18
 19void inspect_files(struct diff_filepair *pair)
 20{
 21	files++;
 22	cgit_diff_files(pair->one->sha1, pair->two->sha1, count_lines);
 23}
 24
 25void print_commit(struct commit *commit)
 26{
 27	char buf[32];
 28	struct commitinfo *info;
 29	struct tm *time;
 30
 31	info = cgit_parse_commit(commit);
 32	time = gmtime(&commit->date);
 33	html("<tr><td>");
 34	strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M", time);
 35	html_txt(buf);
 36	html("</td><td>");
 37	char *qry = fmt("id=%s", sha1_to_hex(commit->object.sha1));
 38	char *url = cgit_pageurl(cgit_query_repo, "commit", qry);
 39	html_link_open(url, NULL, NULL);
 40	html_ntxt(cgit_max_msg_len, info->subject);
 41	html_link_close();
 42	files = 0;
 43	lines = 0;
 44	cgit_diff_commit(commit, inspect_files);
 45	html("</td><td class='right'>");
 46	htmlf("%d", files);
 47	html("</td><td class='right'>");
 48	htmlf("%d", lines);
 49	html("</td><td>");
 50	html_txt(info->author);
 51	html("</td></tr>\n");
 52	cgit_free_commitinfo(info);
 53}
 54
 55
 56void cgit_print_log(const char *tip, int ofs, int cnt, char *grep)
 57{
 58	struct rev_info rev;
 59	struct commit *commit;
 60	const char *argv[3] = {NULL, tip, NULL};
 61	int argc = 2;
 62	int i;
 63
 64	if (grep)
 65		argv[argc++] = fmt("--grep=%s", grep);
 66	init_revisions(&rev, NULL);
 67	rev.abbrev = DEFAULT_ABBREV;
 68	rev.commit_format = CMIT_FMT_DEFAULT;
 69	rev.verbose_header = 1;
 70	rev.show_root_diff = 0;
 71	setup_revisions(argc, argv, &rev, NULL);
 72	if (rev.grep_filter) {
 73		rev.grep_filter->regflags |= REG_ICASE;
 74		compile_grep_patterns(rev.grep_filter);
 75	}
 76	prepare_revision_walk(&rev);
 77
 78	html("<table class='list nowrap'>");
 79	html("<tr class='nohover'><th class='left'>Date</th>"
 80	     "<th class='left'>Message</th>"
 81	     "<th class='left'>Files</th>"
 82	     "<th class='left'>Lines</th>"
 83	     "<th class='left'>Author</th></tr>\n");
 84
 85	if (ofs<0)
 86		ofs = 0;
 87
 88	for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; i++) {
 89		free(commit->buffer);
 90		commit->buffer = NULL;
 91		free_commit_list(commit->parents);
 92		commit->parents = NULL;
 93	}
 94
 95	for (i = 0; i < cnt && (commit = get_revision(&rev)) != NULL; i++) {
 96		print_commit(commit);
 97		free(commit->buffer);
 98		commit->buffer = NULL;
 99		free_commit_list(commit->parents);
100		commit->parents = NULL;
101	}
102	html("</table>\n");
103
104	html("<div class='pager'>");
105	if (ofs > 0) {
106		html("&nbsp;<a href='");
107		html(cgit_pageurl(cgit_query_repo, cgit_query_page,
108				  fmt("h=%s&ofs=%d", tip, ofs-cnt)));
109		html("'>[prev]</a>&nbsp;");
110       	}
111
112	if ((commit = get_revision(&rev)) != NULL) {
113		html("&nbsp;<a href='");
114		html(cgit_pageurl(cgit_query_repo, "log",
115				  fmt("h=%s&ofs=%d", tip, ofs+cnt)));
116		html("'>[next]</a>&nbsp;");
117	}
118	html("</div>");
119}
120