Skip to content

Commit 8cbd431

Browse files
trastgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8cb560f commit 8cbd431

File tree

1 file changed

+3
-27
lines changed

1 file changed

+3
-27
lines changed

git-add--interactive.perl

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -970,39 +970,15 @@ sub patch_update_file {
970970
push @result, @{$mode->{TEXT}};
971971
}
972972
for (@hunk) {
973-
my $text = $_->{TEXT};
974-
my ($o_ofs, $o_cnt, $n_ofs, $n_cnt) =
975-
parse_hunk_header($text->[0]);
976-
977-
if (!$_->{USE}) {
978-
# We would have added ($n_cnt - $o_cnt) lines
979-
# to the postimage if we were to use this hunk,
980-
# but we didn't. So the line number that the next
981-
# hunk starts at would be shifted by that much.
982-
$n_lofs -= ($n_cnt - $o_cnt);
983-
next;
984-
}
985-
else {
986-
if ($n_lofs) {
987-
$n_ofs += $n_lofs;
988-
$text->[0] = ("@@ -$o_ofs" .
989-
(($o_cnt != 1)
990-
? ",$o_cnt" : '') .
991-
" +$n_ofs" .
992-
(($n_cnt != 1)
993-
? ",$n_cnt" : '') .
994-
" @@\n");
995-
}
996-
for (@$text) {
997-
push @result, $_;
998-
}
973+
if ($_->{USE}) {
974+
push @result, @{$_->{TEXT}};
999975
}
1000976
}
1001977

1002978
if (@result) {
1003979
my $fh;
1004980

1005-
open $fh, '| git apply --cached';
981+
open $fh, '| git apply --cached --recount';
1006982
for (@{$head->{TEXT}}, @result) {
1007983
print $fh $_;
1008984
}

0 commit comments

Comments
 (0)