mirror of
https://github.com/git/git
synced 2024-08-27 19:49:21 +00:00
Merge branch 'jc/apply-ws-fix-tab-in-indent' into maint
* jc/apply-ws-fix-tab-in-indent: test: resurrect q_to_tab apply --whitespace=fix: avoid running over the postimage buffer
This commit is contained in:
commit
21247455f3
|
@ -2117,10 +2117,10 @@ static void update_pre_post_images(struct image *preimage,
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Adjust the common context lines in postimage. This can be
|
* Adjust the common context lines in postimage. This can be
|
||||||
* done in-place when we are just doing whitespace fixing,
|
* done in-place when we are shrinking it with whitespace
|
||||||
* which does not make the string grow, but needs a new buffer
|
* fixing, but needs a new buffer when ignoring whitespace or
|
||||||
* when ignoring whitespace causes the update, since in this case
|
* expanding leading tabs to spaces.
|
||||||
* we could have e.g. tabs converted to multiple spaces.
|
*
|
||||||
* We trust the caller to tell us if the update can be done
|
* We trust the caller to tell us if the update can be done
|
||||||
* in place (postlen==0) or not.
|
* in place (postlen==0) or not.
|
||||||
*/
|
*/
|
||||||
|
@ -2185,7 +2185,7 @@ static int match_fragment(struct image *img,
|
||||||
int i;
|
int i;
|
||||||
char *fixed_buf, *buf, *orig, *target;
|
char *fixed_buf, *buf, *orig, *target;
|
||||||
struct strbuf fixed;
|
struct strbuf fixed;
|
||||||
size_t fixed_len;
|
size_t fixed_len, postlen;
|
||||||
int preimage_limit;
|
int preimage_limit;
|
||||||
|
|
||||||
if (preimage->nr + try_lno <= img->nr) {
|
if (preimage->nr + try_lno <= img->nr) {
|
||||||
|
@ -2335,6 +2335,7 @@ static int match_fragment(struct image *img,
|
||||||
strbuf_init(&fixed, preimage->len + 1);
|
strbuf_init(&fixed, preimage->len + 1);
|
||||||
orig = preimage->buf;
|
orig = preimage->buf;
|
||||||
target = img->buf + try;
|
target = img->buf + try;
|
||||||
|
postlen = 0;
|
||||||
for (i = 0; i < preimage_limit; i++) {
|
for (i = 0; i < preimage_limit; i++) {
|
||||||
size_t oldlen = preimage->line[i].len;
|
size_t oldlen = preimage->line[i].len;
|
||||||
size_t tgtlen = img->line[try_lno + i].len;
|
size_t tgtlen = img->line[try_lno + i].len;
|
||||||
|
@ -2362,6 +2363,7 @@ static int match_fragment(struct image *img,
|
||||||
match = (tgtfix.len == fixed.len - fixstart &&
|
match = (tgtfix.len == fixed.len - fixstart &&
|
||||||
!memcmp(tgtfix.buf, fixed.buf + fixstart,
|
!memcmp(tgtfix.buf, fixed.buf + fixstart,
|
||||||
fixed.len - fixstart));
|
fixed.len - fixstart));
|
||||||
|
postlen += tgtfix.len;
|
||||||
|
|
||||||
strbuf_release(&tgtfix);
|
strbuf_release(&tgtfix);
|
||||||
if (!match)
|
if (!match)
|
||||||
|
@ -2399,8 +2401,10 @@ static int match_fragment(struct image *img,
|
||||||
* hunk match. Update the context lines in the postimage.
|
* hunk match. Update the context lines in the postimage.
|
||||||
*/
|
*/
|
||||||
fixed_buf = strbuf_detach(&fixed, &fixed_len);
|
fixed_buf = strbuf_detach(&fixed, &fixed_len);
|
||||||
|
if (postlen < postimage->len)
|
||||||
|
postlen = 0;
|
||||||
update_pre_post_images(preimage, postimage,
|
update_pre_post_images(preimage, postimage,
|
||||||
fixed_buf, fixed_len, 0);
|
fixed_buf, fixed_len, postlen);
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
unmatch_exit:
|
unmatch_exit:
|
||||||
|
|
|
@ -486,4 +486,30 @@ test_expect_success 'same, but with CR-LF line endings && cr-at-eol unset' '
|
||||||
test_cmp one expect
|
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
|
test_done
|
||||||
|
|
|
@ -17,7 +17,7 @@ test_expect_success 'setup: messages' '
|
||||||
vero eos et accusam et justo duo dolores et ea rebum.
|
vero eos et accusam et justo duo dolores et ea rebum.
|
||||||
|
|
||||||
EOF
|
EOF
|
||||||
q_to_tab <<-\EOF >>msg &&
|
qz_to_tab_space <<-\EOF >>msg &&
|
||||||
QDuis autem vel eum iriure dolor in hendrerit in vulputate velit
|
QDuis autem vel eum iriure dolor in hendrerit in vulputate velit
|
||||||
Qesse molestie consequat, vel illum dolore eu feugiat nulla facilisis
|
Qesse molestie consequat, vel illum dolore eu feugiat nulla facilisis
|
||||||
Qat vero eros et accumsan et iusto odio dignissim qui blandit
|
Qat vero eros et accumsan et iusto odio dignissim qui blandit
|
||||||
|
|
|
@ -91,6 +91,10 @@ q_to_tab () {
|
||||||
tr Q '\011'
|
tr Q '\011'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
qz_to_tab_space () {
|
||||||
|
tr QZ '\011\040'
|
||||||
|
}
|
||||||
|
|
||||||
append_cr () {
|
append_cr () {
|
||||||
sed -e 's/$/Q/' | tr Q '\015'
|
sed -e 's/$/Q/' | tr Q '\015'
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue