@matheusbsbs / matheus-bagliano / commits / 8cbd431082
Fork 0

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>

Thomas Rast committed Jul 2, 2008 at 23:59 UTC 8cbd4310821ea2957d32a36c34fa314cf99ca9f3
1 file changed +3 -27
git-add--interactive.perl
+3 -27
@@ -970,39 +970,15 @@ sub patch_update_file {
970 push @result, @{$mode->{TEXT}};
971 }
972 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}};
975 }
976 }
977
978 if (@result) {
979 my $fh;
980
1005 - open $fh, '| git apply --cached';
981 + open $fh, '| git apply --cached --recount';
982 for (@{$head->{TEXT}}, @result) {
983 print $fh $_;
984 }