Adding changes from one Mercurial repository to another
Asked Answered
T

2

8

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
Tomokotomorrow answered 21/4, 2010 at 16:27 Comment(0)
S
12

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 $(ls *.patch | sort -V)

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

Supine answered 21/4, 2010 at 16:45 Comment(3)
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!Gatha
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.Supine
It might not work on Linux as well for a simple reason: changesets are numbered using a variable number of digits (i.e. 1,2,3,...,10,11,...100,101, etc.), causing changeset-10.patch to be imported before changeset-2.patch according to the normal shell expansion. You should sort them: hg import $(ls *.patch | sort -V)Bagehot
B
0

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"
Baryton answered 21/4, 2010 at 17:16 Comment(2)
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.Gatha
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.Baryton

© 2022 - 2024 — McMap. All rights reserved.