Skip to main content

How Mercurial will save my bill (and my time) for the next month

Posted by fabriziogiudici on August 2, 2009 at 4:55 AM PDT

Ahhh... at last I've moved to my "summer residence", as usual in the beloved Maremma Toscana. I've moved part of my lab with me and I can work as usual on my projects - even better, considering the relaxing environment (cicadas, singing birds, plenty of photographic subjects, delicious food).

The only pitfall is the internet connection. Indeed, in the latest years the 3G connection proved to be reasonably reliable and effective - but clearly it's far from the 20mbits/sec that I enjoy at home - not only a matter of speed, but of latency too.

I've already blogged that asynchronous operations of Mercurial are giving me a substantial help in this environment, allowing me to work as usual with the "commit often" approach. But there's another problem. I've moved with three computers: my laptop, the older MacBook Pro where I run Windows (for JavaFX Mobile development) and a netbook for working during hikes (it's a brand new EEE 1008HA). With Subversion, in order to sync changes among the different computers I had to do a round-trip through the internet: commit to the repo and update from the repo on a different computer. Sure, with Subversion you could manually copy files, but I find this error-prone.

With Mercurial, I've just set up a "proxy repository": that is, a repository hosted on the computer I'm using as a gateway (it's an old Mac Mini). To have it working it's a straightforward process:

  1. Install Mercurial on the computer.
  2. Create a user named 'hg'
  3. In the home, create a repos directory
  4. In the home, create a hgweb.config file with these contents:
    [Monsoon:~] hg% cat hgweb.config
    repos/ = repos/

  5. Create a brand new repository for each project; for instance, hg init repos/jrawio~src
  6. Set the configuration file for the repository as follows:

    [Monsoon:~] hg% cat repos/jrawio~src/.hg/hgrc
    allow_push = *
    push_ssl = false

    default =
  7. Have Mercurial to serve files with the command line:
    hg serve --webdir-conf /Users/hg/hgweb.config

Now, in my laptop I changed the Mercurial configuration file as follows:

[Mistral:Projects/jrawio/src] fritz% cat .hg/hgrc
#default =
= http://monsoon:8000/jrawio~src

And, at last, I performed a hg push. Now, all of my work has been pushed to the proxy repository. From another laptop, I can just run

hg clone http://monsoon:8000/jrawio~src

Every push from my laptops will go to the proxy repository; from the latter, I just have to perform another hg push to have the stuff going to Kenai. Of course, the thing can be easily scripted and automated for all my project repositories. Now, bits will go to the internet only when strictly needed, and everything is pretty fast on the local network.

When my friend Emanuele gets here in a few weeks to spend a few days enjoying a mix of holidays and work on our imaging stuff, as we started to do a few years ago, will be a breeze to extend the workflow to his laptop.

I've got still to study it, but I think it's possible to have the proxy repository to automatically push to Kenai whenever it gets new contents.


Hmm... not good yet. I've seen a sort of infinite loop to push with the above hook.

Ok, found it. Just add to the .hgrc file: [hooks] incoming = hg push Everytime you push to the proxy repository, it will in turn push to the original repository. Excellent!