1
votes

Hi I've converted a local svn repository to mercurial, commited several revisions in hg and want now to get the changes back into svn.
Can anyone advise in how to do it?

I've found https://www.mercurial-scm.org/wiki/WorkingWithSubversion#With_Convert_extension but unfortunately, I haven't done the conversion as described there (just did hg convert on the local repo) and didn't work with MQ, either.

Is there any chance to push back the individual revisions to subversion or is all I can to a local diff on the changes?

3
I go through a rather complicated process involving setting up a directory that is both a Mercurial and Subversion working copy at the same time. It's error prone, but works for me.Omnifarious
Are you trying to support two version control systems for the long-term? That sounds like a bad idea. Why do you need this?robert
@robert: no this was just a temporary fork and I just want to get the changes now back to svnKutzi

3 Answers

1
votes

This isn't as hard as people are making it out to be. Long term, I do suggest you use hgsubversion as the other answers suggest, but there is a pretty simple short-term solution.

  1. Check in everything in your hg repo
  2. hg up -r [last revision that was converted from svn]
  3. Check out from svn into a clean directory
  4. Copy the .hg directory from your hg repo to your svn checkout
  5. Check all of these svn changes into your hg repo (remember to add/delete files... this step will take a bit as hg has to scan everything this time)
  6. Merge the two heads you have now using hg (assuming svn has moved on ahead of you)
  7. Test the build (if needed) by pulling the changes back to your original hg repo and testing there (the idea is to keep your 'hg+svn repo' clean so missing/added files are easy to spot in the respective tools)
  8. Check in all the changes using svn (remember to add/delete files)

Once you have this in place, it's actually not too hard to use both systems on top of each other... but hgsubversion is probably a better solution if you need this long term. I personally use the above system because hgsubversion does not handle some of the rather bizarre things we've done to our svn repo in the past.

EDIT: I'm making an assumption with this solution that the svn trunk has moved on ahead of you; if this is not the case, this procedure becomes much simpler. If you want to merge each hg revision in separately, there should be no reason you can't do this, it'll just take a bit more work.

  • Merge hg rev 1 to the svn tip... commit in svn
  • Merge hg rev 2 to the svn tip... commit in svn
  • Merge hg ...
3
votes

I think you might be able to use hgsubversion.

I'd try to do this:

  1. Clone the SVN repository using hgsubversion.
  2. Try to move your changes from your old repository to this new one. This might prove to be tricky. Here are some solutions:
    • Adding changes from one Mercurial repository to another, which uses export and import commands, or the transplant extension.
    • Maybe you can use hg pull --force to pull changesets from that unrelated repository. (see How to combine two projects in Mercurial?) But then, after that, you would need to run merge, which might get buggy when you push your changes back to SVN. So maybe you can try using rebase or mq extension.
    • Maybe you might be able to use mq extension to generate a bunch of patches on the old repository, copy them to the new one, and then apply them.
    • If all else fails, you can "manually" apply each changeset, one-by-one, by re-doing the changes you've done previously. (hg diff -c rev_id command will be useful)
  3. With all changes in your hgsubversion copy, just push them, and they will be added to the SVN repository.
  4. ...?
  5. Profit!
1
votes

I personally use Mercurial at work to work with our subversion repository. I strongly suggest you clone using hgsubversion, since it is able to commit back to the subversion repository when doing a simple push. The only thing is that you have to learn how to rebase your changes as you cannot use the merge functionality of mercurial (subversion simply cannot understand that a changeset could have two parents).

A converted repository as you have done is useful if you want to remove the subversion repo and replace it with mercurial. This is, unfortunately, impossible to push back (unless you want to start playing with diffs)

However, if you clone the svn repo with hgsubversion, you will probably (assuming no merges) be able to pull the changes you already made on your current converted mercurial depot into it. If there are merges, you will have to "linearize" it before transferring the changes.