apply --allow-overlap: fix a corner case
Yes, yes, this is supposed to be only a band-aid option for `git add -p` not Doing The Right Thing. But as long as we carry the `--allow-overlap` option, we might just as well get it right. This fixes the case where one hunk inserts a line before the first line, and is followed by a hunk whose context overlaps with the first one's and which appends a line at the end. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Johannes Schindelin committed
Dec 6, 2019 at 13:08 UTC
b4bbbbd5a247e0e75d079bca591b657ec9084a46
1 file changed
+10
apply.c
+10
@@ -2661,6 +2661,16 @@ static int find_pos(struct apply_state *state,
2661
unsigned long backwards, forwards, current;
2662
int backwards_lno, forwards_lno, current_lno;
2663
2664
+ /*
2665
+ * When running with --allow-overlap, it is possible that a hunk is
2666
+ * seen that pretends to start at the beginning (but no longer does),
2667
+ * and that *still* needs to match the end. So trust `match_end` more
2668
+ * than `match_beginning`.
2669
+ */
2670
+ if (state->allow_overlap && match_beginning && match_end &&
2671
+ img->nr - preimage->nr != 0)
2672
+ match_beginning = 0;
2673
+
2674
/*
2675
* If match_beginning or match_end is specified, there is no
2676
* point starting from a wrong line that will never match and