1 /* ui-log.c: functions for log output
3 * Copyright (C) 2006 Lars Hjemli
5 * Licensed under GNU General Public License v2
6 * (see COPYING for full license text)
13 void count_lines(char *line, int size)
15 if (size>0 && (line[0] == '+' || line[0] == '-'))
19 void inspect_files(struct diff_filepair *pair)
22 cgit_diff_files(pair->one->sha1, pair->two->sha1, count_lines);
25 void print_commit(struct commit *commit)
28 struct commitinfo *info;
31 info = cgit_parse_commit(commit);
32 time = gmtime(&commit->date);
34 strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M", time);
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);
44 cgit_diff_commit(commit, inspect_files);
45 html("</td><td class='right'>");
47 html("</td><td class='right'>");
50 html_txt(info->author);
52 cgit_free_commitinfo(info);
56 void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *path)
59 struct commit *commit;
60 const char *argv[] = {NULL, tip, NULL, NULL, NULL};
65 argv[argc++] = fmt("--grep=%s", grep);
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);
80 prepare_revision_walk(&rev);
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");
92 for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; i++) {
94 commit->buffer = NULL;
95 free_commit_list(commit->parents);
96 commit->parents = NULL;
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;
108 html("<div class='pager'>");
110 html(" <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> ");
116 if ((commit = get_revision(&rev)) != NULL) {
117 html(" <a href='");
118 html(cgit_pageurl(cgit_query_repo, "log",
119 fmt("h=%s&ofs=%d", tip, ofs+cnt)));
120 html("'>[next]</a> ");