[RFC 2/3] git-svn: Support cherry-pick merges

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Detect a cherry-pick merge if there's only one parent and the git-svn-id
metadata exists. Then, get the parent's mergeinfo and merge this commit's
mergeinfo.
---
 git-svn.perl                      | 52 +++++++++++++++++++++++++++++++++++++--
 t/t9161-git-svn-mergeinfo-push.sh | 30 ++++++++++++++++++++++
 2 files changed, 80 insertions(+), 2 deletions(-)

diff --git a/git-svn.perl b/git-svn.perl
index 9ddeaf4..b04cac7 100755
--- a/git-svn.perl
+++ b/git-svn.perl
@@ -698,12 +698,14 @@ sub populate_merge_info {
 	my %parentshash;
 	read_commit_parents(\%parentshash, $d);
 	my @parents = @{$parentshash{$d}};
+
+        my $rooturl = $gs->repos_root;
+        my ($target_branch) = $gs->full_pushurl =~ /^\Q$rooturl\E(.*)/;
+
 	if ($#parents > 0) {
 		# Merge commit
 		my $all_parents_ok = 1;
 		my $aggregate_mergeinfo = '';
-		my $rooturl = $gs->repos_root;
-		my ($target_branch) = $gs->full_pushurl =~ /^\Q$rooturl\E(.*)/;
 
 		if (defined($rewritten_parent)) {
 			# Replace first parent with newly-rewritten version
@@ -785,6 +787,52 @@ sub populate_merge_info {
 		if ($all_parents_ok and $aggregate_mergeinfo) {
 			return $aggregate_mergeinfo;
 		}
+	} elsif ($#parents == 0) {
+		# cherry-pick merge
+		my ($cherry_branchurl, $cherry_svnrev, $cherry_paruuid) =
+			cmt_metadata($d);
+
+		if(defined $cherry_branchurl && defined $cherry_svnrev && defined $cherry_paruuid)
+		{
+			if (defined($rewritten_parent)) {
+				# Replace first parent with newly-rewritten version
+				shift @parents;
+				unshift @parents, $rewritten_parent;
+			}
+
+			my $aggregate_mergeinfo = '';
+
+			# parent mergeinfo
+			my ($branchurl, $svnrev, $paruuid) =
+				cmt_metadata($parents[0]);
+
+			my $ra = Git::SVN::Ra->new($branchurl);
+			my (undef, undef, $props) =
+				$ra->get_dir(canonicalize_path("."), $svnrev);
+			my $parent_mergeinfo = $props->{'svn:mergeinfo'};
+			unless (defined $parent_mergeinfo) {
+				$parent_mergeinfo = '';
+			}
+
+			$aggregate_mergeinfo = merge_merge_info($aggregate_mergeinfo,
+					$parent_mergeinfo,
+					$target_branch);
+
+			# cherry-pick mergeinfo
+			unless ($cherry_branchurl =~ /^\Q$rooturl\E(.*)/) {
+				fatal "commit $d git-svn metadata changed mid-run!";
+			}
+			my $cherry_branchpath = $1;
+
+			my $cherry_pick_mergeinfo = canonicalize_path("$cherry_branchpath")
+				. ":$cherry_svnrev";
+
+			$aggregate_mergeinfo = merge_merge_info($aggregate_mergeinfo,
+					$cherry_pick_mergeinfo,
+					$target_branch);
+
+			return $aggregate_mergeinfo;
+		}
 	}
 
 	return undef;
diff --git a/t/t9161-git-svn-mergeinfo-push.sh b/t/t9161-git-svn-mergeinfo-push.sh
index 1eab701..f348392 100755
--- a/t/t9161-git-svn-mergeinfo-push.sh
+++ b/t/t9161-git-svn-mergeinfo-push.sh
@@ -91,6 +91,36 @@ test_expect_success 'check reintegration mergeinfo' '
 /branches/svnb5:6,11"
 	'
 
+test_expect_success 'make further commits to branch' '
+	git checkout svnb2 &&
+	touch newb2file-3 &&
+	git add newb2file-3 &&
+	git commit -m "later b2 commit 3" &&
+	touch newb2file-4 &&
+	git add newb2file-4 &&
+	git commit -m "later b2 commit 4" &&
+	touch newb2file-5 &&
+	git add newb2file-5 &&
+	git commit -m "later b2 commit 5" &&
+	git svn dcommit
+	'
+
+test_expect_success 'cherry-pick merge' '
+	git checkout svnb1 &&
+	git cherry-pick svnb2 &&
+	git cherry-pick svnb2^ &&
+	git cherry-pick svnb2^^ &&
+	git svn dcommit
+	'
+
+test_expect_success 'check cherry-pick mergeinfo' '
+	mergeinfo=$(svn_cmd propget svn:mergeinfo "$svnrepo"/branches/svnb1)
+	test "$mergeinfo" = "/branches/svnb2:3,8,16-17,20-22
+/branches/svnb3:4,9
+/branches/svnb4:5-6,10-12
+/branches/svnb5:6,11"
+	'
+
 test_expect_success 'dcommit a merge at the top of a stack' '
 	git checkout svnb1 &&
 	touch anotherfile &&
-- 
1.8.5.rc3.5.g96ccada

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]