views:

239

answers:

2

When changing the VCS for my project FakeItEasy from SVN to Mercurial on Google Code I was a bit too eager (I'm funny like that). What I did was just checking the latest version out of SVN and then commiting that checkout as the first revision of the new Mercurial repo. This obviously has the effect that all history is lost.

Later when getting a bit better acustomed to Mercurial I realized that there is such a thing as a "convert extension" that allows you to convert a SVN repo into a Mercurial repo. Now what I want to do is to convert the old SVN repo and then have all change sets from the currently existing Mercurial repo imported into this converted repo except the very first commit to Mercurial.

I've converted the SVN repo to a local Mercurial repo but now is when I'm stuck. I thought I'd be able to use the convert extension to bring the current Mercurial repository into the converted one and having a splice map remove the first commit but I can not seem to get this to work.

I've also tried to just use convert without splice map to get all change sets from the current Mercurial repo into the converted one and the rebase the second version in the current to the last commit from the old SVN repository but I can't get that to work either.

To make this clearer lets say I have these two repositories:

A: revA1-revA2
B: revB1-revB2-revB3 (Where revB1 is actually a copy of revA2)

Now I want to combine these two into the new repository containing this:

C: revA1-revA2-revB2-revB3
+2  A: 

So long as you're changing the hashes on the new revisions (you are), you might as well just use export and import (or the transplant command that is a wrapper around the two).

You already did your convert, which is great, now go into repo B and do:

hg export -o 'changeset-%R.patch' 1:tip

that will create a changeset-##.patch for each changeset in repo B, except the first (numbered zero).

Now go to repo C and import them:

hg import *.patch

That should all apply cleanly if indeed the revA2 and revB1 were identical.

Ry4an
This works perfectly except for one thing. I can't seem to get the import to work with the wildcard so I had to do one import for each patch file, but I only had to do it this once anyway. Thanks!
Patrik Hägne
Yeah the wild card would only work on unix where your shell does glob expansion. On windows each application needs that logic, so if you're on windows you'd need a FOR loop or just run each one as you did. Glad it worked.
Ry4an
+1  A: 

You can pull in changes from an unrelated repository with "hg pull --force"

Here is a simple usage example:

set up the test directories

C:\temp>mkdir hgtest
C:\temp>cd hgtest
C:\temp\hgtest>mkdir a
C:\temp\hgtest>mkdir b
C:\temp\hgtest>mkdir c

make repository a

C:\temp\hgtest>cd a
C:\temp\hgtest\a>hg init
C:\temp\hgtest\a>echo line one >> file.txt
C:\temp\hgtest\a>hg add file.txt
C:\temp\hgtest\a>hg ci -m "check in one"
C:\temp\hgtest\a>echo line two >> file.txt
C:\temp\hgtest\a>hg ci -m "check in two"
C:\temp\hgtest\a>echo line three >> file.txt
C:\temp\hgtest\a>hg ci -m "check in three"

make repository b

C:\temp\hgtest\a>cd ..\b
C:\temp\hgtest\b>copy ..\a\file.txt file.txt
C:\temp\hgtest\b>hg init
C:\temp\hgtest\b>hg add file.txt
C:\temp\hgtest\b>hg ci -m "check in b one"
C:\temp\hgtest\b>echo line four >> file.txt
C:\temp\hgtest\b>hg ci -m "check in b two"
C:\temp\hgtest\b>echo line five >> file.txt
C:\temp\hgtest\b>hg ci -m "check in b three"

make repository c as first a clone of a, then pull in the changes from b

C:\temp\hgtest\b>cd ..\c
C:\temp\hgtest\c>hg clone C:\temp\hgtest\a .
C:\temp\hgtest\c>hg pull --force C:\temp\hgtest\b
C:\temp\hgtest\c>hg merge
C:\temp\hgtest\c>hg ci -m "check in c one"
David Holbrook
Yes, the problem with this is that I get the first commit into repository B included which I don't want. Unless I'm overlooking something.
Patrik Hägne
You will have all revisions from both repositories (including the duplicate), but it should merge without conflict. It leaves you with a slightly messier revision history than the export/import solution.
David Holbrook