Convert mercurial repository to subrepositories with full history (like hg log -f)

mercurial

Solution

I assume that you had something like this structure:

main.c
lib1.c
lib2.c

You renamed the files and got something like this:

main.c
lib/lib1.c
lib/lib2.c

You now want something like this as you `lib` repository:

lib1.c
lib2.c

I assume this last part because, when you include it as a sub-repository, it will look like the your original repository did after the rename.

I would do this in a few stages.

The first stage would be to do as you probably already did. Convert the repository with the command line `hg convert --filemap LibTempMap.txt Main LibTemp` and the following contents of `LibTempMap.txt`:

exclude *
include lib
rename lib .

This gives you a repository with the history after the rename.

The second stage would be to convert the repository before the rename with the command line `hg convert --rev X --filemap LibMap.txt Main Lib` (where X is the revision before the rename) and the following contents of `LibMap.txt`:

exclude *
include lib1.c
include lib2.c

This gives you a repository with the history from before the rename.

I would then transplant the later changes from `LibTemp` to `Lib` using `hg transplant -s ..\LibTemp Y:tip` from within the `Lib` folder (where `Y` is the revision after the rename in the `LibTemp` repository). This should transplant cleanly as you made sure that the file structures were the same in the temporary repository by doing the rename during the convert.

You're then left with the `Lib` repository containing the history and files that you want and can delete the `LibTemp` repository.

Problem

Recently I moved some files in my mercurial repository to a subdirectory (as a module) to keep everything tidy. Some days later I found out I needed that module in another project, so I'm trying to convert it to its own mercurial repository. The problem I'm facing is that the new repository history isn't complete, it only includes file's history after the rename. The history I'm getting is the same as executing `hg log filename`, and what I want is to have the full history of the file, like the output of `hg log -f filename`. What am I missing? Thanks.

Original source