@matheusbsbs / matheus-bagliano / commits / 933e44d3a0
Fork 0

"add -p": work-around an old laziness that does not coalesce hunks

Since 0beee4c (git-add--interactive: remove hunk coalescing, 2008-07-02), "git add--interactive" behaves lazily and passes overlapping hunks to the underlying "git apply" without coalescing. This was partially corrected by 7a26e65 (its partial revert, 2009-05-16), but overlapping hunks are still passed when the patch is edited. Teach "git apply" the --allow-overlap option that disables a safety feature that avoids misapplication of patches by not applying patches to overlapping hunks, and pass this option form "add -p" codepath. Do not even advertise the option, as this is merely a workaround, and the correct fix is to make "add -p" correctly coalesce adjacent patch hunks. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Apr 6, 2011 at 14:20 UTC 933e44d3a040c41a1e45d53a416edd107cc3ae0a
2 files changed +7 -4
builtin/apply.c
+6 -3
@@ -43,6 +43,7 @@ static int apply = 1;
43 static int apply_in_reverse;
44 static int apply_with_reject;
45 static int apply_verbosely;
46 +static int allow_overlap;
47 static int no_add;
48 static const char *fake_ancestor;
49 static int line_termination = '\n';
@@ -2430,9 +2431,9 @@ static void update_image(struct image *img,
2431 memcpy(img->line + applied_pos,
2432 postimage->line,
2433 postimage->nr * sizeof(*img->line));
2433 - for (i = 0; i < postimage->nr; i++)
2434 - img->line[applied_pos + i].flag |= LINE_PATCHED;
2435 -
2434 + if (!allow_overlap)
2435 + for (i = 0; i < postimage->nr; i++)
2436 + img->line[applied_pos + i].flag |= LINE_PATCHED;
2437 img->nr = nr;
2438 }
2439
@@ -3877,6 +3878,8 @@ int cmd_apply(int argc, const char **argv, const char *prefix_)
3878 "don't expect at least one line of context"),
3879 OPT_BOOLEAN(0, "reject", &apply_with_reject,
3880 "leave the rejected hunks in corresponding *.rej files"),
3881 + OPT_BOOLEAN(0, "allow-overlap", &allow_overlap,
3882 + "allow overlapping hunks"),
3883 OPT__VERBOSE(&apply_verbosely, "be verbose"),
3884 OPT_BIT(0, "inaccurate-eof", &options,
3885 "tolerate incorrectly detected missing new-line at the end of file",
git-add--interactive.perl
+1 -1
@@ -705,7 +705,7 @@ sub add_untracked_cmd {
705 sub run_git_apply {
706 my $cmd = shift;
707 my $fh;
708 - open $fh, '| git ' . $cmd . " --recount";
708 + open $fh, '| git ' . $cmd . " --recount --allow-overlap";
709 print $fh @_;
710 return close $fh;
711 }