git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] add--interactive.perl: factor out repeated --recount option

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 6, 2011, 21:31 UTC
Message-ID
<7vy63ngj7a.fsf_-_@alter.siamese.dyndns.org>
In-Reply-To
<7v4o6bi1lm.fsf_-_@alter.siamese.dyndns.org>

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>
---
 * Applies on top of 9d15860.  I tried to be careful but may have missed
   some calls.  Extra set of eyeballs appreciated.
 git-add--interactive.perl |   16 ++++++++--------
 1 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/git-add--interactive.perl b/git-add--interactive.perl
index a329c5a..6a439db 100755
--- a/git-add--interactive.perl
+++ b/git-add--interactive.perl
@@ -705,7 +705,7 @@ sub add_untracked_cmd {
 sub run_git_apply {
 	my $cmd = shift;
 	my $fh;
-	open $fh, '| git ' . $cmd;
+	open $fh, '| git ' . $cmd . " --recount";
 	print $fh @_;
 	return close $fh;
 }
@@ -1050,7 +1050,7 @@ sub edit_hunk_manually {
 
 sub diff_applies {
 	my $fh;
-	return run_git_apply($patch_mode_flavour{APPLY_CHECK} . ' --recount --check',
+	return run_git_apply($patch_mode_flavour{APPLY_CHECK} . ' --check',
 			     map { @{$_->{TEXT}} } @_);
 }
 
@@ -1139,7 +1139,7 @@ sub help_patch_cmd {
 
 sub apply_patch {
 	my $cmd = shift;
-	my $ret = run_git_apply $cmd . ' --recount', @_;
+	my $ret = run_git_apply $cmd, @_;
 	if (!$ret) {
 		print STDERR @_;
 	}
@@ -1148,17 +1148,17 @@ sub apply_patch {
 
 sub apply_patch_for_checkout_commit {
 	my $reverse = shift;
-	my $applies_index = run_git_apply 'apply '.$reverse.' --cached --recount --check', @_;
-	my $applies_worktree = run_git_apply 'apply '.$reverse.' --recount --check', @_;
+	my $applies_index = run_git_apply 'apply '.$reverse.' --cached --check', @_;
+	my $applies_worktree = run_git_apply 'apply '.$reverse.' --check', @_;
 
 	if ($applies_worktree && $applies_index) {
-		run_git_apply 'apply '.$reverse.' --cached --recount', @_;
-		run_git_apply 'apply '.$reverse.' --recount', @_;
+		run_git_apply 'apply '.$reverse.' --cached', @_;
+		run_git_apply 'apply '.$reverse, @_;
 		return 1;
 	} elsif (!$applies_index) {
 		print colored $error_color, "The selected hunks do not apply to the index!\n";
 		if (prompt_yesno "Apply them to the worktree anyway? ") {
-			return run_git_apply 'apply '.$reverse.' --recount', @_;
+			return run_git_apply 'apply '.$reverse, @_;
 		} else {
 			print colored $error_color, "Nothing was applied.\n";
 			return 0;
-- 
1.7.5.rc1
Previous: Junio C HamanoNext: Junio C Hamano
Message 5 of 6 in “[ANNOUNCE] Git 1.7.4.3”
  1. Junio C HamanoApr 3, 2011
  2. Arnaud LacombeApr 6, 2011
  3. Junio C HamanoApr 6, 2011
  4. "add -p" breakageJunio C Hamano, Apr 6, 2011
  5. add--interactive.perl: factor out repeated --recount optionJunio C Hamano, Apr 6, 2011
  6. "add -p": work-around an old laziness that does not coalesce hunksJunio C Hamano, Apr 6, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.