summaryrefslogtreecommitdiffabout
path: root/ui-log.c
Unidiff
Diffstat (limited to 'ui-log.c') (more/less context) (ignore whitespace changes)
-rw-r--r--ui-log.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/ui-log.c b/ui-log.c
index ba2ab03..0b37785 100644
--- a/ui-log.c
+++ b/ui-log.c
@@ -1,230 +1,234 @@
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 unsigned long old_size = 0; 29 unsigned long old_size = 0;
30 unsigned long new_size = 0; 30 unsigned long new_size = 0;
31 int binary = 0; 31 int binary = 0;
32 32
33 files++; 33 files++;
34 if (ctx.repo->enable_log_linecount) 34 if (ctx.repo->enable_log_linecount)
35 cgit_diff_files(pair->one->sha1, pair->two->sha1, &old_size, 35 cgit_diff_files(pair->one->sha1, pair->two->sha1, &old_size,
36 &new_size, &binary, count_lines); 36 &new_size, &binary, count_lines);
37} 37}
38 38
39void show_commit_decorations(struct commit *commit) 39void show_commit_decorations(struct commit *commit)
40{ 40{
41 struct name_decoration *deco; 41 struct name_decoration *deco;
42 static char buf[1024]; 42 static char buf[1024];
43 43
44 buf[sizeof(buf) - 1] = 0; 44 buf[sizeof(buf) - 1] = 0;
45 deco = lookup_decoration(&name_decoration, &commit->object); 45 deco = lookup_decoration(&name_decoration, &commit->object);
46 while (deco) { 46 while (deco) {
47 if (!prefixcmp(deco->name, "refs/heads/")) { 47 if (!prefixcmp(deco->name, "refs/heads/")) {
48 strncpy(buf, deco->name + 11, sizeof(buf) - 1); 48 strncpy(buf, deco->name + 11, sizeof(buf) - 1);
49 cgit_log_link(buf, NULL, "branch-deco", buf, NULL, NULL, 49 cgit_log_link(buf, NULL, "branch-deco", buf, NULL, NULL,
50 0, NULL, NULL, ctx.qry.showmsg); 50 0, NULL, NULL, ctx.qry.showmsg);
51 } 51 }
52 else if (!prefixcmp(deco->name, "tag: refs/tags/")) { 52 else if (!prefixcmp(deco->name, "tag: refs/tags/")) {
53 strncpy(buf, deco->name + 15, sizeof(buf) - 1); 53 strncpy(buf, deco->name + 15, sizeof(buf) - 1);
54 cgit_tag_link(buf, NULL, "tag-deco", ctx.qry.head, buf); 54 cgit_tag_link(buf, NULL, "tag-deco", ctx.qry.head, buf);
55 } 55 }
56 else if (!prefixcmp(deco->name, "refs/tags/")) {
57 strncpy(buf, deco->name + 10, sizeof(buf) - 1);
58 cgit_tag_link(buf, NULL, "tag-deco", ctx.qry.head, buf);
59 }
56 else if (!prefixcmp(deco->name, "refs/remotes/")) { 60 else if (!prefixcmp(deco->name, "refs/remotes/")) {
57 strncpy(buf, deco->name + 13, sizeof(buf) - 1); 61 strncpy(buf, deco->name + 13, sizeof(buf) - 1);
58 cgit_log_link(buf, NULL, "remote-deco", NULL, 62 cgit_log_link(buf, NULL, "remote-deco", NULL,
59 sha1_to_hex(commit->object.sha1), NULL, 63 sha1_to_hex(commit->object.sha1), NULL,
60 0, NULL, NULL, ctx.qry.showmsg); 64 0, NULL, NULL, ctx.qry.showmsg);
61 } 65 }
62 else { 66 else {
63 strncpy(buf, deco->name, sizeof(buf) - 1); 67 strncpy(buf, deco->name, sizeof(buf) - 1);
64 cgit_commit_link(buf, NULL, "deco", ctx.qry.head, 68 cgit_commit_link(buf, NULL, "deco", ctx.qry.head,
65 sha1_to_hex(commit->object.sha1)); 69 sha1_to_hex(commit->object.sha1));
66 } 70 }
67 deco = deco->next; 71 deco = deco->next;
68 } 72 }
69} 73}
70 74
71void print_commit(struct commit *commit) 75void print_commit(struct commit *commit)
72{ 76{
73 struct commitinfo *info; 77 struct commitinfo *info;
74 char *tmp; 78 char *tmp;
75 int cols = 2; 79 int cols = 2;
76 80
77 info = cgit_parse_commit(commit); 81 info = cgit_parse_commit(commit);
78 htmlf("<tr%s><td>", 82 htmlf("<tr%s><td>",
79 ctx.qry.showmsg ? " class='logheader'" : ""); 83 ctx.qry.showmsg ? " class='logheader'" : "");
80 tmp = fmt("id=%s", sha1_to_hex(commit->object.sha1)); 84 tmp = fmt("id=%s", sha1_to_hex(commit->object.sha1));
81 tmp = cgit_pageurl(ctx.repo->url, "commit", tmp); 85 tmp = cgit_pageurl(ctx.repo->url, "commit", tmp);
82 html_link_open(tmp, NULL, NULL); 86 html_link_open(tmp, NULL, NULL);
83 cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE); 87 cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE);
84 html_link_close(); 88 html_link_close();
85 htmlf("</td><td%s>", 89 htmlf("</td><td%s>",
86 ctx.qry.showmsg ? " class='logsubject'" : ""); 90 ctx.qry.showmsg ? " class='logsubject'" : "");
87 cgit_commit_link(info->subject, NULL, NULL, ctx.qry.head, 91 cgit_commit_link(info->subject, NULL, NULL, ctx.qry.head,
88 sha1_to_hex(commit->object.sha1)); 92 sha1_to_hex(commit->object.sha1));
89 show_commit_decorations(commit); 93 show_commit_decorations(commit);
90 html("</td><td>"); 94 html("</td><td>");
91 html_txt(info->author); 95 html_txt(info->author);
92 if (ctx.repo->enable_log_filecount) { 96 if (ctx.repo->enable_log_filecount) {
93 files = 0; 97 files = 0;
94 add_lines = 0; 98 add_lines = 0;
95 rem_lines = 0; 99 rem_lines = 0;
96 cgit_diff_commit(commit, inspect_files); 100 cgit_diff_commit(commit, inspect_files);
97 html("</td><td>"); 101 html("</td><td>");
98 htmlf("%d", files); 102 htmlf("%d", files);
99 if (ctx.repo->enable_log_linecount) { 103 if (ctx.repo->enable_log_linecount) {
100 html("</td><td>"); 104 html("</td><td>");
101 htmlf("-%d/+%d", rem_lines, add_lines); 105 htmlf("-%d/+%d", rem_lines, add_lines);
102 } 106 }
103 } 107 }
104 html("</td></tr>\n"); 108 html("</td></tr>\n");
105 if (ctx.qry.showmsg) { 109 if (ctx.qry.showmsg) {
106 if (ctx.repo->enable_log_filecount) { 110 if (ctx.repo->enable_log_filecount) {
107 cols++; 111 cols++;
108 if (ctx.repo->enable_log_linecount) 112 if (ctx.repo->enable_log_linecount)
109 cols++; 113 cols++;
110 } 114 }
111 htmlf("<tr class='nohover'><td/><td colspan='%d' class='logmsg'>", 115 htmlf("<tr class='nohover'><td/><td colspan='%d' class='logmsg'>",
112 cols); 116 cols);
113 html_txt(info->msg); 117 html_txt(info->msg);
114 html("</td></tr>\n"); 118 html("</td></tr>\n");
115 } 119 }
116 cgit_free_commitinfo(info); 120 cgit_free_commitinfo(info);
117} 121}
118 122
119static const char *disambiguate_ref(const char *ref) 123static const char *disambiguate_ref(const char *ref)
120{ 124{
121 unsigned char sha1[20]; 125 unsigned char sha1[20];
122 const char *longref; 126 const char *longref;
123 127
124 longref = fmt("refs/heads/%s", ref); 128 longref = fmt("refs/heads/%s", ref);
125 if (get_sha1(longref, sha1) == 0) 129 if (get_sha1(longref, sha1) == 0)
126 return longref; 130 return longref;
127 131
128 return ref; 132 return ref;
129} 133}
130 134
131void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern, 135void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern,
132 char *path, int pager) 136 char *path, int pager)
133{ 137{
134 struct rev_info rev; 138 struct rev_info rev;
135 struct commit *commit; 139 struct commit *commit;
136 const char *argv[] = {NULL, NULL, NULL, NULL, NULL}; 140 const char *argv[] = {NULL, NULL, NULL, NULL, NULL};
137 int argc = 2; 141 int argc = 2;
138 int i, columns = 3; 142 int i, columns = 3;
139 143
140 if (!tip) 144 if (!tip)
141 tip = ctx.qry.head; 145 tip = ctx.qry.head;
142 146
143 argv[1] = disambiguate_ref(tip); 147 argv[1] = disambiguate_ref(tip);
144 148
145 if (grep && pattern && (!strcmp(grep, "grep") || 149 if (grep && pattern && (!strcmp(grep, "grep") ||
146 !strcmp(grep, "author") || 150 !strcmp(grep, "author") ||
147 !strcmp(grep, "committer"))) 151 !strcmp(grep, "committer")))
148 argv[argc++] = fmt("--%s=%s", grep, pattern); 152 argv[argc++] = fmt("--%s=%s", grep, pattern);
149 153
150 if (path) { 154 if (path) {
151 argv[argc++] = "--"; 155 argv[argc++] = "--";
152 argv[argc++] = path; 156 argv[argc++] = path;
153 } 157 }
154 init_revisions(&rev, NULL); 158 init_revisions(&rev, NULL);
155 rev.abbrev = DEFAULT_ABBREV; 159 rev.abbrev = DEFAULT_ABBREV;
156 rev.commit_format = CMIT_FMT_DEFAULT; 160 rev.commit_format = CMIT_FMT_DEFAULT;
157 rev.verbose_header = 1; 161 rev.verbose_header = 1;
158 rev.show_root_diff = 0; 162 rev.show_root_diff = 0;
159 setup_revisions(argc, argv, &rev, NULL); 163 setup_revisions(argc, argv, &rev, NULL);
160 load_ref_decorations(); 164 load_ref_decorations();
161 rev.show_decorations = 1; 165 rev.show_decorations = 1;
162 rev.grep_filter.regflags |= REG_ICASE; 166 rev.grep_filter.regflags |= REG_ICASE;
163 compile_grep_patterns(&rev.grep_filter); 167 compile_grep_patterns(&rev.grep_filter);
164 prepare_revision_walk(&rev); 168 prepare_revision_walk(&rev);
165 169
166 if (pager) 170 if (pager)
167 html("<table class='list nowrap'>"); 171 html("<table class='list nowrap'>");
168 172
169 html("<tr class='nohover'><th class='left'>Age</th>" 173 html("<tr class='nohover'><th class='left'>Age</th>"
170 "<th class='left'>Commit message"); 174 "<th class='left'>Commit message");
171 if (pager) { 175 if (pager) {
172 html(" ("); 176 html(" (");
173 cgit_log_link(ctx.qry.showmsg ? "Collapse" : "Expand", NULL, 177 cgit_log_link(ctx.qry.showmsg ? "Collapse" : "Expand", NULL,
174 NULL, ctx.qry.head, ctx.qry.sha1, 178 NULL, ctx.qry.head, ctx.qry.sha1,
175 ctx.qry.path, ctx.qry.ofs, ctx.qry.grep, 179 ctx.qry.path, ctx.qry.ofs, ctx.qry.grep,
176 ctx.qry.search, ctx.qry.showmsg ? 0 : 1); 180 ctx.qry.search, ctx.qry.showmsg ? 0 : 1);
177 html(")"); 181 html(")");
178 } 182 }
179 html("</th><th class='left'>Author</th>"); 183 html("</th><th class='left'>Author</th>");
180 if (ctx.repo->enable_log_filecount) { 184 if (ctx.repo->enable_log_filecount) {
181 html("<th class='left'>Files</th>"); 185 html("<th class='left'>Files</th>");
182 columns++; 186 columns++;
183 if (ctx.repo->enable_log_linecount) { 187 if (ctx.repo->enable_log_linecount) {
184 html("<th class='left'>Lines</th>"); 188 html("<th class='left'>Lines</th>");
185 columns++; 189 columns++;
186 } 190 }
187 } 191 }
188 html("</tr>\n"); 192 html("</tr>\n");
189 193
190 if (ofs<0) 194 if (ofs<0)
191 ofs = 0; 195 ofs = 0;
192 196
193 for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; i++) { 197 for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; i++) {
194 free(commit->buffer); 198 free(commit->buffer);
195 commit->buffer = NULL; 199 commit->buffer = NULL;
196 free_commit_list(commit->parents); 200 free_commit_list(commit->parents);
197 commit->parents = NULL; 201 commit->parents = NULL;
198 } 202 }
199 203
200 for (i = 0; i < cnt && (commit = get_revision(&rev)) != NULL; i++) { 204 for (i = 0; i < cnt && (commit = get_revision(&rev)) != NULL; i++) {
201 print_commit(commit); 205 print_commit(commit);
202 free(commit->buffer); 206 free(commit->buffer);
203 commit->buffer = NULL; 207 commit->buffer = NULL;
204 free_commit_list(commit->parents); 208 free_commit_list(commit->parents);
205 commit->parents = NULL; 209 commit->parents = NULL;
206 } 210 }
207 if (pager) { 211 if (pager) {
208 htmlf("</table><div class='pager'>", 212 htmlf("</table><div class='pager'>",
209 columns); 213 columns);
210 if (ofs > 0) { 214 if (ofs > 0) {
211 cgit_log_link("[prev]", NULL, NULL, ctx.qry.head, 215 cgit_log_link("[prev]", NULL, NULL, ctx.qry.head,
212 ctx.qry.sha1, ctx.qry.path, 216 ctx.qry.sha1, ctx.qry.path,
213 ofs - cnt, ctx.qry.grep, 217 ofs - cnt, ctx.qry.grep,
214 ctx.qry.search, ctx.qry.showmsg); 218 ctx.qry.search, ctx.qry.showmsg);
215 html("&nbsp;"); 219 html("&nbsp;");
216 } 220 }
217 if ((commit = get_revision(&rev)) != NULL) { 221 if ((commit = get_revision(&rev)) != NULL) {
218 cgit_log_link("[next]", NULL, NULL, ctx.qry.head, 222 cgit_log_link("[next]", NULL, NULL, ctx.qry.head,
219 ctx.qry.sha1, ctx.qry.path, 223 ctx.qry.sha1, ctx.qry.path,
220 ofs + cnt, ctx.qry.grep, 224 ofs + cnt, ctx.qry.grep,
221 ctx.qry.search, ctx.qry.showmsg); 225 ctx.qry.search, ctx.qry.showmsg);
222 } 226 }
223 html("</div>"); 227 html("</div>");
224 } else if ((commit = get_revision(&rev)) != NULL) { 228 } else if ((commit = get_revision(&rev)) != NULL) {
225 html("<tr class='nohover'><td colspan='3'>"); 229 html("<tr class='nohover'><td colspan='3'>");
226 cgit_log_link("[...]", NULL, NULL, ctx.qry.head, NULL, NULL, 0, 230 cgit_log_link("[...]", NULL, NULL, ctx.qry.head, NULL, NULL, 0,
227 NULL, NULL, ctx.qry.showmsg); 231 NULL, NULL, ctx.qry.showmsg);
228 html("</td></tr>\n"); 232 html("</td></tr>\n");
229 } 233 }
230} 234}