@matheusbsbs / matheus-bagliano / commits / 9dce832354
Fork 0

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 <gitster@pobox.com>

Junio C Hamano committed Apr 6, 2011 at 14:12 UTC 9dce832354502a04e724c5776e60fc6189182307
1 file changed +8 -8
git-add--interactive.perl
+8 -8
@@ -705,7 +705,7 @@ sub add_untracked_cmd {
705 sub run_git_apply {
706 my $cmd = shift;
707 my $fh;
708 - open $fh, '| git ' . $cmd;
708 + open $fh, '| git ' . $cmd . " --recount";
709 print $fh @_;
710 return close $fh;
711 }
@@ -1050,7 +1050,7 @@ EOF
1050
1051 sub diff_applies {
1052 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',
1054 map { @{$_->{TEXT}} } @_);
1055 }
1056
@@ -1139,7 +1139,7 @@ EOF
1139
1140 sub apply_patch {
1141 my $cmd = shift;
1142 - my $ret = run_git_apply $cmd . ' --recount', @_;
1142 + my $ret = run_git_apply $cmd, @_;
1143 if (!$ret) {
1144 print STDERR @_;
1145 }
@@ -1148,17 +1148,17 @@ sub apply_patch {
1148
1149 sub apply_patch_for_checkout_commit {
1150 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', @_;
1153
1154 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, @_;
1157 return 1;
1158 } elsif (!$applies_index) {
1159 print colored $error_color, "The selected hunks do not apply to the index!\n";
1160 if (prompt_yesno "Apply them to the worktree anyway? ") {
1161 - return run_git_apply 'apply '.$reverse.' --recount', @_;
1161 + return run_git_apply 'apply '.$reverse, @_;
1162 } else {
1163 print colored $error_color, "Nothing was applied.\n";
1164 return 0;