about summary refs log tree commit diff stats
path: root/ui-diff.c
diff options
context:
space:
mode:
Diffstat (limited to 'ui-diff.c')
-rw-r--r--ui-diff.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/ui-diff.c b/ui-diff.c index 1cf2ce0..caebd5d 100644 --- a/ui-diff.c +++ b/ui-diff.c
@@ -36,6 +36,7 @@ static struct fileinfo {
36 36
37static int use_ssdiff = 0; 37static int use_ssdiff = 0;
38static struct diff_filepair *current_filepair; 38static struct diff_filepair *current_filepair;
39static const char *current_prefix;
39 40
40struct diff_filespec *cgit_get_current_old_file(void) 41struct diff_filespec *cgit_get_current_old_file(void)
41{ 42{
@@ -132,11 +133,30 @@ static void count_diff_lines(char *line, int len)
132 } 133 }
133} 134}
134 135
136static int show_filepair(struct diff_filepair *pair)
137{
138 /* Always show if we have no limiting prefix. */
139 if (!current_prefix)
140 return 1;
141
142 /* Show if either path in the pair begins with the prefix. */
143 if (starts_with(pair->one->path, current_prefix) ||
144 starts_with(pair->two->path, current_prefix))
145 return 1;
146
147 /* Otherwise we don't want to show this filepair. */
148 return 0;
149}
150
135static void inspect_filepair(struct diff_filepair *pair) 151static void inspect_filepair(struct diff_filepair *pair)
136{ 152{
137 int binary = 0; 153 int binary = 0;
138 unsigned long old_size = 0; 154 unsigned long old_size = 0;
139 unsigned long new_size = 0; 155 unsigned long new_size = 0;
156
157 if (!show_filepair(pair))
158 return;
159
140 files++; 160 files++;
141 lines_added = 0; 161 lines_added = 0;
142 lines_removed = 0; 162 lines_removed = 0;
@@ -279,6 +299,9 @@ static void filepair_cb(struct diff_filepair *pair)
279 int binary = 0; 299 int binary = 0;
280 linediff_fn print_line_fn = print_line; 300 linediff_fn print_line_fn = print_line;
281 301
302 if (!show_filepair(pair))
303 return;
304
282 current_filepair = pair; 305 current_filepair = pair;
283 if (use_ssdiff) { 306 if (use_ssdiff) {
284 cgit_ssdiff_header_begin(); 307 cgit_ssdiff_header_begin();
@@ -365,6 +388,18 @@ void cgit_print_diff(const char *new_rev, const char *old_rev,
365 const unsigned char *old_tree_sha1, *new_tree_sha1; 388 const unsigned char *old_tree_sha1, *new_tree_sha1;
366 diff_type difftype; 389 diff_type difftype;
367 390
391 /*
392 * If "follow" is set then the diff machinery needs to examine the
393 * entire commit to detect renames so we must limit the paths in our
394 * own callbacks and not pass the prefix to the diff machinery.
395 */
396 if (ctx.qry.follow && ctx.cfg.enable_follow_links) {
397 current_prefix = prefix;
398 prefix = "";
399 } else {
400 current_prefix = NULL;
401 }
402
368 if (!new_rev) 403 if (!new_rev)
369 new_rev = ctx.qry.head; 404 new_rev = ctx.qry.head;
370 if (get_sha1(new_rev, new_rev_sha1)) { 405 if (get_sha1(new_rev, new_rev_sha1)) {