aboutsummaryrefslogtreecommitdiffstats
path: root/ui-diff.c
diff options
context:
space:
mode:
Diffstat (limited to 'ui-diff.c')
-rw-r--r--ui-diff.c92
1 files changed, 75 insertions, 17 deletions
diff --git a/ui-diff.c b/ui-diff.c
index 2196745..0dcabe9 100644
--- a/ui-diff.c
+++ b/ui-diff.c
@@ -9,6 +9,7 @@
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#include "ui-ssdiff.h"
12 13
13unsigned char old_rev_sha1[20]; 14unsigned char old_rev_sha1[20];
14unsigned char new_rev_sha1[20]; 15unsigned char new_rev_sha1[20];
@@ -32,6 +33,7 @@ static struct fileinfo {
32 int binary:1; 33 int binary:1;
33} *items; 34} *items;
34 35
36static int use_ssdiff = 0;
35 37
36static void print_fileinfo(struct fileinfo *info) 38static void print_fileinfo(struct fileinfo *info)
37{ 39{
@@ -83,7 +85,7 @@ static void print_fileinfo(struct fileinfo *info)
83 } 85 }
84 htmlf("</td><td class='%s'>", class); 86 htmlf("</td><td class='%s'>", class);
85 cgit_diff_link(info->new_path, NULL, NULL, ctx.qry.head, ctx.qry.sha1, 87 cgit_diff_link(info->new_path, NULL, NULL, ctx.qry.head, ctx.qry.sha1,
86 ctx.qry.sha2, info->new_path); 88 ctx.qry.sha2, info->new_path, 0);
87 if (info->status == DIFF_STATUS_COPIED || info->status == DIFF_STATUS_RENAMED) 89 if (info->status == DIFF_STATUS_COPIED || info->status == DIFF_STATUS_RENAMED)
88 htmlf(" (%s from %s)", 90 htmlf(" (%s from %s)",
89 info->status == DIFF_STATUS_COPIED ? "copied" : "renamed", 91 info->status == DIFF_STATUS_COPIED ? "copied" : "renamed",
@@ -125,7 +127,7 @@ static void inspect_filepair(struct diff_filepair *pair)
125 lines_added = 0; 127 lines_added = 0;
126 lines_removed = 0; 128 lines_removed = 0;
127 cgit_diff_files(pair->one->sha1, pair->two->sha1, &old_size, &new_size, 129 cgit_diff_files(pair->one->sha1, pair->two->sha1, &old_size, &new_size,
128 &binary, count_diff_lines); 130 &binary, 0, ctx.qry.ignorews, count_diff_lines);
129 if (files >= slots) { 131 if (files >= slots) {
130 if (slots == 0) 132 if (slots == 0)
131 slots = 4; 133 slots = 4;
@@ -152,17 +154,33 @@ static void inspect_filepair(struct diff_filepair *pair)
152} 154}
153 155
154void cgit_print_diffstat(const unsigned char *old_sha1, 156void cgit_print_diffstat(const unsigned char *old_sha1,
155 const unsigned char *new_sha1) 157 const unsigned char *new_sha1, const char *prefix)
156{ 158{
157 int i; 159 int i, save_context = ctx.qry.context;
158 160
159 html("<div class='diffstat-header'>"); 161 html("<div class='diffstat-header'>");
160 cgit_diff_link("Diffstat", NULL, NULL, ctx.qry.head, ctx.qry.sha1, 162 cgit_diff_link("Diffstat", NULL, NULL, ctx.qry.head, ctx.qry.sha1,
161 ctx.qry.sha2, NULL); 163 ctx.qry.sha2, NULL, 0);
164 if (prefix)
165 htmlf(" (limited to '%s')", prefix);
166 html(" (");
167 ctx.qry.context = (save_context > 0 ? save_context : 3) << 1;
168 cgit_self_link("more", NULL, NULL, &ctx);
169 html("/");
170 ctx.qry.context = (save_context > 3 ? save_context : 3) >> 1;
171 cgit_self_link("less", NULL, NULL, &ctx);
172 ctx.qry.context = save_context;
173 html(" context)");
174 html(" (");
175 ctx.qry.ignorews = (ctx.qry.ignorews + 1) % 2;
176 cgit_self_link(ctx.qry.ignorews ? "ignore" : "show", NULL, NULL, &ctx);
177 ctx.qry.ignorews = (ctx.qry.ignorews + 1) % 2;
178 html(" whitespace changes)");
162 html("</div>"); 179 html("</div>");
163 html("<table summary='diffstat' class='diffstat'>"); 180 html("<table summary='diffstat' class='diffstat'>");
164 max_changes = 0; 181 max_changes = 0;
165 cgit_diff_tree(old_sha1, new_sha1, inspect_filepair, NULL); 182 cgit_diff_tree(old_sha1, new_sha1, inspect_filepair, prefix,
183 ctx.qry.ignorews);
166 for(i = 0; i<files; i++) 184 for(i = 0; i<files; i++)
167 print_fileinfo(&items[i]); 185 print_fileinfo(&items[i]);
168 html("</table>"); 186 html("</table>");
@@ -246,26 +264,55 @@ static void header(unsigned char *sha1, char *path1, int mode1,
246 html("</div>"); 264 html("</div>");
247} 265}
248 266
267static void print_ssdiff_link()
268{
269 if (!strcmp(ctx.qry.page, "diff")) {
270 if (use_ssdiff)
271 cgit_diff_link("Unidiff", NULL, NULL, ctx.qry.head,
272 ctx.qry.sha1, ctx.qry.sha2, ctx.qry.path, 1);
273 else
274 cgit_diff_link("Side-by-side diff", NULL, NULL,
275 ctx.qry.head, ctx.qry.sha1,
276 ctx.qry.sha2, ctx.qry.path, 1);
277 }
278}
279
249static void filepair_cb(struct diff_filepair *pair) 280static void filepair_cb(struct diff_filepair *pair)
250{ 281{
251 unsigned long old_size = 0; 282 unsigned long old_size = 0;
252 unsigned long new_size = 0; 283 unsigned long new_size = 0;
253 int binary = 0; 284 int binary = 0;
285 linediff_fn print_line_fn = print_line;
254 286
287 if (use_ssdiff) {
288 cgit_ssdiff_header_begin();
289 print_line_fn = cgit_ssdiff_line_cb;
290 }
255 header(pair->one->sha1, pair->one->path, pair->one->mode, 291 header(pair->one->sha1, pair->one->path, pair->one->mode,
256 pair->two->sha1, pair->two->path, pair->two->mode); 292 pair->two->sha1, pair->two->path, pair->two->mode);
293 if (use_ssdiff)
294 cgit_ssdiff_header_end();
257 if (S_ISGITLINK(pair->one->mode) || S_ISGITLINK(pair->two->mode)) { 295 if (S_ISGITLINK(pair->one->mode) || S_ISGITLINK(pair->two->mode)) {
258 if (S_ISGITLINK(pair->one->mode)) 296 if (S_ISGITLINK(pair->one->mode))
259 print_line(fmt("-Subproject %s", sha1_to_hex(pair->one->sha1)), 52); 297 print_line_fn(fmt("-Subproject %s", sha1_to_hex(pair->one->sha1)), 52);
260 if (S_ISGITLINK(pair->two->mode)) 298 if (S_ISGITLINK(pair->two->mode))
261 print_line(fmt("+Subproject %s", sha1_to_hex(pair->two->sha1)), 52); 299 print_line_fn(fmt("+Subproject %s", sha1_to_hex(pair->two->sha1)), 52);
300 if (use_ssdiff)
301 cgit_ssdiff_footer();
262 return; 302 return;
263 } 303 }
264 if (cgit_diff_files(pair->one->sha1, pair->two->sha1, &old_size, 304 if (cgit_diff_files(pair->one->sha1, pair->two->sha1, &old_size,
265 &new_size, &binary, print_line)) 305 &new_size, &binary, ctx.qry.context,
306 ctx.qry.ignorews, print_line_fn))
266 cgit_print_error("Error running diff"); 307 cgit_print_error("Error running diff");
267 if (binary) 308 if (binary) {
268 html("Binary files differ"); 309 if (use_ssdiff)
310 html("<tr><td colspan='4'>Binary files differ</td></tr>");
311 else
312 html("Binary files differ");
313 }
314 if (use_ssdiff)
315 cgit_ssdiff_footer();
269} 316}
270 317
271void cgit_print_diff(const char *new_rev, const char *old_rev, const char *prefix) 318void cgit_print_diff(const char *new_rev, const char *old_rev, const char *prefix)
@@ -303,11 +350,22 @@ void cgit_print_diff(const char *new_rev, const char *old_rev, const char *prefi
303 if (!commit2 || parse_commit(commit2)) 350 if (!commit2 || parse_commit(commit2))
304 cgit_print_error(fmt("Bad commit: %s", sha1_to_hex(old_rev_sha1))); 351 cgit_print_error(fmt("Bad commit: %s", sha1_to_hex(old_rev_sha1)));
305 } 352 }
306 cgit_print_diffstat(old_rev_sha1, new_rev_sha1);
307 353
308 html("<table summary='diff' class='diff'>"); 354 if ((ctx.qry.ssdiff && !ctx.cfg.ssdiff) || (!ctx.qry.ssdiff && ctx.cfg.ssdiff))
309 html("<tr><td>"); 355 use_ssdiff = 1;
310 cgit_diff_tree(old_rev_sha1, new_rev_sha1, filepair_cb, prefix); 356
311 html("</td></tr>"); 357 print_ssdiff_link();
358 cgit_print_diffstat(old_rev_sha1, new_rev_sha1, prefix);
359
360 if (use_ssdiff) {
361 html("<table summary='ssdiff' class='ssdiff'>");
362 } else {
363 html("<table summary='diff' class='diff'>");
364 html("<tr><td>");
365 }
366 cgit_diff_tree(old_rev_sha1, new_rev_sha1, filepair_cb, prefix,
367 ctx.qry.ignorews);
368 if (!use_ssdiff)
369 html("</td></tr>");
312 html("</table>"); 370 html("</table>");
313} 371}