This week in panospace

Local Transparent Cache of a Mercurial Repository

It’s been a while since I blogged.  January was extremely busy.  I did some interesting stuff with Mercurial and I would like to share some of them, starting with this one.

It is not unusual for developers to work concurrently on different local clones, and cloning clean every time from another repository on the Internet is inefficient.  Many will have a clean local pull and work on copies of it, but this brings the headache of manually updating and keeping track of changes that have not gone upstream yet.  The headache can be done away by making the clean clone a transparent cache, and cloning it rather than copying it.

These are the commands to make it work with Hugin:

$ mkdir ~/src/hugin
$ cd ~/src/hugin
$ hg clone \
     ssh://${USER} \
$ nano hugin.cache/.hg/hgrc

Add the following lines to hugin.cache/.hg/hgrc:

# make sure we're committing on the latest version upstream
precommit.from_master = hg pull
# after committing, push to the main repo
changegroup.sf = hg push
# make sure that we answer a pull with the latest version upstream
preoutgoing.to_master = mv .hg/store/lock .hg/store/unlock
    && hg pull && mv .hg/store/unlock .hg/store/lock

All in the spirit of sync early, sync often, The first hook pulls the latest changes from upstream before committing; the second pushes the committed changes to upstream; and the third pulls from upstream before responding to downstream pulls.

Now, when you want to start working on Hugin on a clean slate you go business as usual:

$ cd ~/src/hugin
$ hg clone hugin.cache
$ cd
$ hg pull && hg up
... hack ... hack ...
$ hg ci
... hack ... hack ...
$ hg ci
$ hg push

And to work on a second copy, e.g. on the next release:

$ cd ~/src/hugin
$ hg clone hugin.cache hugin.release
$ cd hugin.release
$ hg pull && hg up -C 2011.0

Your transparent cache insures that you’re in sync with the rest of the team.  Happy hacking!