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

[PATCH 1/2] git-svn: ignore changeless commits when checking for a cherry-pick

From
Andrew Myrick <amyrick@apple.com>
Date
Jan 7, 2010, 00:25 UTC
Message-ID
<1262823922-3415-1-git-send-email-amyrick@apple.com>
In-Reply-To
<E10FB265-0C47-44C7-9347-687A9F447603@apple.com>

Update git-svn to ignore commits that do not change the tree when it is deciding if an svn merge ticket represents a real branch merge or just a cherry-pick.

Consider the following integration model in the svn repository:
   F---G  branch1
  /     \
 D  tag1 \   E  tag2
/         \ /
A---B      C  trunk
branch1 is merged to trunk in commit C.

With this patch, git-svn will correctly identify branch1 as a proper merge parent, instead of incorrectly ignoring it as a cherry-pick.

Signed-off-by: Andrew Myrick <amyrick@apple.com>
---
 git-svn.perl |   24 ++++++++++++++++++++++++
 1 files changed, 24 insertions(+), 0 deletions(-)
diff --git a/git-svn.perl b/git-svn.perl
index 650c9e5..947184a 100755
--- a/git-svn.perl
+++ b/git-svn.perl
@@ -3052,12 +3052,36 @@ sub check_cherry_pick {
 	for my $range ( @ranges ) {
 		delete @commits{_rev_list($range)};
 	}
+	for my $commit (keys %commits) {
+		if (has_no_changes($commit)) {
+			delete $commits{$commit};
+		}
+	}
 	return (keys %commits);
 }
 
+sub has_no_changes {
+	my $commit = shift;
+
+	my @revs = split / /, command_oneline(
+		qw(rev-list --parents -1 -m), $commit);
+
+	# Commits with no parents, e.g. the start of a partial branch,
+	# have changes by definition.
+	return 1 if (@revs < 2);
+
+	# Commits with multiple parents, e.g a merge, have no changes
+	# by definition.
+	return 0 if (@revs > 2);
+
+	return (command_oneline("rev-parse", "$commit^{tree}") eq
+		command_oneline("rev-parse", "$commit~1^{tree}"));
+}
+
 BEGIN {
 	memoize 'lookup_svn_merge';
 	memoize 'check_cherry_pick';
+	memoize 'has_no_changes';
 }
 
 sub parents_exclude {
-- 
1.6.6.2.g18c9a
Previous: Andrew MyrickNext: Andrew Myrick
Message 8 of 11 in “git-svn: ignore changeless commits when checking for a cherry-pick”
  1. 1/2 git-svn: ignore changeless commits when checking for a cherry-pickAndrew Myrick, Jan 6, 2010
  2. 2/2 git-svn: handle merge-base failuresAndrew Myrick, Jan 6, 2010
  3. Eric WongJan 6, 2010
  4. Sam VilainJan 6, 2010
  5. Eric WongJan 7, 2010
  6. Sam VilainJan 7, 2010
  7. Andrew MyrickJan 6, 2010
  8. 1/2 git-svn: ignore changeless commits when checking for a cherry-pickAndrew Myrick, Jan 7, 2010
  9. 2/2 git-svn: handle merge-base failuresAndrew Myrick, Jan 7, 2010
  10. Eric WongJan 7, 2010
  11. git-svn: update svn mergeinfo test suiteAndrew Myrick, Jan 21, 2010

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.