subrepo, hg clone and symlinks

mercurial, subrepos

Solution

First of all, that part of Mercurial, I'm not an expert, but here's what I've understood.

No, you didn't create a link to the whole directory. Instead, files were hardlinked inside it.

This means that space on disk is reserved to keep your directory structure separate, but the files are all identical, because they were just cloned, so they are constructed as links back to the original.

When you start manipulating the repository, through your `add` or `commit` (`ci`) commands, then the hardlinks are broken by Mercurial and separate files are constructed for each, on demand.

Now, this is purely a technical thing, you don't need to know or care about this. If it makes it easier, just think of a clone as a complete copy of the original repository, separate files and all that. The hardlink part is just to save diskspace for the things that are the same.

Since a typical project has many files, and a typical changeset only changes a few files, and a typical reason to clone is that you're going to do a fixed set of changes, hardlinks makes sense since many of the files in the repository directories will be 100% identical to their original for the lifetime of the repository.

For those that aren't, all of that is silently handled by Mercurial for you.

Problem

I'm quite new to mercurial, I've read a lot on this topic but I've been unable to find a clear answer. The mercurial guide says: "For efficiency, hardlinks are used for cloning whenever the source and destination are on the same filesystem (note this applies only to the repository data, not to the working directory)." The Repository wiki page says: "All of the files and directories that coexist with the .hg directory in the repository root are said to live in the working directory". Now, to "link" a subrepo in a main repo I do: ``` hg init main cd main echo subrepo = ../subrepo > .hgsub hg clone ../subrepo subrepo # (1) hg add hg ci -m "initial rev of the main repo" ``` Does the definition above mean that I'm actually creating a copy of `subrepo` when I perform (1)?? Or am I creating just a symlink to `../subrepo`? According to the output of `ls`, it is an actual copy. But it sounds so strange to me... If someone could put a bit of light on this subject, I'd appreciate.

Original source