Skip to contentSkip to conversation

git-svn: ignore changeless commits when checking for a cherry-pick

PATCH In review Andrew Myrick 3 participants 11 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

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

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.

---
 git-svn.perl |   24 ++++++++++++++++++++++++
 1 files changed, 24 insertions(+), 0 deletions(-)
git-svn.perl +24 -0
index 650c9e5..8c7c034 100755
@@ -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 {
Signature · 1 line
1.6.6.2.g18c9a
#1 lore raw

PATCH 2/2 git-svn: handle merge-base failures

Change git-svn to warn and continue when merge-base fails while processing svn merge tickets.

merge-base can fail when a partial branch is created and merged back to trunk in svn, because it cannot find a common ancestor between the partial branch and trunk.

---
 git-svn.perl |   19 +++++++++++++++----
 1 files changed, 15 insertions(+), 4 deletions(-)
git-svn.perl +15 -4
index 8c7c034..d58982b 100755
@@ -3158,10 +3158,21 @@ sub find_extra_svn_parents {
 		my $ranges = $ranges{$merge_tip};
 
 		# check out 'new' tips
-		my $merge_base = command_oneline(
-			"merge-base",
-			@$parents, $merge_tip,
-		       );
+                my $merge_base;
+                eval {
+                        $merge_base = command_oneline(
+                                "merge-base",
+                                @$parents, $merge_tip,
+                               );
+                };
+                if ($@) {
+                        die "An error occurred during merge-base"
+                            unless $@->isa("Git::Error::Command");
+
+                        warn "W: Cannot find common ancestor between ".
+                            "@$parents and $merge_tip. Ignoring merge info.\n";
+                        next;
+                }
 
 		# double check that there are no missing non-merge commits
 		my (@incomplete) = check_cherry_pick(
Signature · 1 line
1.6.6.2.g18c9a
#2 lore raw
In reply to Andrew Myrick

git-svn.perl sub check_cherry_pick { · line 3055

Quoted 9 lines · Andrew Myrick
git-svn.perl +1 -0
index 650c9e5..8c7c034 100755
@@ -3052,12 +3052,36 @@ sub check_cherry_pick {
 	for my $range ( @ranges ) {
 		delete @commits{_rev_list($range)};
 	}
+        for my $commit (keys %commits) {

Hi Andrew,

I'll again defer to Sam for Acks on these. Test cases would be nice to have, too.

A few notes:

The prevailing standard for indentation in git is with hard tabs and that's certainly the case with the rest of git-svn.perl.

git-svn.perl sub check_cherry_pick { · line 3072

Quoted 10 lines
git-svn.perl +10 -0
+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);
+    

I've become very picky about trailing whitespace (from Junio :), too. "git diff --check" is helpful for this, especially in the pre-commit hook.

Thanks!

Signature · 1 line
Eric Wong
#3 lore raw
Quoted 15 lines · Eric Wong

git-svn.perl sub check_cherry_pick { · line 3056

Quoted 10 lines · Andrew Myrick
git-svn.perl +1 -0
index 650c9e5..8c7c034 100755
@@ -3052,12 +3052,36 @@ sub check_cherry_pick {
 	for my $range ( @ranges ) {
 		delete @commits{_rev_list($range)};
 	}
+        for my $commit (keys %commits) {
 

Hi Andrew,

Quoted 3 lines

I'll again defer to Sam for Acks on these. Test cases would be nice to have, too.

They look fine to me, agreed a test case would be nice and make sure the features aren't lost later inadvertently.

Thanks Andrew,
Sam

#4 lore raw
Quoted 7 lines · Sam Vilain
Quoted 6 lines · Eric Wong

git-svn.perl

Quoted 1 line · Andrew Myrick
git-svn.perl +0 -0

Hi Andrew,

Quoted 6 lines
Quoted 3 lines

I'll again defer to Sam for Acks on these. Test cases would be nice to have, too.

They look fine to me, agreed a test case would be nice and make sure the features aren't lost later inadvertently.

Thanks Sam,

Shall I consider this an Ack and push Andrew's new changes up while waiting for test cases?

Signature · 1 line
Eric Wong
#5 lore raw
Quoted 12 lines · Eric Wong
Quoted 11 lines · Sam Vilain
Quoted 9 lines · Eric Wong

git-svn.perl

Quoted 1 line · Andrew Myrick
git-svn.perl +0 -0

Hi Andrew,

I'll again defer to Sam for Acks on these. Test cases would be nice to have, too.

Quoted 7 lines
Quoted 2 lines

They look fine to me, agreed a test case would be nice and make sure the features aren't lost later inadvertently.

Thanks Sam,

Shall I consider this an Ack and push Andrew's new changes up while waiting for test cases?

Sure, the intent looks fine and given that Andrew has likely been using it a lot it's probably right. So yes, that's an ack. Hopefully I'll find time to push along some tests soon.

Cheers,
Sam

#6 lore raw
In reply to Eric Wong
Quoted 13 lines · Eric Wong

git-svn.perl sub check_cherry_pick { · line 3055

Quoted 9 lines · Andrew Myrick
git-svn.perl +1 -0
index 650c9e5..8c7c034 100755
@@ -3052,12 +3052,36 @@ sub check_cherry_pick {
 	for my $range ( @ranges ) {
 		delete @commits{_rev_list($range)};
 	}
+        for my $commit (keys %commits) {

Hi Andrew,

Quoted 2 lines

I'll again defer to Sam for Acks on these. Test cases would be nice to have, too.

I'll see what I can do. The test cases are conceptually simple (the svn dump I sent out the other day will exercise one of these patches), but it will take me some time to learn git's testing infrastructure, and I have impending deadlines on other work, so I can't promise anything immediate.

Quoted 6 lines

A few notes:

The prevailing standard for indentation in git is with hard tabs and that's certainly the case with the rest of git-svn.perl.

Quoted 14 lines

git-svn.perl sub check_cherry_pick { · line 3072

Quoted 10 lines
git-svn.perl +10 -0
+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);
+    

I've become very picky about trailing whitespace (from Junio :), too. "git diff --check" is helpful for this, especially in the pre-commit hook.

My apologies for not noticing this. I'll regenerate patches that conform to the style guidelines. Thanks for pointing out git diff --check; it's quite helpful.

-Andrew

#7 lore raw

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

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.

---
 git-svn.perl |   24 ++++++++++++++++++++++++
 1 files changed, 24 insertions(+), 0 deletions(-)
git-svn.perl +24 -0
index 650c9e5..947184a 100755
@@ -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 {
Signature · 1 line
1.6.6.2.g18c9a
#8 lore raw

PATCH 2/2 git-svn: handle merge-base failures

Change git-svn to warn and continue when merge-base fails while processing svn merge tickets.

merge-base can fail when a partial branch is created and merged back to trunk in svn, because it cannot find a common ancestor between the partial branch and trunk.

---
 git-svn.perl |   19 +++++++++++++++----
 1 files changed, 15 insertions(+), 4 deletions(-)
git-svn.perl +15 -4
index 947184a..1f201e4 100755
@@ -3158,10 +3158,21 @@ sub find_extra_svn_parents {
 		my $ranges = $ranges{$merge_tip};
 
 		# check out 'new' tips
-		my $merge_base = command_oneline(
-			"merge-base",
-			@$parents, $merge_tip,
-		       );
+		my $merge_base;
+		eval {
+			$merge_base = command_oneline(
+				"merge-base",
+				@$parents, $merge_tip,
+			);
+		};
+		if ($@) {
+			die "An error occurred during merge-base"
+				unless $@->isa("Git::Error::Command");
+
+			warn "W: Cannot find common ancestor between ".
+				"@$parents and $merge_tip. Ignoring merge info.\n";
+			next;
+		}
 
 		# double check that there are no missing non-merge commits
 		my (@incomplete) = check_cherry_pick(
Signature · 1 line
1.6.6.2.g18c9a
#9 lore raw
In reply to Andrew Myrick
Quoted 12 lines · Andrew Myrick

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

Quoted 7 lines

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.

---

Thanks Andrew,

I've added Acks for Sam and myself for this series and pushed out to
git://git.bogomips.org/git-svn:

Andrew Myrick (2):
git-svn: ignore changeless commits when checking for a cherry-pick
git-svn: handle merge-base failures

Signature · 1 line
Eric Wong
#10 lore raw

PATCH 1/1 git-svn: update svn mergeinfo test suite

In reply to Andrew Myrick

Add a partial branch (e.g., a branch from a project subdirectory) to the git-svn mergeinfo test repository.

Add a tag and a branch from that tag to the git-svn mergeinfo test repository.

Update the test script to expect a known failure in git-svn exposed by these additions where merge info for partial branches is not preserved.

---
 t/t9151-svn-mergeinfo.sh   |    2 +-
 t/t9151/make-svnmerge-dump |   65 +++++-
 t/t9151/svn-mergeinfo.dump |  545 ++++++++++++++++++++++++++++++++++----------
 3 files changed, 485 insertions(+), 127 deletions(-)
t/t9151-svn-mergeinfo.sh +1 -1
index 359eeaa..3569c62 100755
@@ -33,7 +33,7 @@ test_expect_success 'svn non-merge merge commits did not become git merge commit
 	[ -z "$bad_non_merges" ]
 	'
 
-test_expect_success 'everything got merged in the end' '
+test_expect_failure 'everything got merged in the end' '
 	unmerged=$(git rev-list --all --not master)
 	[ -z "$unmerged" ]
 	'
t/t9151/make-svnmerge-dump +63 -2

77 lines not on this page · raw message

t/t9151/svn-mergeinfo.dump +421 -124

921 lines not on this page · raw message

Signature · 1 line
1.6.6.2.g1fc48.dirty