To merge two unrelated repositories, preserving history, follow these steps.

If you only want to merge certain files or directories from REPO2 into REPO1, you can use the ConvertExtension to create a repository with only the files from REPO2 that you want, then treat that as your REPO2 when following the instructions above.

Renaming. Now suppose you want the files from REPO2 to live in a subdirectory of REPO1 called "lib2". Here's how to do that without using hg convert: