|
diff --git a/ui-diff.c b/ui-diff.c index a53425d..a7bc667 100644 --- a/ ui-diff.c+++ b/ ui-diff.c |
|
@@ -79,194 +79,197 @@ static void print_fileinfo(struct fileinfo *info) |
79 | die("bug: unhandled diff status %c", info->status); |
79 | die("bug: unhandled diff status %c", info->status); |
80 | } |
80 | } |
81 | |
81 | |
82 | html("<tr>"); |
82 | html("<tr>"); |
83 | htmlf("<td class='mode'>"); |
83 | htmlf("<td class='mode'>"); |
84 | if (is_null_sha1(info->new_sha1)) { |
84 | if (is_null_sha1(info->new_sha1)) { |
85 | cgit_print_filemode(info->old_mode); |
85 | cgit_print_filemode(info->old_mode); |
86 | } else { |
86 | } else { |
87 | cgit_print_filemode(info->new_mode); |
87 | cgit_print_filemode(info->new_mode); |
88 | } |
88 | } |
89 | |
89 | |
90 | if (info->old_mode != info->new_mode && |
90 | if (info->old_mode != info->new_mode && |
91 | !is_null_sha1(info->old_sha1) && |
91 | !is_null_sha1(info->old_sha1) && |
92 | !is_null_sha1(info->new_sha1)) { |
92 | !is_null_sha1(info->new_sha1)) { |
93 | html("<span class='modechange'>["); |
93 | html("<span class='modechange'>["); |
94 | cgit_print_filemode(info->old_mode); |
94 | cgit_print_filemode(info->old_mode); |
95 | html("]</span>"); |
95 | html("]</span>"); |
96 | } |
96 | } |
97 | htmlf("</td><td class='%s'>", class); |
97 | htmlf("</td><td class='%s'>", class); |
98 | cgit_diff_link(info->new_path, NULL, NULL, ctx.qry.head, ctx.qry.sha1, |
98 | cgit_diff_link(info->new_path, NULL, NULL, ctx.qry.head, ctx.qry.sha1, |
99 | ctx.qry.sha2, info->new_path, 0); |
99 | ctx.qry.sha2, info->new_path, 0); |
100 | if (info->status == DIFF_STATUS_COPIED || info->status == DIFF_STATUS_RENAMED) |
100 | if (info->status == DIFF_STATUS_COPIED || info->status == DIFF_STATUS_RENAMED) |
101 | htmlf(" (%s from %s)", |
101 | htmlf(" (%s from %s)", |
102 | info->status == DIFF_STATUS_COPIED ? "copied" : "renamed", |
102 | info->status == DIFF_STATUS_COPIED ? "copied" : "renamed", |
103 | info->old_path); |
103 | info->old_path); |
104 | html("</td><td class='right'>"); |
104 | html("</td><td class='right'>"); |
105 | if (info->binary) { |
105 | if (info->binary) { |
106 | htmlf("bin</td><td class='graph'>%ld -> %ld bytes", |
106 | htmlf("bin</td><td class='graph'>%ld -> %ld bytes", |
107 | info->old_size, info->new_size); |
107 | info->old_size, info->new_size); |
108 | return; |
108 | return; |
109 | } |
109 | } |
110 | htmlf("%d", info->added + info->removed); |
110 | htmlf("%d", info->added + info->removed); |
111 | html("</td><td class='graph'>"); |
111 | html("</td><td class='graph'>"); |
112 | htmlf("<table summary='file diffstat' width='%d%%'><tr>", (max_changes > 100 ? 100 : max_changes)); |
112 | htmlf("<table summary='file diffstat' width='%d%%'><tr>", (max_changes > 100 ? 100 : max_changes)); |
113 | htmlf("<td class='add' style='width: %.1f%%;'/>", |
113 | htmlf("<td class='add' style='width: %.1f%%;'/>", |
114 | info->added * 100.0 / max_changes); |
114 | info->added * 100.0 / max_changes); |
115 | htmlf("<td class='rem' style='width: %.1f%%;'/>", |
115 | htmlf("<td class='rem' style='width: %.1f%%;'/>", |
116 | info->removed * 100.0 / max_changes); |
116 | info->removed * 100.0 / max_changes); |
117 | htmlf("<td class='none' style='width: %.1f%%;'/>", |
117 | htmlf("<td class='none' style='width: %.1f%%;'/>", |
118 | (max_changes - info->removed - info->added) * 100.0 / max_changes); |
118 | (max_changes - info->removed - info->added) * 100.0 / max_changes); |
119 | html("</tr></table></td></tr>\n"); |
119 | html("</tr></table></td></tr>\n"); |
120 | } |
120 | } |
121 | |
121 | |
122 | static void count_diff_lines(char *line, int len) |
122 | static void count_diff_lines(char *line, int len) |
123 | { |
123 | { |
124 | if (line && (len > 0)) { |
124 | if (line && (len > 0)) { |
125 | if (line[0] == '+') |
125 | if (line[0] == '+') |
126 | lines_added++; |
126 | lines_added++; |
127 | else if (line[0] == '-') |
127 | else if (line[0] == '-') |
128 | lines_removed++; |
128 | lines_removed++; |
129 | } |
129 | } |
130 | } |
130 | } |
131 | |
131 | |
132 | static void inspect_filepair(struct diff_filepair *pair) |
132 | static void inspect_filepair(struct diff_filepair *pair) |
133 | { |
133 | { |
134 | int binary = 0; |
134 | int binary = 0; |
135 | unsigned long old_size = 0; |
135 | unsigned long old_size = 0; |
136 | unsigned long new_size = 0; |
136 | unsigned long new_size = 0; |
137 | files++; |
137 | files++; |
138 | lines_added = 0; |
138 | lines_added = 0; |
139 | lines_removed = 0; |
139 | lines_removed = 0; |
140 | cgit_diff_files(pair->one->sha1, pair->two->sha1, &old_size, &new_size, |
140 | cgit_diff_files(pair->one->sha1, pair->two->sha1, &old_size, &new_size, |
141 | &binary, 0, ctx.qry.ignorews, count_diff_lines); |
141 | &binary, 0, ctx.qry.ignorews, count_diff_lines); |
142 | if (files >= slots) { |
142 | if (files >= slots) { |
143 | if (slots == 0) |
143 | if (slots == 0) |
144 | slots = 4; |
144 | slots = 4; |
145 | else |
145 | else |
146 | slots = slots * 2; |
146 | slots = slots * 2; |
147 | items = xrealloc(items, slots * sizeof(struct fileinfo)); |
147 | items = xrealloc(items, slots * sizeof(struct fileinfo)); |
148 | } |
148 | } |
149 | items[files-1].status = pair->status; |
149 | items[files-1].status = pair->status; |
150 | hashcpy(items[files-1].old_sha1, pair->one->sha1); |
150 | hashcpy(items[files-1].old_sha1, pair->one->sha1); |
151 | hashcpy(items[files-1].new_sha1, pair->two->sha1); |
151 | hashcpy(items[files-1].new_sha1, pair->two->sha1); |
152 | items[files-1].old_mode = pair->one->mode; |
152 | items[files-1].old_mode = pair->one->mode; |
153 | items[files-1].new_mode = pair->two->mode; |
153 | items[files-1].new_mode = pair->two->mode; |
154 | items[files-1].old_path = xstrdup(pair->one->path); |
154 | items[files-1].old_path = xstrdup(pair->one->path); |
155 | items[files-1].new_path = xstrdup(pair->two->path); |
155 | items[files-1].new_path = xstrdup(pair->two->path); |
156 | items[files-1].added = lines_added; |
156 | items[files-1].added = lines_added; |
157 | items[files-1].removed = lines_removed; |
157 | items[files-1].removed = lines_removed; |
158 | items[files-1].old_size = old_size; |
158 | items[files-1].old_size = old_size; |
159 | items[files-1].new_size = new_size; |
159 | items[files-1].new_size = new_size; |
160 | items[files-1].binary = binary; |
160 | items[files-1].binary = binary; |
161 | if (lines_added + lines_removed > max_changes) |
161 | if (lines_added + lines_removed > max_changes) |
162 | max_changes = lines_added + lines_removed; |
162 | max_changes = lines_added + lines_removed; |
163 | total_adds += lines_added; |
163 | total_adds += lines_added; |
164 | total_rems += lines_removed; |
164 | total_rems += lines_removed; |
165 | } |
165 | } |
166 | |
166 | |
167 | void cgit_print_diffstat(const unsigned char *old_sha1, |
167 | void cgit_print_diffstat(const unsigned char *old_sha1, |
168 | const unsigned char *new_sha1, const char *prefix) |
168 | const unsigned char *new_sha1, const char *prefix) |
169 | { |
169 | { |
170 | int i, save_context = ctx.qry.context; |
170 | int i, save_context = ctx.qry.context; |
171 | |
171 | |
172 | html("<div class='diffstat-header'>"); |
172 | html("<div class='diffstat-header'>"); |
173 | cgit_diff_link("Diffstat", NULL, NULL, ctx.qry.head, ctx.qry.sha1, |
173 | cgit_diff_link("Diffstat", NULL, NULL, ctx.qry.head, ctx.qry.sha1, |
174 | ctx.qry.sha2, NULL, 0); |
174 | ctx.qry.sha2, NULL, 0); |
175 | if (prefix) |
175 | if (prefix) { |
176 | htmlf(" (limited to '%s')", prefix); |
176 | html(" (limited to '"); |
| |
177 | html_txt(prefix); |
| |
178 | html("')"); |
| |
179 | } |
177 | html(" ("); |
180 | html(" ("); |
178 | ctx.qry.context = (save_context > 0 ? save_context : 3) << 1; |
181 | ctx.qry.context = (save_context > 0 ? save_context : 3) << 1; |
179 | cgit_self_link("more", NULL, NULL, &ctx); |
182 | cgit_self_link("more", NULL, NULL, &ctx); |
180 | html("/"); |
183 | html("/"); |
181 | ctx.qry.context = (save_context > 3 ? save_context : 3) >> 1; |
184 | ctx.qry.context = (save_context > 3 ? save_context : 3) >> 1; |
182 | cgit_self_link("less", NULL, NULL, &ctx); |
185 | cgit_self_link("less", NULL, NULL, &ctx); |
183 | ctx.qry.context = save_context; |
186 | ctx.qry.context = save_context; |
184 | html(" context)"); |
187 | html(" context)"); |
185 | html(" ("); |
188 | html(" ("); |
186 | ctx.qry.ignorews = (ctx.qry.ignorews + 1) % 2; |
189 | ctx.qry.ignorews = (ctx.qry.ignorews + 1) % 2; |
187 | cgit_self_link(ctx.qry.ignorews ? "ignore" : "show", NULL, NULL, &ctx); |
190 | cgit_self_link(ctx.qry.ignorews ? "ignore" : "show", NULL, NULL, &ctx); |
188 | ctx.qry.ignorews = (ctx.qry.ignorews + 1) % 2; |
191 | ctx.qry.ignorews = (ctx.qry.ignorews + 1) % 2; |
189 | html(" whitespace changes)"); |
192 | html(" whitespace changes)"); |
190 | html("</div>"); |
193 | html("</div>"); |
191 | html("<table summary='diffstat' class='diffstat'>"); |
194 | html("<table summary='diffstat' class='diffstat'>"); |
192 | max_changes = 0; |
195 | max_changes = 0; |
193 | cgit_diff_tree(old_sha1, new_sha1, inspect_filepair, prefix, |
196 | cgit_diff_tree(old_sha1, new_sha1, inspect_filepair, prefix, |
194 | ctx.qry.ignorews); |
197 | ctx.qry.ignorews); |
195 | for(i = 0; i<files; i++) |
198 | for(i = 0; i<files; i++) |
196 | print_fileinfo(&items[i]); |
199 | print_fileinfo(&items[i]); |
197 | html("</table>"); |
200 | html("</table>"); |
198 | html("<div class='diffstat-summary'>"); |
201 | html("<div class='diffstat-summary'>"); |
199 | htmlf("%d files changed, %d insertions, %d deletions", |
202 | htmlf("%d files changed, %d insertions, %d deletions", |
200 | files, total_adds, total_rems); |
203 | files, total_adds, total_rems); |
201 | html("</div>"); |
204 | html("</div>"); |
202 | } |
205 | } |
203 | |
206 | |
204 | |
207 | |
205 | /* |
208 | /* |
206 | * print a single line returned from xdiff |
209 | * print a single line returned from xdiff |
207 | */ |
210 | */ |
208 | static void print_line(char *line, int len) |
211 | static void print_line(char *line, int len) |
209 | { |
212 | { |
210 | char *class = "ctx"; |
213 | char *class = "ctx"; |
211 | char c = line[len-1]; |
214 | char c = line[len-1]; |
212 | |
215 | |
213 | if (line[0] == '+') |
216 | if (line[0] == '+') |
214 | class = "add"; |
217 | class = "add"; |
215 | else if (line[0] == '-') |
218 | else if (line[0] == '-') |
216 | class = "del"; |
219 | class = "del"; |
217 | else if (line[0] == '@') |
220 | else if (line[0] == '@') |
218 | class = "hunk"; |
221 | class = "hunk"; |
219 | |
222 | |
220 | htmlf("<div class='%s'>", class); |
223 | htmlf("<div class='%s'>", class); |
221 | line[len-1] = '\0'; |
224 | line[len-1] = '\0'; |
222 | html_txt(line); |
225 | html_txt(line); |
223 | html("</div>"); |
226 | html("</div>"); |
224 | line[len-1] = c; |
227 | line[len-1] = c; |
225 | } |
228 | } |
226 | |
229 | |
227 | static void header(unsigned char *sha1, char *path1, int mode1, |
230 | static void header(unsigned char *sha1, char *path1, int mode1, |
228 | unsigned char *sha2, char *path2, int mode2) |
231 | unsigned char *sha2, char *path2, int mode2) |
229 | { |
232 | { |
230 | char *abbrev1, *abbrev2; |
233 | char *abbrev1, *abbrev2; |
231 | int subproject; |
234 | int subproject; |
232 | |
235 | |
233 | subproject = (S_ISGITLINK(mode1) || S_ISGITLINK(mode2)); |
236 | subproject = (S_ISGITLINK(mode1) || S_ISGITLINK(mode2)); |
234 | html("<div class='head'>"); |
237 | html("<div class='head'>"); |
235 | html("diff --git a/"); |
238 | html("diff --git a/"); |
236 | html_txt(path1); |
239 | html_txt(path1); |
237 | html(" b/"); |
240 | html(" b/"); |
238 | html_txt(path2); |
241 | html_txt(path2); |
239 | |
242 | |
240 | if (is_null_sha1(sha1)) |
243 | if (is_null_sha1(sha1)) |
241 | path1 = "dev/null"; |
244 | path1 = "dev/null"; |
242 | if (is_null_sha1(sha2)) |
245 | if (is_null_sha1(sha2)) |
243 | path2 = "dev/null"; |
246 | path2 = "dev/null"; |
244 | |
247 | |
245 | if (mode1 == 0) |
248 | if (mode1 == 0) |
246 | htmlf("<br/>new file mode %.6o", mode2); |
249 | htmlf("<br/>new file mode %.6o", mode2); |
247 | |
250 | |
248 | if (mode2 == 0) |
251 | if (mode2 == 0) |
249 | htmlf("<br/>deleted file mode %.6o", mode1); |
252 | htmlf("<br/>deleted file mode %.6o", mode1); |
250 | |
253 | |
251 | if (!subproject) { |
254 | if (!subproject) { |
252 | abbrev1 = xstrdup(find_unique_abbrev(sha1, DEFAULT_ABBREV)); |
255 | abbrev1 = xstrdup(find_unique_abbrev(sha1, DEFAULT_ABBREV)); |
253 | abbrev2 = xstrdup(find_unique_abbrev(sha2, DEFAULT_ABBREV)); |
256 | abbrev2 = xstrdup(find_unique_abbrev(sha2, DEFAULT_ABBREV)); |
254 | htmlf("<br/>index %s..%s", abbrev1, abbrev2); |
257 | htmlf("<br/>index %s..%s", abbrev1, abbrev2); |
255 | free(abbrev1); |
258 | free(abbrev1); |
256 | free(abbrev2); |
259 | free(abbrev2); |
257 | if (mode1 != 0 && mode2 != 0) { |
260 | if (mode1 != 0 && mode2 != 0) { |
258 | htmlf(" %.6o", mode1); |
261 | htmlf(" %.6o", mode1); |
259 | if (mode2 != mode1) |
262 | if (mode2 != mode1) |
260 | htmlf("..%.6o", mode2); |
263 | htmlf("..%.6o", mode2); |
261 | } |
264 | } |
262 | html("<br/>--- a/"); |
265 | html("<br/>--- a/"); |
263 | if (mode1 != 0) |
266 | if (mode1 != 0) |
264 | cgit_tree_link(path1, NULL, NULL, ctx.qry.head, |
267 | cgit_tree_link(path1, NULL, NULL, ctx.qry.head, |
265 | sha1_to_hex(old_rev_sha1), path1); |
268 | sha1_to_hex(old_rev_sha1), path1); |
266 | else |
269 | else |
267 | html_txt(path1); |
270 | html_txt(path1); |
268 | html("<br/>+++ b/"); |
271 | html("<br/>+++ b/"); |
269 | if (mode2 != 0) |
272 | if (mode2 != 0) |
270 | cgit_tree_link(path2, NULL, NULL, ctx.qry.head, |
273 | cgit_tree_link(path2, NULL, NULL, ctx.qry.head, |
271 | sha1_to_hex(new_rev_sha1), path2); |
274 | sha1_to_hex(new_rev_sha1), path2); |
272 | else |
275 | else |
|