Skip to content

Commit 9dce832

Browse files
committed
add--interactive.perl: factor out repeated --recount option
Depending on the direction and the target of patch application, we would need to pass --cached and --reverse to underlying "git apply". Also we only pass --check when we are not applying but just checking. But we always pass --recount since 8cbd431 (git-add--interactive: replace hunk recounting with apply --recount, 2008-07-02). Instead of repeating the same --recount over and over again, move it to a single place that actually runs the command, namely, "run_git_apply" subroutine. Signed-off-by: Junio C Hamano <[email protected]>
1 parent f3217e2 commit 9dce832

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

git-add--interactive.perl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ sub add_untracked_cmd {
705705
sub run_git_apply {
706706
my $cmd = shift;
707707
my $fh;
708-
open $fh, '| git ' . $cmd;
708+
open $fh, '| git ' . $cmd . " --recount";
709709
print $fh @_;
710710
return close $fh;
711711
}
@@ -1050,7 +1050,7 @@ sub edit_hunk_manually {
10501050

10511051
sub diff_applies {
10521052
my $fh;
1053-
return run_git_apply($patch_mode_flavour{APPLY_CHECK} . ' --recount --check',
1053+
return run_git_apply($patch_mode_flavour{APPLY_CHECK} . ' --check',
10541054
map { @{$_->{TEXT}} } @_);
10551055
}
10561056

@@ -1139,7 +1139,7 @@ sub help_patch_cmd {
11391139

11401140
sub apply_patch {
11411141
my $cmd = shift;
1142-
my $ret = run_git_apply $cmd . ' --recount', @_;
1142+
my $ret = run_git_apply $cmd, @_;
11431143
if (!$ret) {
11441144
print STDERR @_;
11451145
}
@@ -1148,17 +1148,17 @@ sub apply_patch {
11481148

11491149
sub apply_patch_for_checkout_commit {
11501150
my $reverse = shift;
1151-
my $applies_index = run_git_apply 'apply '.$reverse.' --cached --recount --check', @_;
1152-
my $applies_worktree = run_git_apply 'apply '.$reverse.' --recount --check', @_;
1151+
my $applies_index = run_git_apply 'apply '.$reverse.' --cached --check', @_;
1152+
my $applies_worktree = run_git_apply 'apply '.$reverse.' --check', @_;
11531153

11541154
if ($applies_worktree && $applies_index) {
1155-
run_git_apply 'apply '.$reverse.' --cached --recount', @_;
1156-
run_git_apply 'apply '.$reverse.' --recount', @_;
1155+
run_git_apply 'apply '.$reverse.' --cached', @_;
1156+
run_git_apply 'apply '.$reverse, @_;
11571157
return 1;
11581158
} elsif (!$applies_index) {
11591159
print colored $error_color, "The selected hunks do not apply to the index!\n";
11601160
if (prompt_yesno "Apply them to the worktree anyway? ") {
1161-
return run_git_apply 'apply '.$reverse.' --recount', @_;
1161+
return run_git_apply 'apply '.$reverse, @_;
11621162
} else {
11631163
print colored $error_color, "Nothing was applied.\n";
11641164
return 0;

0 commit comments

Comments
 (0)