hg makes distro hacking simpler

December 5th, 2007

Once, I offhandedly mentioned to Michael K Johnson that I often use hg to help me hack on distro packages. He said he thought it was neat and I should blog about it. So, half a year later when I finally bothered to set up a real blog…

The problem I was having was one of control. When approaching a bug in a package who’s codebase was unfamiliar, as I was often required to do, it would naturally take a number of attempts to get a bugfix correct. My build dir was often getting overwritten, causing my changes to unintentionally disappear. Further, when making changes, it was a pain to copy around build trees to get good diffs, especially on large packages, and it was impossible to undo something if I made a mistake.

Enter mercurial. Because hg has a totally distributed model, it is trivial to set up repositories, allowing one to use them essentially as scratch space. Now, every time I work on a package, I “cvc cook –prep” it to get the sources, and then run this script (if, indeed, you can call it that):

#!/bin/sh
hg init
hg addremove > /dev/null # addremove is overly verbose
hg ci -m “initial commit”

Then I hack on the package to my heart’s content without worrying what I’m screwing up in the process. I save “checkpoints” by doing hg commits, then later I can generate a diff from the initial commit all the way to tip, or to any point in the tree. When I’m done, I generate a patch and commit it to the conary repo. The hg tree is blown away by the next cvc cook, or by a tmpwatch cronjob that watches over my build dir. This allows me to not worry about forgetting parts of the changes I’ve made as it is all in the repo, and allows me to not worry about whether upstream patches or other applied patches conflict as they are all included in the first hg commit.

This method has the added benefit of making patches cleaner. Hg always generates a minimal unified level 1 diff. Always. No matter where you are in the tree or what nastiness you’ve done, making the patch both easier for humans to read and easier for cvc to apply.

Leave a Reply

You must be logged in to post a comment.