Mercurial, Eclipse, Hard Links
For one of my major projects, I use Mercurial for version control, and Eclipse with PyDev for my primary development environment. I frequently clone a development trunk to create new development branches (usually one per feature set I’m working on at a time). I had a little hiccup of paranoia about what it means to clone a repository, since at least some of the newly-cloned files are not physical copies, but hard links. And I didn’t know what Eclipse did with hard links.
A quick look at the output of hg clone --help reveals the following:
- Running
hg clonecopies the tracked files and hard links the metadata (.hg directory). hg clone --pullcopies everything and hard links nothing.cp -alcopies nothing and hard links everything, which means your editor had better break hard links or else changes will be saved in two repositories at once.
In other words, an invocation of hg clone followed by editing some tracked files will always do the right thing, regardless of what your editor does. Since I always clone repositories using hg clone (disk space isn’t too tight at the moment), it was never an issue, even using a rather complex Java IDE.
That got me wondering, though, what would have happened if I cloned using cp -al. It turns out that by default,
- emacs breaks hard links. Can be overridden by adding
(setq backup-by-copying-when-linked t)to one’s “.emacs” file. - vim preserves hard links. Can be overriden by
set bkc=noin.vimrcor at the vim command line - Eclipse preserves hard links. This was tested empirically rather than looked up in documentation, and there isn’t an easily-located setting to change this.
- OS X TextEdit breaks hard links. Also tested, and I didn’t even look for a way to change it.
The moral of the story: when in doubt, hg clone.