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 ctx.qry.showmsg ? " class='logheader'" : "");
43 tmp = fmt("id=%s", sha1_to_hex(commit->object.sha1));
44 tmp = cgit_pageurl(ctx.repo->url, "commit", tmp);
45 html_link_open(tmp, NULL, NULL);
46 cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE);
49 ctx.qry.showmsg ? " class='logsubject'" : "");
50 cgit_commit_link(info->subject, NULL, NULL, ctx.qry.head,
51 sha1_to_hex(commit->object.sha1));
53 html_txt(info->author);
54 if (ctx.repo->enable_log_filecount) {
58 cgit_diff_commit(commit, inspect_files);
61 if (ctx.repo->enable_log_linecount) {
63 htmlf("-%d/+%d", rem_lines, add_lines);
67 if (ctx.qry.showmsg) {
68 if (ctx.repo->enable_log_filecount) {
70 if (ctx.repo->enable_log_linecount)
73 htmlf("<tr class='nohover'><td/><td colspan='%d' class='logmsg'>",
78 cgit_free_commitinfo(info);
82 void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern,
83 char *path, int pager)
86 struct commit *commit;
87 const char *argv[] = {NULL, tip, NULL, NULL, NULL};
92 argv[1] = ctx.qry.head;
94 if (grep && pattern && (!strcmp(grep, "grep") ||
95 !strcmp(grep, "author") ||
96 !strcmp(grep, "committer")))
97 argv[argc++] = fmt("--%s=%s", grep, pattern);
103 init_revisions(&rev, NULL);
104 rev.abbrev = DEFAULT_ABBREV;
105 rev.commit_format = CMIT_FMT_DEFAULT;
106 rev.verbose_header = 1;
107 rev.show_root_diff = 0;
108 setup_revisions(argc, argv, &rev, NULL);
109 rev.grep_filter.regflags |= REG_ICASE;
110 compile_grep_patterns(&rev.grep_filter);
111 prepare_revision_walk(&rev);
114 html("<table class='list nowrap'>");
116 html("<tr class='nohover'><th class='left'>Age</th>"
117 "<th class='left'>Commit message");
120 cgit_log_link("toggle", NULL, NULL, ctx.qry.head, ctx.qry.sha1,
121 ctx.qry.path, ctx.qry.ofs, ctx.qry.grep,
122 ctx.qry.search, ctx.qry.showmsg ? 0 : 1);
125 html("</th><th class='left'>Author</th>");
126 if (ctx.repo->enable_log_filecount) {
127 html("<th class='left'>Files</th>");
129 if (ctx.repo->enable_log_linecount) {
130 html("<th class='left'>Lines</th>");
139 for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; i++) {
140 free(commit->buffer);
141 commit->buffer = NULL;
142 free_commit_list(commit->parents);
143 commit->parents = NULL;
146 for (i = 0; i < cnt && (commit = get_revision(&rev)) != NULL; i++) {
147 print_commit(commit);
148 free(commit->buffer);
149 commit->buffer = NULL;
150 free_commit_list(commit->parents);
151 commit->parents = NULL;
154 htmlf("</table><div class='pager'>",
157 cgit_log_link("[prev]", NULL, NULL, ctx.qry.head,
158 ctx.qry.sha1, ctx.qry.path,
159 ofs - cnt, ctx.qry.grep,
160 ctx.qry.search, ctx.qry.showmsg);
163 if ((commit = get_revision(&rev)) != NULL) {
164 cgit_log_link("[next]", NULL, NULL, ctx.qry.head,
165 ctx.qry.sha1, ctx.qry.path,
166 ofs + cnt, ctx.qry.grep,
167 ctx.qry.search, ctx.qry.showmsg);
170 } else if ((commit = get_revision(&rev)) != NULL) {
171 html("<tr class='nohover'><td colspan='3'>");
172 cgit_log_link("[...]", NULL, NULL, ctx.qry.head, NULL, NULL, 0,
173 NULL, NULL, ctx.qry.showmsg);
174 html("</td></tr>\n");