Skip to contentSkip to conversation

git-svn: teach git-svn to populate svn:mergeinfo

PATCH Superseded Bryan Jacobs 3 participants 11 messages Jun 15, 2016 Documentation

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 git-svn: teach git-svn to populate svn:mergeinfo

Quoted 1 line

From a74814d4cd91627098e5be0209da30a2bc23904e Mon Sep 17 00:00:00 2001

From: Bryan Jacobs <[email protected]>
Date: Thu, 1 Sep 2011 16:53:17 -0400
Subject: [PATCH] git-svn: teach git-svn to populate svn:mergeinfo

Allow git-svn to populate the svn:mergeinfo property automatically in a narrow range of circumstances. Specifically, when dcommitting a revision with multiple parents, each of which have been already committed to SVN.

In this case, the merge info is the union of that given by each of the parents, plus all changes introduced to the first parent by the other parents.

In all other cases where a revision has multiple parents, cause "git svn dcommit" to raise an error rather than completing the commit and potentially losing history information in the upstream SVN repository.

This behavior is disabled by default, and can be enabled by setting the svn.pushmergeinfo config option.

---

Per previous discussion re: svn:mergeinfo handling, I am submitting for your consideration a patch which allows git-svn to write mergeinfo as well as read it.

This has several limitations. Specifically, it does not handle any cases concerning fast-forward merges, nor any with cherry-picks. It exclusively deals with --no-ff merges where both parents are already committed to SVN.

For this particular case, it works well: svn:mergeinfo is populated in such a way that the local merge history is recreated when another git-svn user pulls down the repository. This patch thus allows to git users to exchange branching and merging development through a central SVN server without loss of fidelity and without explicitly manipulating the mergeinfo property by hand.

If the user has made commits to two local branches, merges them with --no-ff, and attempts to dcommit the result, the tool will error out with a message stating that all parents must reside in the SVN repository before their merge can be committed.

I was unable to discover a way to clean way to restore the repository state in the case where this happens before reaching the HEAD commit. For example:

r1 --- B --- C -- F
\ /
r2 --- E ------

If r1 and r2 already reside in SVN, git-svn will dcommit B and C, then error when it tries to dcommit F (since the SVN revision number for E has not yet been set; the user should dcommit E before dcommitting F). The repository SHOULD be set to the following state after this happens:

r1 -- r3 -- r4 -- F
\ /
r2 --- E ------

... but git-svn seems to put all the changes from all objects that it will be dcommitting into the working copy, which means that cherry-picking F atop the state the WC is in fails (due to conflicts with "untracked" objects already added). So in this patch if you try the above, you actually end up in this state:

r1 --- r3 -- r4
\
r2 --- E

F is lost and cannot be cherry-picked back onto the WC, as any files created in E are already present but untracked locally.

I would appreciate any help anyone can give with what the proper way to "partially reset" a git-svn commit which gets halfway through is. My attempt is the commented-out code in merge_commit_fail below. So far as I can tell, if *any* multi-revision dcommit of a merge is aborted partway through, it may end with an unclean WC and make reflog recovery necessary (even before my changes).

The other corner case I am unsure about is when two branches are merged, then the merge result is itself merged into a third. Like so:

branch1: r1 ----- r4

                 /  \
branch2:   r2 ---    \
                      \

branch3: r3 --------- r5

This has the effect of branch3's mergeinfo containing r2 as part of both branch1 and branch2 (branch2:2 from the merge history set in r4, and branch1:2 from the changes being introduced by the second parent of r5). I wasn't sure whether the mergeinfo should be "deduplicated" and only contain r2 on branch2. Not sure what the stock SVN client does here.

Finally, this makes NO EFFORT to handle svn:mergeinfo set on subdirectories of the branch root folder. The SVN red book advises against using mergeinfo on anything other than a branch top-level folder, so I think this is acceptable.

All new behavior is disabled by default, and all non-error-handling behavior is tested/demonstrated.

 Documentation/git-svn.txt         |    8 +
 git-svn.perl                      |  230 ++++++++++++++++++++++-
 t/t9160-git-svn-mergeinfo-push.sh |   97 ++++++++++
 t/t9160/branches.dump             |  374 +++++++++++++++++++++++++++++++++++++
 4 files changed, 707 insertions(+), 2 deletions(-)
 create mode 100755 t/t9160-git-svn-mergeinfo-push.sh
 create mode 100644 t/t9160/branches.dump
