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;
39 info = cgit_parse_commit(commit);
41 tmp = fmt("id=%s", sha1_to_hex(commit->object.sha1));
42 tmp = cgit_pageurl(ctx.repo->url, "commit", tmp);
43 html_link_open(tmp, NULL, NULL);
44 cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE);
49 cgit_commit_link(info->subject, NULL, NULL, ctx.qry.head,
50 sha1_to_hex(commit->object.sha1));
54 html_txt(info->author);
55 if (ctx.repo->enable_log_filecount) {
59 cgit_diff_commit(commit, inspect_files);
62 if (ctx.repo->enable_log_linecount) {
64 htmlf("-%d/+%d", rem_lines, add_lines);
68 if (ctx.qry.showmsg) {
69 html("<tr class='nohover'><td></td><td><div class='commit-msg'>");
71 html("</div><br/></td><td></td>");
72 if (ctx.repo->enable_log_filecount) {
74 if (ctx.repo->enable_log_linecount)
79 cgit_free_commitinfo(info);
83 void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern,
84 char *path, int pager)
87 struct commit *commit;
88 const char *argv[] = {NULL, tip, NULL, NULL, NULL};
93 argv[1] = ctx.qry.head;
95 if (grep && pattern && (!strcmp(grep, "grep") ||
96 !strcmp(grep, "author") ||
97 !strcmp(grep, "committer")))
98 argv[argc++] = fmt("--%s=%s", grep, pattern);
104 init_revisions(&rev, NULL);
105 rev.abbrev = DEFAULT_ABBREV;
106 rev.commit_format = CMIT_FMT_DEFAULT;
107 rev.verbose_header = 1;
108 rev.show_root_diff = 0;
109 setup_revisions(argc, argv, &rev, NULL);
110 rev.grep_filter.regflags |= REG_ICASE;
111 compile_grep_patterns(&rev.grep_filter);
112 prepare_revision_walk(&rev);
115 html("<table class='list nowrap'>");
117 html("<tr class='nohover'><th class='left'>Age</th>"
118 "<th class='left'>Commit message");
121 cgit_log_link("toggle", NULL, NULL, ctx.qry.head, ctx.qry.sha1,
122 ctx.qry.path, ctx.qry.ofs, ctx.qry.grep,
123 ctx.qry.search, ctx.qry.showmsg ? 0 : 1);
126 html("</th><th class='left'>Author</th>");
127 if (ctx.repo->enable_log_filecount) {
128 html("<th class='left'>Files</th>");
130 if (ctx.repo->enable_log_linecount) {
131 html("<th class='left'>Lines</th>");
140 for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; i++) {
141 free(commit->buffer);
142 commit->buffer = NULL;
143 free_commit_list(commit->parents);
144 commit->parents = NULL;
147 for (i = 0; i < cnt && (commit = get_revision(&rev)) != NULL; i++) {
148 print_commit(commit);
149 free(commit->buffer);
150 commit->buffer = NULL;
151 free_commit_list(commit->parents);
152 commit->parents = NULL;
155 htmlf("</table><div class='pager'>",
158 cgit_log_link("[prev]", NULL, NULL, ctx.qry.head,
159 ctx.qry.sha1, ctx.qry.path,
160 ofs - cnt, ctx.qry.grep,
161 ctx.qry.search, ctx.qry.showmsg);
164 if ((commit = get_revision(&rev)) != NULL) {
165 cgit_log_link("[next]", NULL, NULL, ctx.qry.head,
166 ctx.qry.sha1, ctx.qry.path,
167 ofs + cnt, ctx.qry.grep,
168 ctx.qry.search, ctx.qry.showmsg);
171 } else if ((commit = get_revision(&rev)) != NULL) {
172 html("<tr class='nohover'><td colspan='3'>");
173 cgit_log_link("[...]", NULL, NULL, ctx.qry.head, NULL, NULL, 0,
174 NULL, NULL, ctx.qry.showmsg);
175 html("</td></tr>\n");