Split Subversion repository into multiple Mercurial repositories?
Asked Answered
C

3

17

We're migrating from Subversion to Mercurial and have run into a bump in the SVN->Hg conversion process. Right now, our single SVN repo holds code for a couple distinct "projects", and we'd like to split them apart in the migration process. Our SVN repo is organized as:

.
|-- proj1
|   |-- branches
|   |-- tags
|   `-- trunk
`-- proj2
    |-- branches
    |-- tags
    `-- trunk

and we'd like to simply make proj1 and proj2 their own Hg repos. We'd like to, of course, not have history specific to proj1 appear in proj2's log either. Right now, when hg convert does the conversion, it just reads all the files pretty dumbly, not even distinguishing branches from trunks.

What's the process for filtering by directory and recognizing SVN branches in hg convert?

Culmiferous answered 17/11, 2010 at 23:39 Comment(9)
+1 This is a really important question and relevant at many companies.Todtoday
@Andres Jaan Tack: why were not projects organized as separated repositories at the beginning of work then?Disheveled
@erjiang: If you were happy using 2 projects in 1 repo using svn, why don't you follow the same (incorrect) schema and with mercurial? ;-)))Disheveled
I'm gonna go with "use SVN to sort the mess out and then import into Hg" aka "How do you split SVN repos into two projects and keep the appropriate data with each" ... you're trying to shoehorn two projects under one banner. At least, that's the case from where I'm standing.Goliath
@zerkms: Perhaps the same reason that ALL of KDE was in one SVN repo. They were two somewhat-related projects (a lot of the same people working on both), and having them in one repo saved some work setting up SVN. The reasons we justified it with don't really hold in Mercurial, so...Culmiferous
All in one is pretty good setup in svn because there's the ability to checkout only portions of a tree. Mercurial (and other DVCSs) just don't offer that, which is why convert and filemap make it pretty easy to split out a repo.Mambo
Here's the similar question: #3066798Mambo
@erjiang: "repo saved some work setting up SVN" -- you saved a lot of time on ~20 keystrokes of svnadmin create ... ;-)Disheveled
-1 to all unhelpful commenters.Oedema
C
8

I've got it working now, thanks to the ConvertExtension wiki page!

I tried Ry4an's method, but it came with the downsides of having to first convert the SVN repo into an intermediate Mercurial repo before splitting everything, and that branches, trunk, and tags weren't being recognized because there are two projects each with their own branches, trunk, and tags.

I found that manually specifying the branches, trunk, and tags directory worked great for converting one project from SVN to Mercurial at a time:

hg \
--config convert.svn.trunk=proj1/trunk \
--config convert.svn.branches=proj1/branches \
--config convert.svn.tags=proj1/tags \
convert --authors authors.txt original-svn-dir hg-proj1

This will take care of recognizing SVN branches, tags, and trunk and filter for only proj1 revisions at the same time. Then, I just repeated it for proj2.

Culmiferous answered 18/11, 2010 at 4:25 Comment(2)
Glad you got it working. The drawback with multiple svn->hg conversations is that the svn->hg piece takes much much longer than the hg->hg pieces, so given the iterative nature of getting authormaps, splits, etc. right doing the svn->hg once, and doing (and redoing) hg->hg for each project usually saves time. Also, if you're going to be using convert's support for incremental conversion (ie: do this again in a month bringing in the new svn stuff w/o altering hg hashids) you need a single svn convert.Mambo
It was a local->local conversion, so it wasn't too bad time-wise.Culmiferous
E
2

Another way to solve it would be to use svnadmin dump and svndumpfilter to split the svn repo into one new svn repository per project as described in the svn documentation. Splitting repositories by filtering repository history

Extravasation answered 18/11, 2010 at 11:52 Comment(0)
M
0

This is easily done using the 'convert' extension as you've suggested. Here's the procedure:

  1. do a hg convert SVNREPO all-in-one-mercurial-repo from svn to mercurial with everything
  2. do multiple hg convert --filemap projectfilemap.txt all-in-one-mercurial-repo project-repo commands -- one per project

Those filemaps have in them lines like:

exclude proj1
rename proj2 .

That would the the filemap used when extracting just project two's repo from the all-in-one mercurial repo. You may need to list each individual file in those maps, but I think directories are okay.

There's another question here on SO where I answered pretty much the same thing and pasted in a full example, but that should be enough to get you going.

Mambo answered 18/11, 2010 at 2:30 Comment(3)
Perhaps a link to the previous question could be posted?Culmiferous
Oh, also, can hg convert understand branches like git-svn can?Culmiferous
Yes, if you've used a normal branches/, tags/, trunk/ tree structure it picks them up just fine.Mambo

© 2022 - 2024 — McMap. All rights reserved.