Skip to content

Commit 477a08a

Browse files
committed
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 <[email protected]>
1 parent 3ee2ad1 commit 477a08a

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

builtin/apply.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1997,9 +1997,12 @@ static int parse_chunk(char *buffer, unsigned long size, struct patch *patch)
19971997

19981998
prefix_patch(patch);
19991999

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);
20032006

20042007
patchsize = parse_single_patch(buffer + offset + hdrsize,
20052008
size - offset - hdrsize, patch);

t/t4124-apply-ws-rule.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,4 +512,15 @@ test_expect_success 'whitespace=fix to expand' '
512512
git -c core.whitespace=tab-in-indent apply --whitespace=fix patch
513513
'
514514

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+
515526
test_done

0 commit comments

Comments
 (0)