summaryrefslogtreecommitdiffabout
path: root/ui-log.c
Unidiff
Diffstat (limited to 'ui-log.c') (more/less context) (ignore whitespace changes)
-rw-r--r--ui-log.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/ui-log.c b/ui-log.c
index 631e46d..adc9a66 100644
--- a/ui-log.c
+++ b/ui-log.c
@@ -1,177 +1,178 @@
1/* ui-log.c: functions for log output 1/* ui-log.c: functions for log output
2 * 2 *
3 * Copyright (C) 2006 Lars Hjemli 3 * Copyright (C) 2006 Lars Hjemli
4 * 4 *
5 * Licensed under GNU General Public License v2 5 * Licensed under GNU General Public License v2
6 * (see COPYING for full license text) 6 * (see COPYING for full license text)
7 */ 7 */
8 8
9#include "cgit.h" 9#include "cgit.h"
10#include "html.h" 10#include "html.h"
11#include "ui-shared.h" 11#include "ui-shared.h"
12 12
13int files, add_lines, rem_lines; 13int files, add_lines, rem_lines;
14 14
15void count_lines(char *line, int size) 15void count_lines(char *line, int size)
16{ 16{
17 if (size <= 0) 17 if (size <= 0)
18 return; 18 return;
19 19
20 if (line[0] == '+') 20 if (line[0] == '+')
21 add_lines++; 21 add_lines++;
22 22
23 else if (line[0] == '-') 23 else if (line[0] == '-')
24 rem_lines++; 24 rem_lines++;
25} 25}
26 26
27void inspect_files(struct diff_filepair *pair) 27void inspect_files(struct diff_filepair *pair)
28{ 28{
29 files++; 29 files++;
30 if (ctx.repo->enable_log_linecount) 30 if (ctx.repo->enable_log_linecount)
31 cgit_diff_files(pair->one->sha1, pair->two->sha1, count_lines); 31 cgit_diff_files(pair->one->sha1, pair->two->sha1, count_lines);
32} 32}
33 33
34void print_commit(struct commit *commit) 34void print_commit(struct commit *commit)
35{ 35{
36 struct commitinfo *info; 36 struct commitinfo *info;
37 char *tmp; 37 char *tmp;
38 int cols = 2;
38 39
39 info = cgit_parse_commit(commit); 40 info = cgit_parse_commit(commit);
40 html("<tr><td>"); 41 html("<tr><td>");
41 tmp = fmt("id=%s", sha1_to_hex(commit->object.sha1)); 42 tmp = fmt("id=%s", sha1_to_hex(commit->object.sha1));
42 tmp = cgit_pageurl(ctx.repo->url, "commit", tmp); 43 tmp = cgit_pageurl(ctx.repo->url, "commit", tmp);
43 html_link_open(tmp, NULL, NULL); 44 html_link_open(tmp, NULL, NULL);
44 cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE); 45 cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE);
45 html_link_close(); 46 html_link_close();
46 html("</td><td>"); 47 html("</td><td>");
47 if (ctx.qry.showmsg) 48 if (ctx.qry.showmsg)
48 html("<u>"); 49 html("<u>");
49 cgit_commit_link(info->subject, NULL, NULL, ctx.qry.head, 50 cgit_commit_link(info->subject, NULL, NULL, ctx.qry.head,
50 sha1_to_hex(commit->object.sha1)); 51 sha1_to_hex(commit->object.sha1));
51 if (ctx.qry.showmsg) 52 if (ctx.qry.showmsg)
52 html("</u>"); 53 html("</u>");
53 html("</td><td>"); 54 html("</td><td>");
54 html_txt(info->author); 55 html_txt(info->author);
55 if (ctx.repo->enable_log_filecount) { 56 if (ctx.repo->enable_log_filecount) {
56 files = 0; 57 files = 0;
57 add_lines = 0; 58 add_lines = 0;
58 rem_lines = 0; 59 rem_lines = 0;
59 cgit_diff_commit(commit, inspect_files); 60 cgit_diff_commit(commit, inspect_files);
60 html("</td><td>"); 61 html("</td><td>");
61 htmlf("%d", files); 62 htmlf("%d", files);
62 if (ctx.repo->enable_log_linecount) { 63 if (ctx.repo->enable_log_linecount) {
63 html("</td><td>"); 64 html("</td><td>");
64 htmlf("-%d/+%d", rem_lines, add_lines); 65 htmlf("-%d/+%d", rem_lines, add_lines);
65 } 66 }
66 } 67 }
67 html("</td></tr>\n"); 68 html("</td></tr>\n");
68 if (ctx.qry.showmsg) { 69 if (ctx.qry.showmsg) {
69 html("<tr class='nohover'><td></td><td><div class='commit-msg'>");
70 html_txt(info->msg);
71 html("</div><br/></td><td></td>");
72 if (ctx.repo->enable_log_filecount) { 70 if (ctx.repo->enable_log_filecount) {
73 html("<td></td>"); 71 cols++;
74 if (ctx.repo->enable_log_linecount) 72 if (ctx.repo->enable_log_linecount)
75 html("<td></td>"); 73 cols++;
76 } 74 }
77 html("</tr>\n"); 75 htmlf("<tr class='nohover'><td></td><td colspan='%d'><div class='commit-msg'>",
76 cols);
77 html_txt(info->msg);
78 html("</div><br/></td></tr>\n");
78 } 79 }
79 cgit_free_commitinfo(info); 80 cgit_free_commitinfo(info);
80} 81}
81 82
82 83
83void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern, 84void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern,
84 char *path, int pager) 85 char *path, int pager)
85{ 86{
86 struct rev_info rev; 87 struct rev_info rev;
87 struct commit *commit; 88 struct commit *commit;
88 const char *argv[] = {NULL, tip, NULL, NULL, NULL}; 89 const char *argv[] = {NULL, tip, NULL, NULL, NULL};
89 int argc = 2; 90 int argc = 2;
90 int i, columns = 3; 91 int i, columns = 3;
91 92
92 if (!tip) 93 if (!tip)
93 argv[1] = ctx.qry.head; 94 argv[1] = ctx.qry.head;
94 95
95 if (grep && pattern && (!strcmp(grep, "grep") || 96 if (grep && pattern && (!strcmp(grep, "grep") ||
96 !strcmp(grep, "author") || 97 !strcmp(grep, "author") ||
97 !strcmp(grep, "committer"))) 98 !strcmp(grep, "committer")))
98 argv[argc++] = fmt("--%s=%s", grep, pattern); 99 argv[argc++] = fmt("--%s=%s", grep, pattern);
99 100
100 if (path) { 101 if (path) {
101 argv[argc++] = "--"; 102 argv[argc++] = "--";
102 argv[argc++] = path; 103 argv[argc++] = path;
103 } 104 }
104 init_revisions(&rev, NULL); 105 init_revisions(&rev, NULL);
105 rev.abbrev = DEFAULT_ABBREV; 106 rev.abbrev = DEFAULT_ABBREV;
106 rev.commit_format = CMIT_FMT_DEFAULT; 107 rev.commit_format = CMIT_FMT_DEFAULT;
107 rev.verbose_header = 1; 108 rev.verbose_header = 1;
108 rev.show_root_diff = 0; 109 rev.show_root_diff = 0;
109 setup_revisions(argc, argv, &rev, NULL); 110 setup_revisions(argc, argv, &rev, NULL);
110 rev.grep_filter.regflags |= REG_ICASE; 111 rev.grep_filter.regflags |= REG_ICASE;
111 compile_grep_patterns(&rev.grep_filter); 112 compile_grep_patterns(&rev.grep_filter);
112 prepare_revision_walk(&rev); 113 prepare_revision_walk(&rev);
113 114
114 if (pager) 115 if (pager)
115 html("<table class='list nowrap'>"); 116 html("<table class='list nowrap'>");
116 117
117 html("<tr class='nohover'><th class='left'>Age</th>" 118 html("<tr class='nohover'><th class='left'>Age</th>"
118 "<th class='left'>Commit message"); 119 "<th class='left'>Commit message");
119 if (pager) { 120 if (pager) {
120 html(" ("); 121 html(" (");
121 cgit_log_link("toggle", NULL, NULL, ctx.qry.head, ctx.qry.sha1, 122 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.path, ctx.qry.ofs, ctx.qry.grep,
123 ctx.qry.search, ctx.qry.showmsg ? 0 : 1); 124 ctx.qry.search, ctx.qry.showmsg ? 0 : 1);
124 html(")"); 125 html(")");
125 } 126 }
126 html("</th><th class='left'>Author</th>"); 127 html("</th><th class='left'>Author</th>");
127 if (ctx.repo->enable_log_filecount) { 128 if (ctx.repo->enable_log_filecount) {
128 html("<th class='left'>Files</th>"); 129 html("<th class='left'>Files</th>");
129 columns++; 130 columns++;
130 if (ctx.repo->enable_log_linecount) { 131 if (ctx.repo->enable_log_linecount) {
131 html("<th class='left'>Lines</th>"); 132 html("<th class='left'>Lines</th>");
132 columns++; 133 columns++;
133 } 134 }
134 } 135 }
135 html("</tr>\n"); 136 html("</tr>\n");
136 137
137 if (ofs<0) 138 if (ofs<0)
138 ofs = 0; 139 ofs = 0;
139 140
140 for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; i++) { 141 for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; i++) {
141 free(commit->buffer); 142 free(commit->buffer);
142 commit->buffer = NULL; 143 commit->buffer = NULL;
143 free_commit_list(commit->parents); 144 free_commit_list(commit->parents);
144 commit->parents = NULL; 145 commit->parents = NULL;
145 } 146 }
146 147
147 for (i = 0; i < cnt && (commit = get_revision(&rev)) != NULL; i++) { 148 for (i = 0; i < cnt && (commit = get_revision(&rev)) != NULL; i++) {
148 print_commit(commit); 149 print_commit(commit);
149 free(commit->buffer); 150 free(commit->buffer);
150 commit->buffer = NULL; 151 commit->buffer = NULL;
151 free_commit_list(commit->parents); 152 free_commit_list(commit->parents);
152 commit->parents = NULL; 153 commit->parents = NULL;
153 } 154 }
154 if (pager) { 155 if (pager) {
155 htmlf("</table><div class='pager'>", 156 htmlf("</table><div class='pager'>",
156 columns); 157 columns);
157 if (ofs > 0) { 158 if (ofs > 0) {
158 cgit_log_link("[prev]", NULL, NULL, ctx.qry.head, 159 cgit_log_link("[prev]", NULL, NULL, ctx.qry.head,
159 ctx.qry.sha1, ctx.qry.path, 160 ctx.qry.sha1, ctx.qry.path,
160 ofs - cnt, ctx.qry.grep, 161 ofs - cnt, ctx.qry.grep,
161 ctx.qry.search, ctx.qry.showmsg); 162 ctx.qry.search, ctx.qry.showmsg);
162 html("&nbsp;"); 163 html("&nbsp;");
163 } 164 }
164 if ((commit = get_revision(&rev)) != NULL) { 165 if ((commit = get_revision(&rev)) != NULL) {
165 cgit_log_link("[next]", NULL, NULL, ctx.qry.head, 166 cgit_log_link("[next]", NULL, NULL, ctx.qry.head,
166 ctx.qry.sha1, ctx.qry.path, 167 ctx.qry.sha1, ctx.qry.path,
167 ofs + cnt, ctx.qry.grep, 168 ofs + cnt, ctx.qry.grep,
168 ctx.qry.search, ctx.qry.showmsg); 169 ctx.qry.search, ctx.qry.showmsg);
169 } 170 }
170 html("</div>"); 171 html("</div>");
171 } else if ((commit = get_revision(&rev)) != NULL) { 172 } else if ((commit = get_revision(&rev)) != NULL) {
172 html("<tr class='nohover'><td colspan='3'>"); 173 html("<tr class='nohover'><td colspan='3'>");
173 cgit_log_link("[...]", NULL, NULL, ctx.qry.head, NULL, NULL, 0, 174 cgit_log_link("[...]", NULL, NULL, ctx.qry.head, NULL, NULL, 0,
174 NULL, NULL, ctx.qry.showmsg); 175 NULL, NULL, ctx.qry.showmsg);
175 html("</td></tr>\n"); 176 html("</td></tr>\n");
176 } 177 }
177} 178}