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);
81 static const char *disambiguate_ref(const char *ref)
83 unsigned char sha1[20];
86 longref = fmt("refs/heads/%s", ref);
87 if (get_sha1(longref, sha1) == 0)
93 void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern,
94 char *path, int pager)
97 struct commit *commit;
98 const char *argv[] = {NULL, NULL, NULL, NULL, NULL};
105 argv[1] = disambiguate_ref(tip);
107 if (grep && pattern && (!strcmp(grep, "grep") ||
108 !strcmp(grep, "author") ||
109 !strcmp(grep, "committer")))
110 argv[argc++] = fmt("--%s=%s", grep, pattern);
116 init_revisions(&rev, NULL);
117 rev.abbrev = DEFAULT_ABBREV;
118 rev.commit_format = CMIT_FMT_DEFAULT;
119 rev.verbose_header = 1;
120 rev.show_root_diff = 0;
121 setup_revisions(argc, argv, &rev, NULL);
122 rev.grep_filter.regflags |= REG_ICASE;
123 compile_grep_patterns(&rev.grep_filter);
124 prepare_revision_walk(&rev);
127 html("<table class='list nowrap'>");
129 html("<tr class='nohover'><th class='left'>Age</th>"
130 "<th class='left'>Commit message");
133 cgit_log_link("toggle", NULL, NULL, ctx.qry.head, ctx.qry.sha1,
134 ctx.qry.path, ctx.qry.ofs, ctx.qry.grep,
135 ctx.qry.search, ctx.qry.showmsg ? 0 : 1);
138 html("</th><th class='left'>Author</th>");
139 if (ctx.repo->enable_log_filecount) {
140 html("<th class='left'>Files</th>");
142 if (ctx.repo->enable_log_linecount) {
143 html("<th class='left'>Lines</th>");
152 for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; i++) {
153 free(commit->buffer);
154 commit->buffer = NULL;
155 free_commit_list(commit->parents);
156 commit->parents = NULL;
159 for (i = 0; i < cnt && (commit = get_revision(&rev)) != NULL; i++) {
160 print_commit(commit);
161 free(commit->buffer);
162 commit->buffer = NULL;
163 free_commit_list(commit->parents);
164 commit->parents = NULL;
167 htmlf("</table><div class='pager'>",
170 cgit_log_link("[prev]", NULL, NULL, ctx.qry.head,
171 ctx.qry.sha1, ctx.qry.path,
172 ofs - cnt, ctx.qry.grep,
173 ctx.qry.search, ctx.qry.showmsg);
176 if ((commit = get_revision(&rev)) != NULL) {
177 cgit_log_link("[next]", NULL, NULL, ctx.qry.head,
178 ctx.qry.sha1, ctx.qry.path,
179 ofs + cnt, ctx.qry.grep,
180 ctx.qry.search, ctx.qry.showmsg);
183 } else if ((commit = get_revision(&rev)) != NULL) {
184 html("<tr class='nohover'><td colspan='3'>");
185 cgit_log_link("[...]", NULL, NULL, ctx.qry.head, NULL, NULL, 0,
186 NULL, NULL, ctx.qry.showmsg);
187 html("</td></tr>\n");