Documentation/git-svn.txt +8 -0
index ed5eca1..2bf5703 100644
@@ -213,6 +213,14 @@ discouraged.
 	store this information (as a property), and svn clients starting from
 	version 1.5 can make use of it. 'git svn' currently does not use it
 	and does not set it automatically.
++
+[verse]
+config key: svn.pushmergeinfo
++
+This option will cause git-svn to attempt to automatically populate the
+svn:mergeinfo property in the SVN repository when possible. Currently, this can
+only be done when dcommitting non-fast-forward merges where all parents have
+already been pushed into SVN.
 
 'branch'::
 	Create a branch in the SVN repository.
git-svn.perl +228 -2

254 lines not on this page · raw message

t/t9160-git-svn-mergeinfo-push.sh new file +97 -0

97 lines not on this page · raw message

t/t9160/branches.dump new file +374 -0

374 lines not on this page · raw message

Signature · 1 line
1.7.7.rc0.73.gc42335.dirty
#1 lore raw
Quoted 1 line · Bryan Jacobs

For this particular case, it works well: svn:mergeinfo is populated in such a way that the local merge history is recreated when another git-svn user pulls down the repository. This patch thus allows to git users to exchange branching and merging development through a central SVN server without loss of fidelity and without explicitly manipulating the mergeinfo property by hand.

Whee! That's what I was intending when I wrote the original change. I might have written it myself back in 2008 or whenever it was, but I found I didn't actually have any SVN projects I was sending commits to, let alone merges. git-svn is a project with a continually atrophying userbase :-). Thanks for picking it up.

Quoted 14 lines

If the user has made commits to two local branches, merges them with --no-ff, and attempts to dcommit the result, the tool will error out with a message stating that all parents must reside in the SVN repository before their merge can be committed.

I was unable to discover a way to clean way to restore the repository state in the case where this happens before reaching the HEAD commit. For example:

r1 --- B --- C -- F
\ /
r2 --- E ------

If r1 and r2 already reside in SVN, git-svn will dcommit B and C, then error when it tries to dcommit F (since the SVN revision number for E has not yet been set; the user should dcommit E before dcommitting F). The repository SHOULD be set to the following state after this happens:

r1 -- r3 -- r4 -- F
\ /
r2 --- E ------

Quoted 7 lines

... but git-svn seems to put all the changes from all objects that it will be dcommitting into the working copy, which means that cherry-picking F atop the state the WC is in fails (due to conflicts with "untracked" objects already added). So in this patch if you try the above, you actually end up in this state:

r1 --- r3 -- r4

  \
   r2 --- E

F is lost and cannot be cherry-picked back onto the WC, as any files created in E are already present but untracked locally.

Are r1 and r2 supposed to be on the same SVN branch?

Overall, I could believe that. Perhaps it is simpler to detect those situations in advance and insist the user dcommits them independently, although it appears to me that it would apply to any dcommit which failed for any reason part way through. So perhaps there is a wider justification for fixing that.

Sam

#2 lore raw
Quoted 8 lines · On Fri, 02 Sep 2011 11:40:25 -0700 Sam Vilain <[email protected]> wrote:
Quoted 6 lines · Bryan Jacobs

For this particular case, it works well: svn:mergeinfo is populated in such a way that the local merge history is recreated when another git-svn user pulls down the repository. This patch thus allows to git users to exchange branching and merging development through a central SVN server without loss of fidelity and without explicitly manipulating the mergeinfo property by hand.

Quoted 6 lines

Whee! That's what I was intending when I wrote the original change. I might have written it myself back in 2008 or whenever it was, but I found I didn't actually have any SVN projects I was sending commits to, let alone merges. git-svn is a project with a continually atrophying userbase :-). Thanks for picking it up.

Glad to hear it. I think there's still work to be done, mostly because I'm not very familiar with the git codebase and the "right" way to do things, but I want this to work.

Quoted 8 lines
Quoted 6 lines

r1 --- r3 -- r4

  \
   r2 --- E

F is lost and cannot be cherry-picked back onto the WC, as any files created in E are already present but untracked locally.

Are r1 and r2 supposed to be on the same SVN branch?

No, different SVN branches.

Quoted 6 lines

Overall, I could believe that. Perhaps it is simpler to detect those situations in advance and insist the user dcommits them independently, although it appears to me that it would apply to any dcommit which failed for any reason part way through. So perhaps there is a wider justification for fixing that.

