]> git.cameronkatri.com Git - cgit.git/blob - ui-log.c
Remove 'patch' link from tab, add to commit view
[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
38 info = cgit_parse_commit(commit);
39 html("<tr><td>");
40 cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE);
41 html("</td><td>");
42 cgit_commit_link(info->subject, NULL, NULL, ctx.qry.head,
43 sha1_to_hex(commit->object.sha1));
44 if (ctx.repo->enable_log_filecount) {
45 files = 0;
46 add_lines = 0;
47 rem_lines = 0;
48 cgit_diff_commit(commit, inspect_files);
49 html("</td><td class='right'>");
50 htmlf("%d", files);
51 if (ctx.repo->enable_log_linecount) {
52 html("</td><td class='right'>");
53 htmlf("-%d/+%d", rem_lines, add_lines);
54 }
55 }
56 html("</td><td>");
57 html_txt(info->author);
58 html("</td></tr>\n");
59 cgit_free_commitinfo(info);
60 }
61
62
63 void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern, char *path, int pager)
64 {
65 struct rev_info rev;
66 struct commit *commit;
67 const char *argv[] = {NULL, tip, NULL, NULL, NULL};
68 int argc = 2;
69 int i;
70
71 if (!tip)
72 argv[1] = ctx.qry.head;
73
74 if (grep && pattern && (!strcmp(grep, "grep") ||
75 !strcmp(grep, "author") ||
76 !strcmp(grep, "committer")))
77 argv[argc++] = fmt("--%s=%s", grep, pattern);
78
79 if (path) {
80 argv[argc++] = "--";
81 argv[argc++] = path;
82 }
83 init_revisions(&rev, NULL);
84 rev.abbrev = DEFAULT_ABBREV;
85 rev.commit_format = CMIT_FMT_DEFAULT;
86 rev.verbose_header = 1;
87 rev.show_root_diff = 0;
88 setup_revisions(argc, argv, &rev, NULL);
89 if (rev.grep_filter) {
90 rev.grep_filter->regflags |= REG_ICASE;
91 compile_grep_patterns(rev.grep_filter);
92 }
93 prepare_revision_walk(&rev);
94
95 html("<table summary='log' class='list nowrap'>");
96 html("<tr class='nohover'><th class='left'>Age</th>"
97 "<th class='left'>Message</th>");
98
99 if (ctx.repo->enable_log_filecount) {
100 html("<th class='right'>Files</th>");
101 if (ctx.repo->enable_log_linecount)
102 html("<th class='right'>Lines</th>");
103 }
104 html("<th class='left'>Author</th></tr>\n");
105
106 if (ofs<0)
107 ofs = 0;
108
109 for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; i++) {
110 free(commit->buffer);
111 commit->buffer = NULL;
112 free_commit_list(commit->parents);
113 commit->parents = NULL;
114 }
115
116 for (i = 0; i < cnt && (commit = get_revision(&rev)) != NULL; i++) {
117 print_commit(commit);
118 free(commit->buffer);
119 commit->buffer = NULL;
120 free_commit_list(commit->parents);
121 commit->parents = NULL;
122 }
123 html("</table>\n");
124
125 if (pager) {
126 html("<div class='pager'>");
127 if (ofs > 0) {
128 cgit_log_link("[prev]", NULL, NULL, ctx.qry.head,
129 ctx.qry.sha1, ctx.qry.path,
130 ofs - cnt, ctx.qry.grep,
131 ctx.qry.search);
132 html("&nbsp;");
133 }
134 if ((commit = get_revision(&rev)) != NULL) {
135 cgit_log_link("[next]", NULL, NULL, ctx.qry.head,
136 ctx.qry.sha1, ctx.qry.path,
137 ofs + cnt, ctx.qry.grep,
138 ctx.qry.search);
139 }
140 html("</div>");
141 }
142 }