all repos — cgit @ 9927e63f387e6c9328eb3c347ecb0e339f8ac023

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, char *path)
 57{
 58	struct rev_info rev;
 59	struct commit *commit;
 60	const char *argv[] = {NULL, tip, NULL, NULL, NULL};
 61	int argc = 2;
 62	int i;
 63
 64	if (grep)
 65		argv[argc++] = fmt("--grep=%s", grep);
 66	if (path) {
 67		argv[argc++] = "--";
 68		argv[argc++] = path;
 69	}
 70	init_revisions(&rev, NULL);
 71	rev.abbrev = DEFAULT_ABBREV;
 72	rev.commit_format = CMIT_FMT_DEFAULT;
 73	rev.verbose_header = 1;
 74	rev.show_root_diff = 0;
 75	setup_revisions(argc, argv, &rev, NULL);
 76	if (rev.grep_filter) {
 77		rev.grep_filter->regflags |= REG_ICASE;
 78		compile_grep_patterns(rev.grep_filter);
 79	}
 80	prepare_revision_walk(&rev);
 81
 82	html("<table class='list nowrap'>");
 83	html("<tr class='nohover'><th class='left'>Date</th>"
 84	     "<th class='left'>Message</th>"
 85	     "<th class='left'>Files</th>"
 86	     "<th class='left'>Lines</th>"
 87	     "<th class='left'>Author</th></tr>\n");
 88
 89	if (ofs<0)
 90		ofs = 0;
 91
 92	for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; i++) {
 93		free(commit->buffer);
 94		commit->buffer = NULL;
 95		free_commit_list(commit->parents);
 96		commit->parents = NULL;
 97	}
 98
 99	for (i = 0; i < cnt && (commit = get_revision(&rev)) != NULL; i++) {
100		print_commit(commit);
101		free(commit->buffer);
102		commit->buffer = NULL;
103		free_commit_list(commit->parents);
104		commit->parents = NULL;
105	}
106	html("</table>\n");
107
108	html("<div class='pager'>");
109	if (ofs > 0) {
110		html("&nbsp;<a href='");
111		html(cgit_pageurl(cgit_query_repo, cgit_query_page,
112				  fmt("h=%s&ofs=%d", tip, ofs-cnt)));
113		html("'>[prev]</a>&nbsp;");
114       	}
115
116	if ((commit = get_revision(&rev)) != NULL) {
117		html("&nbsp;<a href='");
118		html(cgit_pageurl(cgit_query_repo, "log",
119				  fmt("h=%s&ofs=%d", tip, ofs+cnt)));
120		html("'>[next]</a>&nbsp;");
121	}
122	html("</div>");
123}
124