Using "hg convert" on repos with multiple branches

Greg Ward greg at gerg.ca
Wed Sep 12 00:30:00 UTC 2012


On 11 September 2012, Scott Jarvi said:
> We're in the process of trying to collapse some of our Hg repos into a
> single repository.   The "convert" extension seems to be the right fit, but
> I'm not sure how the branches within each repo will be merged into the new
> repo.    An example - we have two separate repos, "old_repo1" and
> "old_repo2" both with named branches that have the same name:
> 
> old_repo1
> - default
> - branchA
> - branchB
> 
> old_repo2
> - default
> - branchA
> - branchB
> 
> We want old_repo1 & old_repo2 to become subdirectories of new_repo, but
> retain the branches and history.
> 
> new_repo
>  /old_repo1
>  /old_repo2
> - default
> - branchA
> - branchB
> 
> 
> Is this possible, and if so, what is the recommended approach here?

There's more than one way to do it. The simplest, most
straightforward, least clever, least magical is:

  * create new_repo
  * pull from old_repo1 into it
  * move all files into old_repo1
    (repeat for each branch -- or do it on the earliest branch and
    merge forward, if these are chronological release branches)
  * pull from old_repo2 -- that will create a separate root and
    new heads on each named branch
  * move all files into old_repo2 (again, repeat for each branch)
  * merge the two heads of branchB
  * merge the two heads of branchA
  * merge the two heads of default

This accurately preserves the history of what you did, with no "hg
convert" trickery to magically change history.

Downsides: 
  * you always need to remember "hg log -f" to follow renames
  * if the two old_repos are big (thousands of files), then those 
    two "rename everything" changesets will be annoyingly big:
    - "hg log -v" will be overwhelmed by the long list of renamed files
    - looking at them in hgweb will be slow

Alternately, you can use "hg convert" to magically change history.
That saves you from needing to remember "hg log -f", and avoids the
annoyingly large "rename everything" changesets. It does *not* save
you from:

  * a repository with multiple roots, which is a bit weird -- 
    if you update back to old changesets, either old_repo1/ or
    old_repo2/ completely disappears (don't worry, multi-root
    repos work just fine, they're just a bit weird, and certain
    Mercurial gurus -- notably Matt Mackall -- frown on them)
  * you have to merge heads on branchA, branchB, and default
    so that future history has both old_repo1/ and old_repo2/

I've done this a couple of times. Everything works just fine, but it's
up to you to do merge heads together. "hg convert" doesn't do it for
you.

       Greg
-- 
Greg Ward                                http://www.gerg.ca/
"Sure it's portable -- it works on Windows 95 *and* 98!"



More information about the Mercurial mailing list