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;
40 info = cgit_parse_commit(commit);
42 tmp = fmt("id=%s", sha1_to_hex(commit->object.sha1));
43 tmp = cgit_pageurl(ctx.repo->url, "commit", tmp);
44 html_link_open(tmp, NULL, NULL);
45 cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE);
50 cgit_commit_link(info->subject, NULL, NULL, ctx.qry.head,
51 sha1_to_hex(commit->object.sha1));
55 html_txt(info->author);
56 if (ctx.repo->enable_log_filecount) {
60 cgit_diff_commit(commit, inspect_files);
63 if (ctx.repo->enable_log_linecount) {
65 htmlf("-%d/+%d", rem_lines, add_lines);
69 if (ctx.qry.showmsg) {
70 if (ctx.repo->enable_log_filecount) {
72 if (ctx.repo->enable_log_linecount)
75 htmlf("<tr class='nohover'><td></td><td colspan='%d'><div class='commit-msg'>",
78 html("</div><br/></td></tr>\n");
80 cgit_free_commitinfo(info);
84 void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern,
85 char *path, int pager)
88 struct commit *commit;
89 const char *argv[] = {NULL, tip, NULL, NULL, NULL};
94 argv[1] = ctx.qry.head;
96 if (grep && pattern && (!strcmp(grep, "grep") ||
97 !strcmp(grep, "author") ||
98 !strcmp(grep, "committer")))
99 argv[argc++] = fmt("--%s=%s", grep, pattern);
105 init_revisions(&rev, NULL);
106 rev.abbrev = DEFAULT_ABBREV;
107 rev.commit_format = CMIT_FMT_DEFAULT;
108 rev.verbose_header = 1;
109 rev.show_root_diff = 0;
110 setup_revisions(argc, argv, &rev, NULL);
111 rev.grep_filter.regflags |= REG_ICASE;
112 compile_grep_patterns(&rev.grep_filter);
113 prepare_revision_walk(&rev);
116 html("<table class='list nowrap'>");
118 html("<tr class='nohover'><th class='left'>Age</th>"
119 "<th class='left'>Commit message");
122 cgit_log_link("toggle", NULL, NULL, ctx.qry.head, ctx.qry.sha1,
123 ctx.qry.path, ctx.qry.ofs, ctx.qry.grep,
124 ctx.qry.search, ctx.qry.showmsg ? 0 : 1);
127 html("</th><th class='left'>Author</th>");
128 if (ctx.repo->enable_log_filecount) {
129 html("<th class='left'>Files</th>");
131 if (ctx.repo->enable_log_linecount) {
132 html("<th class='left'>Lines</th>");
141 for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; i++) {
142 free(commit->buffer);
143 commit->buffer = NULL;
144 free_commit_list(commit->parents);
145 commit->parents = NULL;
148 for (i = 0; i < cnt && (commit = get_revision(&rev)) != NULL; i++) {
149 print_commit(commit);
150 free(commit->buffer);
151 commit->buffer = NULL;
152 free_commit_list(commit->parents);
153 commit->parents = NULL;
156 htmlf("</table><div class='pager'>",
159 cgit_log_link("[prev]", NULL, NULL, ctx.qry.head,
160 ctx.qry.sha1, ctx.qry.path,
161 ofs - cnt, ctx.qry.grep,
162 ctx.qry.search, ctx.qry.showmsg);
165 if ((commit = get_revision(&rev)) != NULL) {
166 cgit_log_link("[next]", NULL, NULL, ctx.qry.head,
167 ctx.qry.sha1, ctx.qry.path,
168 ofs + cnt, ctx.qry.grep,
169 ctx.qry.search, ctx.qry.showmsg);
172 } else if ((commit = get_revision(&rev)) != NULL) {
173 html("<tr class='nohover'><td colspan='3'>");
174 cgit_log_link("[...]", NULL, NULL, ctx.qry.head, NULL, NULL, 0,
175 NULL, NULL, ctx.qry.showmsg);
176 html("</td></tr>\n");