]> git.cameronkatri.com Git - cgit.git/blob - ui-log.c
tests/Makefile: not everyone has `.` in $PATH
[cgit.git] / ui-log.c
1 /* ui-log.c: functions for log output
2 *
3 * Copyright (C) 2006 Lars Hjemli
4 *
5 * Licensed under GNU General Public License v2
6 * (see COPYING for full license text)
7 */
8
9 #include "cgit.h"
10 #include "html.h"
11 #include "ui-shared.h"
12
13 int files, add_lines, rem_lines;
14
15 void count_lines(char *line, int size)
16 {
17 if (size <= 0)
18 return;
19
20 if (line[0] == '+')
21 add_lines++;
22
23 else if (line[0] == '-')
24 rem_lines++;
25 }
26
27 void inspect_files(struct diff_filepair *pair)
28 {
29 files++;
30 if (ctx.repo->enable_log_linecount)
31 cgit_diff_files(pair->one->sha1, pair->two->sha1, count_lines);
32 }
33
34 void print_commit(struct commit *commit)
35 {
36 struct commitinfo *info;
37 char *tmp;
38
39 info = cgit_parse_commit(commit);
40 html("<tr><td>");
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);
45 html_link_close();
46 html("</td><td>");
47 cgit_commit_link(info->subject, NULL, NULL, ctx.qry.head,
48 sha1_to_hex(commit->object.sha1));
49 html("</td><td>");
50 html_txt(info->author);
51 if (ctx.repo->enable_log_filecount) {
52 files = 0;
53 add_lines = 0;
54 rem_lines = 0;
55 cgit_diff_commit(commit, inspect_files);
56 html("</td><td>");
57 htmlf("%d", files);
58 if (ctx.repo->enable_log_linecount) {
59 html("</td><td>");
60 htmlf("-%d/+%d", rem_lines, add_lines);
61 }
62 }
63 html("</td></tr>\n");
64 cgit_free_commitinfo(info);
65 }
66
67
68 void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern,
69 char *path, int pager)
70 {
71 struct rev_info rev;
72 struct commit *commit;
73 const char *argv[] = {NULL, tip, NULL, NULL, NULL};
74 int argc = 2;
75 int i, columns = 3;
76
77 if (!tip)
78 argv[1] = ctx.qry.head;
79
80 if (grep && pattern && (!strcmp(grep, "grep") ||
81 !strcmp(grep, "author") ||
82 !strcmp(grep, "committer")))
83 argv[argc++] = fmt("--%s=%s", grep, pattern);
84
85 if (path) {
86 argv[argc++] = "--";
87 argv[argc++] = path;
88 }
89 init_revisions(&rev, NULL);
90 rev.abbrev = DEFAULT_ABBREV;
91 rev.commit_format = CMIT_FMT_DEFAULT;
92 rev.verbose_header = 1;
93 rev.show_root_diff = 0;
94 setup_revisions(argc, argv, &rev, NULL);
95 if (rev.grep_filter) {
96 rev.grep_filter->regflags |= REG_ICASE;
97 compile_grep_patterns(rev.grep_filter);
98 }
99 prepare_revision_walk(&rev);
100
101 if (pager)
102 html("<table class='list nowrap'>");
103
104 html("<tr class='nohover'><th class='left'>Age</th>"
105 "<th class='left'>Commit message</th>"
106 "<th class='left'>Author</th>");
107 if (ctx.repo->enable_log_filecount) {
108 html("<th class='left'>Files</th>");
109 columns++;
110 if (ctx.repo->enable_log_linecount) {
111 html("<th class='left'>Lines</th>");
112 columns++;
113 }
114 }
115 html("</tr>\n");
116
117 if (ofs<0)
118 ofs = 0;
119
120 for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; i++) {
121 free(commit->buffer);
122 commit->buffer = NULL;
123 free_commit_list(commit->parents);
124 commit->parents = NULL;
125 }
126
127 for (i = 0; i < cnt && (commit = get_revision(&rev)) != NULL; i++) {
128 print_commit(commit);
129 free(commit->buffer);
130 commit->buffer = NULL;
131 free_commit_list(commit->parents);
132 commit->parents = NULL;
133 }
134 if (pager) {
135 htmlf("</table><div class='pager'>",
136 columns);
137 if (ofs > 0) {
138 cgit_log_link("[prev]", NULL, NULL, ctx.qry.head,
139 ctx.qry.sha1, ctx.qry.path,
140 ofs - cnt, ctx.qry.grep,
141 ctx.qry.search);
142 html("&nbsp;");
143 }
144 if ((commit = get_revision(&rev)) != NULL) {
145 cgit_log_link("[next]", NULL, NULL, ctx.qry.head,
146 ctx.qry.sha1, ctx.qry.path,
147 ofs + cnt, ctx.qry.grep,
148 ctx.qry.search);
149 }
150 html("</div>");
151 } else if ((commit = get_revision(&rev)) != NULL) {
152 html("<tr class='nohover'><td colspan='3'>");
153 cgit_log_link("[...]", NULL, NULL, ctx.qry.head, NULL, NULL, 0,
154 NULL, NULL);
155 html("</td></tr>\n");
156 }
157 }