diff options
author | Junio C Hamano <gitster@pobox.com> | 2013-03-22 11:10:03 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2013-03-22 11:16:01 -0700 |
commit | 250b3c6c992b3cb04e756eb33bed99442fc55193 (patch) | |
tree | 83e7a3f5b95a391d43c381e5a117ad768bf84e41 /t/t4124-apply-ws-rule.sh | |
parent | 15999998fbda60552742275570947431b57108ae (diff) | |
download | git-250b3c6c992b3cb04e756eb33bed99442fc55193.tar.gz git-250b3c6c992b3cb04e756eb33bed99442fc55193.tar.xz |
apply --whitespace=fix: avoid running over the postimage buffer
Originally update-pre-post-images could assume that any whitespace
fixing will make the result only shorter by unexpanding runs of
leading SPs into HTs and removing trailing whitespaces at the end of
lines. Updating the post-image we read from the patch to match the
actual result can be performed in-place under this assumption.
These days, however, we have tab-in-indent (aka Python) rule whose
result can be longer than the original, and we do need to allocate
a larger buffer than the input and replace the result.
Fortunately the support for lengthening rewrite was already added
when we began supporting "match while ignoring whitespace
differences" mode in 86c91f91794c (git apply: option to ignore
whitespace differences, 2009-08-04). We only need to correctly
count the number of bytes necessary to hold the updated result and
tell the function to allocate a new buffer.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/t4124-apply-ws-rule.sh')
-rwxr-xr-x | t/t4124-apply-ws-rule.sh | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/t/t4124-apply-ws-rule.sh b/t/t4124-apply-ws-rule.sh index 6f6ee88b2..0bbcf0603 100755 --- a/t/t4124-apply-ws-rule.sh +++ b/t/t4124-apply-ws-rule.sh @@ -486,4 +486,30 @@ test_expect_success 'same, but with CR-LF line endings && cr-at-eol unset' ' test_cmp one expect ' +test_expect_success 'whitespace=fix to expand' ' + qz_to_tab_space >preimage <<-\EOF && + QQa + QQb + QQc + ZZZZZZZZZZZZZZZZd + QQe + QQf + QQg + EOF + qz_to_tab_space >patch <<-\EOF && + diff --git a/preimage b/preimage + --- a/preimage + +++ b/preimage + @@ -1,7 +1,6 @@ + QQa + QQb + QQc + -QQd + QQe + QQf + QQg + EOF + git -c core.whitespace=tab-in-indent apply --whitespace=fix patch +' + test_done |