I could do a pass through all the commits which are about to be sent out to SVN to check if this is going to happen, yes. But I think a better solution would be to change how the changes are replayed by git-svn dcommit: right now, all changes are applied to the WC, then it sequentially does an add+dcommit for each patch? Right? I think it might be better to reset --hard to the parent, then pick each change into the WC+index before committing. That way if you abort early, cleaning up just consists of rebasing the stack onto the last change you sent upstream.

If I get around to making git-svn put its stuff into notes, this would be a lot easier since you could just reset --hard back to the original HEAD, since none of the earlier commits would have been mangled. But of course everyone who already imported a repo would be SOL if the new version relied on that Hippocratic behavior...

Quoted 1 line

Sam

#3 lore raw
Quoted 9 lines · Bryan Jacobs

I could do a pass through all the commits which are about to be sent out to SVN to check if this is going to happen, yes. But I think a better solution would be to change how the changes are replayed by git-svn dcommit: right now, all changes are applied to the WC, then it sequentially does an add+dcommit for each patch? Right? I think it might be better to reset --hard to the parent, then pick each change into the WC+index before committing. That way if you abort early, cleaning up just consists of rebasing the stack onto the last change you sent upstream.

That's one way to do it; in fact, if the trees match you don't need to do anything complicated like cherry-pick.

ie, say you're committing

r1---A---B---C---D

and it blows up at

r1--r2--r3--C---D

So long as the tree from the fetched r3 == the tree from B, then you can just go ahead and write out new commits for C and D without doing any merging (ie cherry-pick or rebase). You could also put merge commits back the way they were, too.

If they don't match, then something went wrong with the push really, or there is something weird going on. I'd try to avoid using cherry pick automatically in situations like this. There are too many error modes, and if it only happens when you don't know what's going on, it's not a good idea to try to fix that. If it /is/ a sufficiently unlikely error (ie, the trees not matching as above), then it would be better to simply bomb out and provide two commands:

* a 'git reset' command to restore to previous state (ie, before the dcommit)
* a 'git rebase' command to attempt to put the new history on top of the new upstream. Rebase doesn't work with merges of course but it still should help the user figure out what to do.

Another benefit of this approach is that you don't need to muck with the WC + index at all, no matter what happens.

Sam

#4 lore raw
Quoted 7 lines · On Fri, 02 Sep 2011 12:01:09 -0700 Sam Vilain <[email protected]> wrote:

That's one way to do it; in fact, if the trees match you don't need to do anything complicated like cherry-pick.

ie, say you're committing

    r1---A---B---C---D
Quoted 8 lines

and it blows up at

    r1--r2--r3--C---D

So long as the tree from the fetched r3 == the tree from B, then you can just go ahead and write out new commits for C and D without doing any merging (ie cherry-pick or rebase). You could also put merge commits back the way they were, too.

When you say "write out new commits" you mean create a commit object with the same contents, but a different parent? Does git-svn do this somewhere already?

Quoted 8 lines

If they don't match, then something went wrong with the push really, or there is something weird going on. I'd try to avoid using cherry pick automatically in situations like this. There are too many error modes, and if it only happens when you don't know what's going on, it's not a good idea to try to fix that. If it /is/ a sufficiently unlikely error (ie, the trees not matching as above), then it would be better to simply bomb out and provide two commands:

Quoted 8 lines

* a 'git reset' command to restore to previous state (ie, before the dcommit)
* a 'git rebase' command to attempt to put the new history on top of the new upstream. Rebase doesn't work with merges of course but it still should help the user figure out what to do.

Another benefit of this approach is that you don't need to muck with the WC + index at all, no matter what happens.

All of the above sounds good to me. I haven't taken the time to understand how git-svn sends changesets upstream (I only know it mucks with the WC from empirical experience) so I don't know how easy it would be to change the methodology, though.

Would this also mean we could dcommit from a dirty checkout? Having to stash/unstash is a nuisance.

Quoted 2 lines

Sam

#5 lore raw
Quoted 14 lines · Bryan Jacobs
Quoted 11 lines · On Fri, 02 Sep 2011 12:01:09 -0700 Sam Vilain<[email protected]> wrote:

That's one way to do it; in fact, if the trees match you don't need to do anything complicated like cherry-pick.

