mirror of
https://github.com/git/git
synced 2024-11-05 18:59:29 +00:00
git-add--interactive: replace hunk recounting with apply --recount
We recounted the postimage offsets to compensate for hunks that were not selected. Now apply --recount can do the job for us. Signed-off-by: Thomas Rast <trast@student.ethz.ch> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
8cb560fc47
commit
8cbd431082
1 changed files with 3 additions and 27 deletions
|
@ -970,39 +970,15 @@ sub patch_update_file {
|
||||||
push @result, @{$mode->{TEXT}};
|
push @result, @{$mode->{TEXT}};
|
||||||
}
|
}
|
||||||
for (@hunk) {
|
for (@hunk) {
|
||||||
my $text = $_->{TEXT};
|
if ($_->{USE}) {
|
||||||
my ($o_ofs, $o_cnt, $n_ofs, $n_cnt) =
|
push @result, @{$_->{TEXT}};
|
||||||
parse_hunk_header($text->[0]);
|
|
||||||
|
|
||||||
if (!$_->{USE}) {
|
|
||||||
# We would have added ($n_cnt - $o_cnt) lines
|
|
||||||
# to the postimage if we were to use this hunk,
|
|
||||||
# but we didn't. So the line number that the next
|
|
||||||
# hunk starts at would be shifted by that much.
|
|
||||||
$n_lofs -= ($n_cnt - $o_cnt);
|
|
||||||
next;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if ($n_lofs) {
|
|
||||||
$n_ofs += $n_lofs;
|
|
||||||
$text->[0] = ("@@ -$o_ofs" .
|
|
||||||
(($o_cnt != 1)
|
|
||||||
? ",$o_cnt" : '') .
|
|
||||||
" +$n_ofs" .
|
|
||||||
(($n_cnt != 1)
|
|
||||||
? ",$n_cnt" : '') .
|
|
||||||
" @@\n");
|
|
||||||
}
|
|
||||||
for (@$text) {
|
|
||||||
push @result, $_;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (@result) {
|
if (@result) {
|
||||||
my $fh;
|
my $fh;
|
||||||
|
|
||||||
open $fh, '| git apply --cached';
|
open $fh, '| git apply --cached --recount';
|
||||||
for (@{$head->{TEXT}}, @result) {
|
for (@{$head->{TEXT}}, @result) {
|
||||||
print $fh $_;
|
print $fh $_;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue