summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 9dce832)
raw | patch | inline | side by side (parent: 9dce832)
author | Junio C Hamano <gitster@pobox.com> | |
Wed, 6 Apr 2011 21:20:57 +0000 (14:20 -0700) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Fri, 29 Apr 2011 22:27:59 +0000 (15:27 -0700) |
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>
"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>
builtin/apply.c | patch | blob | history | |
git-add--interactive.perl | patch | blob | history |
diff --git a/builtin/apply.c b/builtin/apply.c
index 04f56f850a430cc0f132b6ad38018760eb68a77b..8be1ce539c7282db2376925a0bb6be7bad5fcfe4 100644 (file)
--- a/builtin/apply.c
+++ b/builtin/apply.c
static int apply_in_reverse;
static int apply_with_reject;
static int apply_verbosely;
+static int allow_overlap;
static int no_add;
static const char *fake_ancestor;
static int line_termination = '\n';
memcpy(img->line + applied_pos,
postimage->line,
postimage->nr * sizeof(*img->line));
- for (i = 0; i < postimage->nr; i++)
- img->line[applied_pos + i].flag |= LINE_PATCHED;
-
+ if (!allow_overlap)
+ for (i = 0; i < postimage->nr; i++)
+ img->line[applied_pos + i].flag |= LINE_PATCHED;
img->nr = nr;
}
"don't expect at least one line of context"),
OPT_BOOLEAN(0, "reject", &apply_with_reject,
"leave the rejected hunks in corresponding *.rej files"),
+ OPT_BOOLEAN(0, "allow-overlap", &allow_overlap,
+ "allow overlapping hunks"),
OPT__VERBOSE(&apply_verbosely, "be verbose"),
OPT_BIT(0, "inaccurate-eof", &options,
"tolerate incorrectly detected missing new-line at the end of file",
index fced0ce8eceb1d062c23bbf6b7ab8091907fdbe6..4f08fe704bbaff64613ab07630a71da8bf8bbca0 100755 (executable)
sub run_git_apply {
my $cmd = shift;
my $fh;
- open $fh, '| git ' . $cmd . " --recount";
+ open $fh, '| git ' . $cmd . " --recount --allow-overlap";
print $fh @_;
return close $fh;
}