aboutsummaryrefslogtreecommitdiffstats
path: root/ui-diff.c
diff options
context:
space:
mode:
Diffstat (limited to 'ui-diff.c')
-rw-r--r--ui-diff.c82
1 files changed, 66 insertions, 16 deletions
diff --git a/ui-diff.c b/ui-diff.c
index 2196745..e0a72f7 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, 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,27 @@ 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)");
162 html("</div>"); 174 html("</div>");
163 html("<table summary='diffstat' class='diffstat'>"); 175 html("<table summary='diffstat' class='diffstat'>");
164 max_changes = 0; 176 max_changes = 0;
165 cgit_diff_tree(old_sha1, new_sha1, inspect_filepair, NULL); 177 cgit_diff_tree(old_sha1, new_sha1, inspect_filepair, prefix);
166 for(i = 0; i<files; i++) 178 for(i = 0; i<files; i++)
167 print_fileinfo(&items[i]); 179 print_fileinfo(&items[i]);
168 html("</table>"); 180 html("</table>");
@@ -246,26 +258,54 @@ static void header(unsigned char *sha1, char *path1, int mode1,
246 html("</div>"); 258 html("</div>");
247} 259}
248 260
261static void print_ssdiff_link()
262{
263 if (!strcmp(ctx.qry.page, "diff")) {
264 if (use_ssdiff)
265 cgit_diff_link("Unidiff", NULL, NULL, ctx.qry.head,
266 ctx.qry.sha1, ctx.qry.sha2, ctx.qry.path, 1);
267 else
268 cgit_diff_link("Side-by-side diff", NULL, NULL,
269 ctx.qry.head, ctx.qry.sha1,
270 ctx.qry.sha2, ctx.qry.path, 1);
271 }
272}
273
249static void filepair_cb(struct diff_filepair *pair) 274static void filepair_cb(struct diff_filepair *pair)
250{ 275{
251 unsigned long old_size = 0; 276 unsigned long old_size = 0;
252 unsigned long new_size = 0; 277 unsigned long new_size = 0;
253 int binary = 0; 278 int binary = 0;
279 linediff_fn print_line_fn = print_line;
254 280
281 if (use_ssdiff) {
282 cgit_ssdiff_header_begin();
283 print_line_fn = cgit_ssdiff_line_cb;
284 }
255 header(pair->one->sha1, pair->one->path, pair->one->mode, 285 header(pair->one->sha1, pair->one->path, pair->one->mode,
256 pair->two->sha1, pair->two->path, pair->two->mode); 286 pair->two->sha1, pair->two->path, pair->two->mode);
287 if (use_ssdiff)
288 cgit_ssdiff_header_end();
257 if (S_ISGITLINK(pair->one->mode) || S_ISGITLINK(pair->two->mode)) { 289 if (S_ISGITLINK(pair->one->mode) || S_ISGITLINK(pair->two->mode)) {
258 if (S_ISGITLINK(pair->one->mode)) 290 if (S_ISGITLINK(pair->one->mode))
259 print_line(fmt("-Subproject %s", sha1_to_hex(pair->one->sha1)), 52); 291 print_line_fn(fmt("-Subproject %s", sha1_to_hex(pair->one->sha1)), 52);
260 if (S_ISGITLINK(pair->two->mode)) 292 if (S_ISGITLINK(pair->two->mode))
261 print_line(fmt("+Subproject %s", sha1_to_hex(pair->two->sha1)), 52); 293 print_line_fn(fmt("+Subproject %s", sha1_to_hex(pair->two->sha1)), 52);
294 if (use_ssdiff)
295 cgit_ssdiff_footer();
262 return; 296 return;
263 } 297 }
264 if (cgit_diff_files(pair->one->sha1, pair->two->sha1, &old_size, 298 if (cgit_diff_files(pair->one->sha1, pair->two->sha1, &old_size,
265 &new_size, &binary, print_line)) 299 &new_size, &binary, ctx.qry.context, print_line_fn))
266 cgit_print_error("Error running diff"); 300 cgit_print_error("Error running diff");
267 if (binary) 301 if (binary) {
268 html("Binary files differ"); 302 if (use_ssdiff)
303 html("<tr><td colspan='4'>Binary files differ</td></tr>");
304 else
305 html("Binary files differ");
306 }
307 if (use_ssdiff)
308 cgit_ssdiff_footer();
269} 309}
270 310
271void cgit_print_diff(const char *new_rev, const char *old_rev, const char *prefix) 311void cgit_print_diff(const char *new_rev, const char *old_rev, const char *prefix)
@@ -303,11 +343,21 @@ void cgit_print_diff(const char *new_rev, const char *old_rev, const char *prefi
303 if (!commit2 || parse_commit(commit2)) 343 if (!commit2 || parse_commit(commit2))
304 cgit_print_error(fmt("Bad commit: %s", sha1_to_hex(old_rev_sha1))); 344 cgit_print_error(fmt("Bad commit: %s", sha1_to_hex(old_rev_sha1)));
305 } 345 }
306 cgit_print_diffstat(old_rev_sha1, new_rev_sha1);
307 346
308 html("<table summary='diff' class='diff'>"); 347 if ((ctx.qry.ssdiff && !ctx.cfg.ssdiff) || (!ctx.qry.ssdiff && ctx.cfg.ssdiff))
309 html("<tr><td>"); 348 use_ssdiff = 1;
349
350 print_ssdiff_link();
351 cgit_print_diffstat(old_rev_sha1, new_rev_sha1, prefix);
352
353 if (use_ssdiff) {
354 html("<table summary='ssdiff' class='ssdiff'>");
355 } else {
356 html("<table summary='diff' class='diff'>");
357 html("<tr><td>");
358 }
310 cgit_diff_tree(old_rev_sha1, new_rev_sha1, filepair_cb, prefix); 359 cgit_diff_tree(old_rev_sha1, new_rev_sha1, filepair_cb, prefix);
311 html("</td></tr>"); 360 if (!use_ssdiff)
361 html("</td></tr>");
312 html("</table>"); 362 html("</table>");
313} 363}