@matheusbsbs / matheus-bagliano / commits / 0c3ef984fa
Fork 0

apply: Allow blank *trailing* context lines to match beyond EOF

In 51667147be, "git apply --whitespace=fix" was extended to allow a blank context line to match beyond the end of the file, but only if the context line was in the leading part of the hunk (i.e. the hunk inserted additional contents at the end of the file). Drop the restriction that the context line must be in the leading part of the hunk, thus allowing a file to be changed from: a (blank line) to: b a (blank line) Note that the blank line will be kept, because "--whitespace=fix" only removes trailing blank lines that a hunk would add, never trailing blank lines in the context. Signed-off-by: Björn Gustavsson <bgustavsson@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Björn Gustavsson committed Apr 8, 2010 at 06:14 UTC 0c3ef984fa2d4a42be787e168cfb189d15b00919
2 files changed +18 -6
builtin-apply.c
+6 -6
@@ -1864,13 +1864,13 @@ static int match_fragment(struct image *img,
1864 if (match_end && (preimage->nr + try_lno != img->nr))
1865 return 0;
1866 } else if (ws_error_action == correct_ws_error &&
1867 - (ws_rule & WS_BLANK_AT_EOF) && match_end) {
1867 + (ws_rule & WS_BLANK_AT_EOF)) {
1868 /*
1869 - * This hunk that matches at the end extends beyond
1870 - * the end of img, and we are removing blank lines
1871 - * at the end of the file. This many lines from the
1872 - * beginning of the preimage must match with img, and
1873 - * the remainder of the preimage must be blank.
1869 + * This hunk extends beyond the end of img, and we are
1870 + * removing blank lines at the end of the file. This
1871 + * many lines from the beginning of the preimage must
1872 + * match with img, and the remainder of the preimage
1873 + * must be blank.
1874 */
1875 preimage_limit = img->nr - try_lno;
1876 } else {
t/t4124-apply-ws-rule.sh
+12
@@ -325,6 +325,18 @@ test_expect_success 'two missing blank lines at end with --whitespace=fix' '
325 test_cmp one expect
326 '
327
328 +test_expect_success 'missing blank line at end, insert before end, --whitespace=fix' '
329 + { echo a; echo; } >one &&
330 + git add one &&
331 + { echo b; echo a; echo; } >one &&
332 + cp one expect &&
333 + git diff -- one >patch &&
334 + echo a >one &&
335 + test_must_fail git apply patch &&
336 + git apply --whitespace=fix patch &&
337 + test_cmp one expect
338 +'
339 +
340 test_expect_success 'shrink file with tons of missing blanks at end of file' '
341 { echo a; echo b; echo c; } >one &&
342 cp one no-blank-lines &&