ie, say you're committing

     r1---A---B---C---D

and it blows up at

     r1--r2--r3--C---D
Quoted 7 lines
Quoted 4 lines

So long as the tree from the fetched r3 == the tree from B, then you can just go ahead and write out new commits for C and D without doing any merging (ie cherry-pick or rebase). You could also put merge commits back the way they were, too.

When you say "write out new commits" you mean create a commit object with the same contents, but a different parent? Does git-svn do this somewhere already?

I guess it doesn't, but if it did it would certainly make this easier. I'm not sure why it would need to modify the WC at all. Eric, is this just historical or is there a better reason for that?

Sam

#6 lore raw
Quoted 19 lines · Sam Vilain
Quoted 18 lines · Bryan Jacobs
Quoted 15 lines · On Fri, 02 Sep 2011 12:01:09 -0700 Sam Vilain<[email protected]> wrote:

That's one way to do it; in fact, if the trees match you don't need to do anything complicated like cherry-pick.

ie, say you're committing

    r1---A---B---C---D

and it blows up at

    r1--r2--r3--C---D

So long as the tree from the fetched r3 == the tree from B, then you can just go ahead and write out new commits for C and D without doing any merging (ie cherry-pick or rebase). You could also put merge commits back the way they were, too.

Quoted 7 lines
Quoted 3 lines

When you say "write out new commits" you mean create a commit object with the same contents, but a different parent? Does git-svn do this somewhere already?

I guess it doesn't, but if it did it would certainly make this easier. I'm not sure why it would need to modify the WC at all. Eric, is this just historical or is there a better reason for that?

dcommit needs to continually rebase because it's possible somebody else may make a commit to the SVN repo while a git-svn user is dcommiting and cause a conflict the user would need to resolve in the working tree.

At least I think that was the reason... There is also the "commit-diff" command in git-svn. It was the precursor to dcommit which requires no changes to the working tree.

Signature · 1 line
Eric Wong
#7 lore raw
Quoted 9 lines · On Sat, 3 Sep 2011 08:49:47 +0000 Eric Wong <[email protected]> wrote:

dcommit needs to continually rebase because it's possible somebody else may make a commit to the SVN repo while a git-svn user is dcommiting and cause a conflict the user would need to resolve in the working tree.

At least I think that was the reason... There is also the "commit-diff" command in git-svn. It was the precursor to dcommit which requires no changes to the working tree.

Let me see if I've got this right.

The goal here is to commit each x~..x for each x in A..B, aborting if the SVN tree is not in state "x~" when the diff arrives.

"commit-diff" appears to be doing exactly what "dcommit" is doing, but iteratively for each change in linearized A..B, rebasing after each step. This sounds correct to me, assuming that the "apply_diff" method will correctly abort if a commit races into the upstream SVN before it is called. So why am I seeing files added in changes on alternate branches ending up in the working copy when I abort before apply_diff is called for the commit which merges them into the present branch?

You can check for this yourself with my patch using the example setup I gave earlier. You'll see files in the present/untracked state - these interfere with rebasing the user-created-but-not-SVN-dcommited merge onto the partially-sent-to-SVN tree.

Bryan Jacobs

#8 lore raw
Quoted 7 lines · Bryan Jacobs
Quoted 5 lines · On Sat, 3 Sep 2011 08:49:47 +0000 Eric Wong <[email protected]> wrote:

dcommit needs to continually rebase because it's possible somebody else may make a commit to the SVN repo while a git-svn user is dcommiting and cause a conflict the user would need to resolve in the working tree.

Quoted 8 lines
Quoted 3 lines

At least I think that was the reason... There is also the "commit-diff" command in git-svn. It was the precursor to dcommit which requires no changes to the working tree.

Let me see if I've got this right.

The goal here is to commit each x~..x for each x in A..B, aborting if the SVN tree is not in state "x~" when the diff arrives.

Yes.

Quoted 3 lines

So why am I seeing files added in changes on alternate branches ending up in the working copy when I abort before apply_diff is called for the commit which merges them into the present branch?

I don't know.

In my past use of git-svn, I've _always_ stuck with linear changes and avoided anything non-linear. SVN mergeinfo didn't exist when/where I used SVN and my only current uses of git-svn is read-only.

Anyhow, I'm willing to accept your change since it doesn't appear to break anything for existing users and Sam seems to approve.

