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

[PATCH 1/2] add-interactive: handle unborn branch in patch mode

From
Jeff King <peff@peff.net>
Date
Oct 25, 2013, 06:52 UTC
Message-ID
<20131025065229.GA15253@sigill.intra.peff.net>
In-Reply-To
<20131025065117.GA15192@sigill.intra.peff.net>

The list_modified function already knows how to handle an unborn branch by diffing against the empty tree. However, the diff we perform to get the actual hunks does not. Let's use the same logic for both diffs.

Signed-off-by: Jeff King <peff@peff.net>
---
 git-add--interactive.perl | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)
diff --git a/git-add--interactive.perl b/git-add--interactive.perl
index 5156384..24bb1ab 100755
--- a/git-add--interactive.perl
+++ b/git-add--interactive.perl
@@ -263,6 +263,17 @@ sub get_empty_tree {
 	return '4b825dc642cb6eb9a060e54bf8d69288fbee4904';
 }
 
+sub get_diff_reference {
+	my $ref = shift;
+	if (defined $ref and $ref ne 'HEAD') {
+		return $ref;
+	} elsif (is_initial_commit()) {
+		return get_empty_tree();
+	} else {
+		return 'HEAD';
+	}
+}
+
 # Returns list of hashes, contents of each of which are:
 # VALUE:	pathname
 # BINARY:	is a binary path
@@ -286,14 +297,7 @@ sub list_modified {
 		return if (!@tracked);
 	}
 
-	my $reference;
-	if (defined $patch_mode_revision and $patch_mode_revision ne 'HEAD') {
-		$reference = $patch_mode_revision;
-	} elsif (is_initial_commit()) {
-		$reference = get_empty_tree();
-	} else {
-		$reference = 'HEAD';
-	}
+	my $reference = get_diff_reference($patch_mode_revision);
 	for (run_cmd_pipe(qw(git diff-index --cached
 			     --numstat --summary), $reference,
 			     '--', @tracked)) {
@@ -737,7 +741,7 @@ sub parse_diff {
 		splice @diff_cmd, 1, 0, "--diff-algorithm=${diff_algorithm}";
 	}
 	if (defined $patch_mode_revision) {
-		push @diff_cmd, $patch_mode_revision;
+		push @diff_cmd, get_diff_reference($patch_mode_revision);
 	}
 	my @diff = run_cmd_pipe("git", @diff_cmd, "--", $path);
 	my @colored = ();
-- 
1.8.4.1.898.g8bf8a41.dirty
Previous: Jeff KingNext: Jeff King
Message 7 of 9 in “Fwd: Bug report: reset -p HEAD”
  1. Maarten de VriesOct 24, 2013
  2. Maarten de VriesOct 24, 2013
  3. Re* Bug report: reset -p HEADJunio C Hamano, Oct 25, 2013
  4. Jeff KingOct 25, 2013
  5. Martin von ZweigbergkOct 25, 2013
  6. 0/2 reset -p and unborn branchesJeff King, Oct 25, 2013
  7. 1/2 add-interactive: handle unborn branch in patch modeJeff King, Oct 25, 2013
  8. 2/2 reset: pass real rev name to add--interactiveJeff King, Oct 25, 2013
  9. Junio C HamanoOct 25, 2013

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.