apply: omit ws check for excluded paths

Whitespace breakages are checked while the patch is being parsed. Disable them at the beginning of parse_chunk(), where each individual patch is parsed, immediately after we learn the name of the file the patch applies to and before we start parsing the diff contained in the patch. One may naively think that we should be able to not just skip the whitespace checks but simply fast-forward to the next patch without doing anything once use_patch() tells us that this patch is not going to be used. But in reality we cannot really skip much of the parsing in order to do such a "fast-forward", primarily because parsing "@@ -k,l +m,n @@" lines and counting the input lines is how we determine the boundaries of individual patches. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Aug 6, 2014 at 13:09 UTC 477a08af04c227064860ce99197c501037f7f39c
2 files changed +17 -3
builtin/apply.c
+6 -3
@@ -1997,9 +1997,12 @@ static int parse_chunk(char *buffer, unsigned long size, struct patch *patch)
1997
1998 prefix_patch(patch);
1999
2000 - patch->ws_rule = whitespace_rule(patch->new_name
2001 - ? patch->new_name
2002 - : patch->old_name);
2000 + if (!use_patch(patch))
2001 + patch->ws_rule = 0;
2002 + else
2003 + patch->ws_rule = whitespace_rule(patch->new_name
2004 + ? patch->new_name
2005 + : patch->old_name);
2006
2007 patchsize = parse_single_patch(buffer + offset + hdrsize,
2008 size - offset - hdrsize, patch);
t/t4124-apply-ws-rule.sh
+11
@@ -512,4 +512,15 @@ test_expect_success 'whitespace=fix to expand' '
512 git -c core.whitespace=tab-in-indent apply --whitespace=fix patch
513 '
514
515 +test_expect_success 'whitespace check skipped for excluded paths' '
516 + git config core.whitespace blank-at-eol &&
517 + >used &&
518 + >unused &&
519 + git add used unused &&
520 + echo "used" >used &&
521 + echo "unused " >unused &&
522 + git diff-files -p used unused >patch &&
523 + git apply --include=used --stat --whitespace=error <patch
524 +'
525 +
526 test_done