Signature · 1 line
Eric Wong
#9 lore raw
In reply to Bryan Jacobs

git-svn.perl sub cmd_set_tree { · line 502

Quoted 3 lines · Bryan Jacobs
git-svn.perl +3 -0
+sub split_merge_info_range {
+	my ($range) = @_;
+	if ($range =~ /(\d+)-(\d+)/o) {

No need for "/o" in regexps unless you have a (constant) variable expansion in there.

git-svn.perl sub cmd_set_tree { · line 600

Quoted 7 lines
git-svn.perl +7 -0
+sub merge_commit_fail {
+	my ($gs, $linear_refs, $d) = @_;
+	#while (1) {
+	#	my $cs = shift @$linear_refs or last;
+	#	command_noisy(qw/cherry-pick/, $cs);
+	#}
+	#command_noisy(qw/cherry-pick -m/, '1', $d);

Huh? If there's commented-out code, it must be explained or removed.

git-svn.perl line 3

Quoted 8 lines
git-svn.perl +6 -0
+	fatal "Aborted after failed dcommit of merge revision";
+}
 
+++ b/t/t9160-git-svn-mergeinfo-push.sh
@@ -0,0 +1,97 @@
+#!/bin/sh
+#
+# Copyright (c) 2007, 2009 Sam Vilain

That should be: "Copyright (c) 2011 Brian Jacobs", correct?

t/t9160-git-svn-mergeinfo-push.sh line 27

Quoted 3 lines
t/t9160-git-svn-mergeinfo-push.sh new file +3 -0
+test_expect_success 'check svn:mergeinfo' '
+	mergeinfo=$(svn_cmd propget svn:mergeinfo "$svnrepo"/branches/svnb1)
+	echo "$mergeinfo"

No need to echo unless you're debugging a test, right?

Signature · 1 line
Eric Wong
#10 lore raw
Quoted 7 lines · On Tue, 6 Sep 2011 13:57:50 -0700 Eric Wong <[email protected]> wrote:

git-svn.perl sub cmd_set_tree { · line 502

Quoted 3 lines · Bryan Jacobs
git-svn.perl +3 -0
+sub split_merge_info_range {
+	my ($range) = @_;
+	if ($range =~ /(\d+)-(\d+)/o) {

No need for "/o" in regexps unless you have a (constant) variable expansion in there.

Okay, I'll take that out. I got into the habit of putting "optimize" on all regexes without an explicitly dynamic variable on some earlier Perl version.

Quoted 9 lines

git-svn.perl sub cmd_set_tree { · line 600

Quoted 7 lines
git-svn.perl +7 -0
+sub merge_commit_fail {
+	my ($gs, $linear_refs, $d) = @_;
+	#while (1) {
+	#	my $cs = shift @$linear_refs or last;
+	#	command_noisy(qw/cherry-pick/, $cs);
+	#}
+	#command_noisy(qw/cherry-pick -m/, '1', $d);

Huh? If there's commented-out code, it must be explained or removed.

I think I did explain that in my earlier comments. I'm still not happy with the recovery-from-aborted-commit-series handling. That commented bit was my attempt.

The best suggestion so far is to prescan the commits to fail-fast. I will do that in the next revision of the patch, just give me some time to put it together.

Quoted 10 lines

git-svn.perl line 3

Quoted 8 lines
git-svn.perl +6 -0
+	fatal "Aborted after failed dcommit of merge revision";
+}
 
+++ b/t/t9160-git-svn-mergeinfo-push.sh
@@ -0,0 +1,97 @@
+#!/bin/sh
+#
+# Copyright (c) 2007, 2009 Sam Vilain

That should be: "Copyright (c) 2011 Brian Jacobs", correct?

Well, the file was copied from one bearing the Vilain copyright bit. I'm not sure I entirely understand why it matters who holds the individual copyrights if you have a collective license which is going to be changed, but I can't just stick my own name on derived work - as the setup code for that unit is.

Quoted 7 lines

Review

Quoted 4 lines
(quoted diff) +2 -0
+test_expect_success 'check svn:mergeinfo' '
+	mergeinfo=$(svn_cmd propget svn:mergeinfo

"$svnrepo"/branches/svnb1)

(quoted diff) +1 -0
+	echo "$mergeinfo"

No need to echo unless you're debugging a test, right?

Correct, leftover test-debugging cruft, will remove.

I will submit another revision shortly.

Bryan Jacobs