Skip to content

Commit 0beee4c

Browse files
trastgitster
authored andcommitted
git-add--interactive: remove hunk coalescing
Current git-apply has no trouble at all applying chunks that have overlapping context, as produced by the splitting feature. So we can drop the manual coalescing. Signed-off-by: Thomas Rast <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8cbd431 commit 0beee4c

File tree

1 file changed

+0
-89
lines changed

1 file changed

+0
-89
lines changed

git-add--interactive.perl

Lines changed: 0 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -682,93 +682,6 @@ sub split_hunk {
682682
return @split;
683683
}
684684

685-
sub find_last_o_ctx {
686-
my ($it) = @_;
687-
my $text = $it->{TEXT};
688-
my ($o_ofs, $o_cnt) = parse_hunk_header($text->[0]);
689-
my $i = @{$text};
690-
my $last_o_ctx = $o_ofs + $o_cnt;
691-
while (0 < --$i) {
692-
my $line = $text->[$i];
693-
if ($line =~ /^ /) {
694-
$last_o_ctx--;
695-
next;
696-
}
697-
last;
698-
}
699-
return $last_o_ctx;
700-
}
701-
702-
sub merge_hunk {
703-
my ($prev, $this) = @_;
704-
my ($o0_ofs, $o0_cnt, $n0_ofs, $n0_cnt) =
705-
parse_hunk_header($prev->{TEXT}[0]);
706-
my ($o1_ofs, $o1_cnt, $n1_ofs, $n1_cnt) =
707-
parse_hunk_header($this->{TEXT}[0]);
708-
709-
my (@line, $i, $ofs, $o_cnt, $n_cnt);
710-
$ofs = $o0_ofs;
711-
$o_cnt = $n_cnt = 0;
712-
for ($i = 1; $i < @{$prev->{TEXT}}; $i++) {
713-
my $line = $prev->{TEXT}[$i];
714-
if ($line =~ /^\+/) {
715-
$n_cnt++;
716-
push @line, $line;
717-
next;
718-
}
719-
720-
last if ($o1_ofs <= $ofs);
721-
722-
$o_cnt++;
723-
$ofs++;
724-
if ($line =~ /^ /) {
725-
$n_cnt++;
726-
}
727-
push @line, $line;
728-
}
729-
730-
for ($i = 1; $i < @{$this->{TEXT}}; $i++) {
731-
my $line = $this->{TEXT}[$i];
732-
if ($line =~ /^\+/) {
733-
$n_cnt++;
734-
push @line, $line;
735-
next;
736-
}
737-
$ofs++;
738-
$o_cnt++;
739-
if ($line =~ /^ /) {
740-
$n_cnt++;
741-
}
742-
push @line, $line;
743-
}
744-
my $head = ("@@ -$o0_ofs" .
745-
(($o_cnt != 1) ? ",$o_cnt" : '') .
746-
" +$n0_ofs" .
747-
(($n_cnt != 1) ? ",$n_cnt" : '') .
748-
" @@\n");
749-
@{$prev->{TEXT}} = ($head, @line);
750-
}
751-
752-
sub coalesce_overlapping_hunks {
753-
my (@in) = @_;
754-
my @out = ();
755-
756-
my ($last_o_ctx);
757-
758-
for (grep { $_->{USE} } @in) {
759-
my $text = $_->{TEXT};
760-
my ($o_ofs) = parse_hunk_header($text->[0]);
761-
if (defined $last_o_ctx &&
762-
$o_ofs <= $last_o_ctx) {
763-
merge_hunk($out[-1], $_);
764-
}
765-
else {
766-
push @out, $_;
767-
}
768-
$last_o_ctx = find_last_o_ctx($out[-1]);
769-
}
770-
return @out;
771-
}
772685

773686
sub help_patch_cmd {
774687
print colored $help_color, <<\EOF ;
@@ -962,8 +875,6 @@ sub patch_update_file {
962875
}
963876
}
964877

965-
@hunk = coalesce_overlapping_hunks(@hunk);
966-
967878
my $n_lofs = 0;
968879
my @result = ();
969880
if ($mode->{USE}) {

0 commit comments

Comments
 (0)