aboutsummaryrefslogtreecommitdiffstats
path: root/ui-diff.c
diff options
context:
space:
mode:
Diffstat (limited to 'ui-diff.c')
-rw-r--r--ui-diff.c106
1 files changed, 88 insertions, 18 deletions
diff --git a/ui-diff.c b/ui-diff.c
index 2196745..a53425d 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,18 @@ static struct fileinfo {
32 int binary:1; 33 int binary:1;
33} *items; 34} *items;
34 35
36static int use_ssdiff = 0;
37static struct diff_filepair *current_filepair;
38
39struct diff_filespec *cgit_get_current_old_file(void)
40{
41 return current_filepair->one;
42}
43
44struct diff_filespec *cgit_get_current_new_file(void)
45{
46 return current_filepair->two;
47}
35 48
36static void print_fileinfo(struct fileinfo *info) 49static void print_fileinfo(struct fileinfo *info)
37{ 50{
@@ -83,14 +96,14 @@ static void print_fileinfo(struct fileinfo *info)
83 } 96 }
84 htmlf("</td><td class='%s'>", class); 97 htmlf("</td><td class='%s'>", class);
85 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,
86 ctx.qry.sha2, info->new_path); 99 ctx.qry.sha2, info->new_path, 0);
87 if (info->status == DIFF_STATUS_COPIED || info->status == DIFF_STATUS_RENAMED) 100 if (info->status == DIFF_STATUS_COPIED || info->status == DIFF_STATUS_RENAMED)
88 htmlf(" (%s from %s)", 101 htmlf(" (%s from %s)",
89 info->status == DIFF_STATUS_COPIED ? "copied" : "renamed", 102 info->status == DIFF_STATUS_COPIED ? "copied" : "renamed",
90 info->old_path); 103 info->old_path);
91 html("</td><td class='right'>"); 104 html("</td><td class='right'>");
92 if (info->binary) { 105 if (info->binary) {
93 htmlf("bin</td><td class='graph'>%d -> %d bytes", 106 htmlf("bin</td><td class='graph'>%ld -> %ld bytes",
94 info->old_size, info->new_size); 107 info->old_size, info->new_size);
95 return; 108 return;
96 } 109 }
@@ -125,7 +138,7 @@ static void inspect_filepair(struct diff_filepair *pair)
125 lines_added = 0; 138 lines_added = 0;
126 lines_removed = 0; 139 lines_removed = 0;
127 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,
128 &binary, count_diff_lines); 141 &binary, 0, ctx.qry.ignorews, count_diff_lines);
129 if (files >= slots) { 142 if (files >= slots) {
130 if (slots == 0) 143 if (slots == 0)
131 slots = 4; 144 slots = 4;
@@ -152,17 +165,33 @@ static void inspect_filepair(struct diff_filepair *pair)
152} 165}
153 166
154void cgit_print_diffstat(const unsigned char *old_sha1, 167void cgit_print_diffstat(const unsigned char *old_sha1,
155 const unsigned char *new_sha1) 168 const unsigned char *new_sha1, const char *prefix)
156{ 169{
157 int i; 170 int i, save_context = ctx.qry.context;
158 171
159 html("<div class='diffstat-header'>"); 172 html("<div class='diffstat-header'>");
160 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,
161 ctx.qry.sha2, NULL); 174 ctx.qry.sha2, NULL, 0);
175 if (prefix)
176 htmlf(" (limited to '%s')", prefix);
177 html(" (");
178 ctx.qry.context = (save_context > 0 ? save_context : 3) << 1;
179 cgit_self_link("more", NULL, NULL, &ctx);
180 html("/");
181 ctx.qry.context = (save_context > 3 ? save_context : 3) >> 1;
182 cgit_self_link("less", NULL, NULL, &ctx);
183 ctx.qry.context = save_context;
184 html(" context)");
185 html(" (");
186 ctx.qry.ignorews = (ctx.qry.ignorews + 1) % 2;
187 cgit_self_link(ctx.qry.ignorews ? "ignore" : "show", NULL, NULL, &ctx);
188 ctx.qry.ignorews = (ctx.qry.ignorews + 1) % 2;
189 html(" whitespace changes)");
162 html("</div>"); 190 html("</div>");
163 html("<table summary='diffstat' class='diffstat'>"); 191 html("<table summary='diffstat' class='diffstat'>");
164 max_changes = 0; 192 max_changes = 0;
165 cgit_diff_tree(old_sha1, new_sha1, inspect_filepair, NULL); 193 cgit_diff_tree(old_sha1, new_sha1, inspect_filepair, prefix,
194 ctx.qry.ignorews);
166 for(i = 0; i<files; i++) 195 for(i = 0; i<files; i++)
167 print_fileinfo(&items[i]); 196 print_fileinfo(&items[i]);
168 html("</table>"); 197 html("</table>");
@@ -246,26 +275,56 @@ static void header(unsigned char *sha1, char *path1, int mode1,
246 html("</div>"); 275 html("</div>");
247} 276}
248 277
278static void print_ssdiff_link()
279{
280 if (!strcmp(ctx.qry.page, "diff")) {
281 if (use_ssdiff)
282 cgit_diff_link("Unidiff", NULL, NULL, ctx.qry.head,
283 ctx.qry.sha1, ctx.qry.sha2, ctx.qry.path, 1);
284 else
285 cgit_diff_link("Side-by-side diff", NULL, NULL,
286 ctx.qry.head, ctx.qry.sha1,
287 ctx.qry.sha2, ctx.qry.path, 1);
288 }
289}
290
249static void filepair_cb(struct diff_filepair *pair) 291static void filepair_cb(struct diff_filepair *pair)
250{ 292{
251 unsigned long old_size = 0; 293 unsigned long old_size = 0;
252 unsigned long new_size = 0; 294 unsigned long new_size = 0;
253 int binary = 0; 295 int binary = 0;
296 linediff_fn print_line_fn = print_line;
254 297
298 current_filepair = pair;
299 if (use_ssdiff) {
300 cgit_ssdiff_header_begin();
301 print_line_fn = cgit_ssdiff_line_cb;
302 }
255 header(pair->one->sha1, pair->one->path, pair->one->mode, 303 header(pair->one->sha1, pair->one->path, pair->one->mode,
256 pair->two->sha1, pair->two->path, pair->two->mode); 304 pair->two->sha1, pair->two->path, pair->two->mode);
305 if (use_ssdiff)
306 cgit_ssdiff_header_end();
257 if (S_ISGITLINK(pair->one->mode) || S_ISGITLINK(pair->two->mode)) { 307 if (S_ISGITLINK(pair->one->mode) || S_ISGITLINK(pair->two->mode)) {
258 if (S_ISGITLINK(pair->one->mode)) 308 if (S_ISGITLINK(pair->one->mode))
259 print_line(fmt("-Subproject %s", sha1_to_hex(pair->one->sha1)), 52); 309 print_line_fn(fmt("-Subproject %s", sha1_to_hex(pair->one->sha1)), 52);
260 if (S_ISGITLINK(pair->two->mode)) 310 if (S_ISGITLINK(pair->two->mode))
261 print_line(fmt("+Subproject %s", sha1_to_hex(pair->two->sha1)), 52); 311 print_line_fn(fmt("+Subproject %s", sha1_to_hex(pair->two->sha1)), 52);
312 if (use_ssdiff)
313 cgit_ssdiff_footer();
262 return; 314 return;
263 } 315 }
264 if (cgit_diff_files(pair->one->sha1, pair->two->sha1, &old_size, 316 if (cgit_diff_files(pair->one->sha1, pair->two->sha1, &old_size,
265 &new_size, &binary, print_line)) 317 &new_size, &binary, ctx.qry.context,
318 ctx.qry.ignorews, print_line_fn))
266 cgit_print_error("Error running diff"); 319 cgit_print_error("Error running diff");
267 if (binary) 320 if (binary) {
268 html("Binary files differ"); 321 if (use_ssdiff)
322 html("<tr><td colspan='4'>Binary files differ</td></tr>");
323 else
324 html("Binary files differ");
325 }
326 if (use_ssdiff)
327 cgit_ssdiff_footer();
269} 328}
270 329
271void cgit_print_diff(const char *new_rev, const char *old_rev, const char *prefix) 330void cgit_print_diff(const char *new_rev, const char *old_rev, const char *prefix)
@@ -303,11 +362,22 @@ void cgit_print_diff(const char *new_rev, const char *old_rev, const char *prefi
303 if (!commit2 || parse_commit(commit2)) 362 if (!commit2 || parse_commit(commit2))
304 cgit_print_error(fmt("Bad commit: %s", sha1_to_hex(old_rev_sha1))); 363 cgit_print_error(fmt("Bad commit: %s", sha1_to_hex(old_rev_sha1)));
305 } 364 }
306 cgit_print_diffstat(old_rev_sha1, new_rev_sha1);
307 365
308 html("<table summary='diff' class='diff'>"); 366 if ((ctx.qry.ssdiff && !ctx.cfg.ssdiff) || (!ctx.qry.ssdiff && ctx.cfg.ssdiff))
309 html("<tr><td>"); 367 use_ssdiff = 1;
310 cgit_diff_tree(old_rev_sha1, new_rev_sha1, filepair_cb, prefix); 368
311 html("</td></tr>"); 369 print_ssdiff_link();
370 cgit_print_diffstat(old_rev_sha1, new_rev_sha1, prefix);
371
372 if (use_ssdiff) {
373 html("<table summary='ssdiff' class='ssdiff'>");
374 } else {
375 html("<table summary='diff' class='diff'>");
376 html("<tr><td>");
377 }
378 cgit_diff_tree(old_rev_sha1, new_rev_sha1, filepair_cb, prefix,
379 ctx.qry.ignorews);
380 if (!use_ssdiff)
381 html("</td></tr>");
312 html("</table>"); 382 html("</table>");
313} 383}