Using Convert to Decompose Your Repository

posted by Thomas G. Willis on November 16, 2009

Say you have a repository that has evolved to contain many projects (folders). And you have decided you’d be better off if each project (folder) were a separate repository. You can use the convert extension to do just that and retain your changeset history.

For example, a repository laid out like this:

/yourrepository
    /DatabaseFoo
    /SweetBusinessLogic
    /BaseUI
    /AnotherDamnContentManagementSystem

You may have decided at some point that AnotherDamnContentManagementSystem really should belong in its own repository, and had you been able to predict the future so long ago, you would have seen that it was truly a poor choice on your part to combine them all together in one like you were still using Perforce and assumed that this whole version control thing was a super expensive operation.

Well lucky for you, the convert extension can help you undo this embarrassing decision before you show your work to the Venture Capitalist you’re meeting for lunch.

First enable the convert extension:

[extensions]
convert =

The convert command has a --filemap parameter which allows you to specify what you want included in the operation and what you don’t. You can even have things renamed as part of the operation. A filemap for the operation we are to perform will look like this:

include AnotherDamnContentManagementSystem
rename .

Then your command to convert will look like this:

$ hg convert --filemap myfilemap bigrepo AnotherDamnContentManagementSystem-Repo

And that’s it. AnotherDamnContentManagementSystem is now its own Mercurial repository.

What if your repository is too big for its own britches, and you would rather the projects contained within be their own repositories? But darn it, what about the history?