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)
11 #include "ui-shared.h"
13 int files, add_lines, rem_lines;
15 void count_lines(char *line, int size)
23 else if (line[0] == '-')
27 void inspect_files(struct diff_filepair *pair)
30 if (ctx.repo->enable_log_linecount)
31 cgit_diff_files(pair->one->sha1, pair->two->sha1, count_lines);
34 void print_commit(struct commit *commit)
36 struct commitinfo *info;
38 info = cgit_parse_commit(commit);
40 cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE);
42 cgit_commit_link(info->subject, NULL, NULL, ctx.qry.head,
43 sha1_to_hex(commit->object.sha1));
45 html_txt(info->author);
46 if (ctx.repo->enable_log_filecount) {
50 cgit_diff_commit(commit, inspect_files);
53 if (ctx.repo->enable_log_linecount) {
55 htmlf("-%d/+%d", rem_lines, add_lines);
59 cgit_free_commitinfo(info);
63 void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern,
64 char *path, int pager)
67 struct commit *commit;
68 const char *argv[] = {NULL, tip, NULL, NULL, NULL};
73 argv[1] = ctx.qry.head;
75 if (grep && pattern && (!strcmp(grep, "grep") ||
76 !strcmp(grep, "author") ||
77 !strcmp(grep, "committer")))
78 argv[argc++] = fmt("--%s=%s", grep, pattern);
84 init_revisions(&rev, NULL);
85 rev.abbrev = DEFAULT_ABBREV;
86 rev.commit_format = CMIT_FMT_DEFAULT;
87 rev.verbose_header = 1;
88 rev.show_root_diff = 0;
89 setup_revisions(argc, argv, &rev, NULL);
90 if (rev.grep_filter) {
91 rev.grep_filter->regflags |= REG_ICASE;
92 compile_grep_patterns(rev.grep_filter);
94 prepare_revision_walk(&rev);
97 html("<table class='list nowrap'>");
99 html("<tr class='nohover'><th class='left'>Age</th>"
100 "<th class='left'>Commit message</th>"
101 "<th class='left'>Author</th>");
102 if (ctx.repo->enable_log_filecount) {
103 html("<th class='left'>Files</th>");
105 if (ctx.repo->enable_log_linecount) {
106 html("<th class='left'>Lines</th>");
115 for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; i++) {
116 free(commit->buffer);
117 commit->buffer = NULL;
118 free_commit_list(commit->parents);
119 commit->parents = NULL;
122 for (i = 0; i < cnt && (commit = get_revision(&rev)) != NULL; i++) {
123 print_commit(commit);
124 free(commit->buffer);
125 commit->buffer = NULL;
126 free_commit_list(commit->parents);
127 commit->parents = NULL;
130 htmlf("</table><div class='pager'>",
133 cgit_log_link("[prev]", NULL, NULL, ctx.qry.head,
134 ctx.qry.sha1, ctx.qry.path,
135 ofs - cnt, ctx.qry.grep,
139 if ((commit = get_revision(&rev)) != NULL) {
140 cgit_log_link("[next]", NULL, NULL, ctx.qry.head,
141 ctx.qry.sha1, ctx.qry.path,
142 ofs + cnt, ctx.qry.grep,
146 } else if ((commit = get_revision(&rev)) != NULL) {
147 html("<tr class='nohover'><td colspan='3'>");
148 cgit_log_link("[...]", NULL, NULL, ctx.qry.head, NULL, NULL, 0,
150 html("</td></tr>\n");