Skip to content

Commit 492e60c

Browse files
phillipwoodgitster
authored andcommitted
add -i: add function to format hunk header
This code is duplicated in a couple of places so make it into a function as we're going to add some more callers shortly. Signed-off-by: Phillip Wood <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8279ed0 commit 492e60c

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

git-add--interactive.perl

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,15 @@ sub parse_hunk_header {
751751
return ($o_ofs, $o_cnt, $n_ofs, $n_cnt);
752752
}
753753

754+
sub format_hunk_header {
755+
my ($o_ofs, $o_cnt, $n_ofs, $n_cnt) = @_;
756+
return ("@@ -$o_ofs" .
757+
(($o_cnt != 1) ? ",$o_cnt" : '') .
758+
" +$n_ofs" .
759+
(($n_cnt != 1) ? ",$n_cnt" : '') .
760+
" @@\n");
761+
}
762+
754763
sub split_hunk {
755764
my ($text, $display) = @_;
756765
my @split = ();
@@ -838,11 +847,7 @@ sub split_hunk {
838847
my $o_cnt = $hunk->{OCNT};
839848
my $n_cnt = $hunk->{NCNT};
840849

841-
my $head = ("@@ -$o_ofs" .
842-
(($o_cnt != 1) ? ",$o_cnt" : '') .
843-
" +$n_ofs" .
844-
(($n_cnt != 1) ? ",$n_cnt" : '') .
845-
" @@\n");
850+
my $head = format_hunk_header($o_ofs, $o_cnt, $n_ofs, $n_cnt);
846851
my $display_head = $head;
847852
unshift @{$hunk->{TEXT}}, $head;
848853
if ($diff_use_color) {
@@ -912,11 +917,7 @@ sub merge_hunk {
912917
}
913918
push @line, $line;
914919
}
915-
my $head = ("@@ -$o0_ofs" .
916-
(($o_cnt != 1) ? ",$o_cnt" : '') .
917-
" +$n0_ofs" .
918-
(($n_cnt != 1) ? ",$n_cnt" : '') .
919-
" @@\n");
920+
my $head = format_hunk_header($o0_ofs, $o_cnt, $n0_ofs, $n_cnt);
920921
@{$prev->{TEXT}} = ($head, @line);
921922
}
922923

0 commit comments

Comments
 (0)