mirror of
https://github.com/git/git.git
synced 2024-12-18 06:14:59 +08:00
"add -p": work-around an old laziness that does not coalesce hunks
Since0beee4c
(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 by7a26e65
(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>
This commit is contained in:
parent
9dce832354
commit
933e44d3a0
@ -43,6 +43,7 @@ static int apply = 1;
|
||||
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';
|
||||
@ -2430,9 +2431,9 @@ static void update_image(struct image *img,
|
||||
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;
|
||||
}
|
||||
|
||||
@ -3877,6 +3878,8 @@ int cmd_apply(int argc, const char **argv, const char *prefix_)
|
||||
"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",
|
||||
|
@ -705,7 +705,7 @@ sub add_untracked_cmd {
|
||||
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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user