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