In my last post, on Mercurial Queues, I outlined how you might use MQ to manage a dwm patchset. Mercurial makes this process ridiculously easy, and this functionality is more than enough to recommend it. However, where I think it really gets interesting is when you share that same patchset across multiple machines and are easily able to customize which patches in the queue are applied, based upon the particular machine you are building dwm on.
For example, in my case I use dwm on all three of my machines: my desktop at home, my laptop at work and my EeePC. Given the nature of each of these three machines, though, I want a slightly different stack of patches applied. These differences might extend only to particular rules applied in config.def.h based upon the number of tags I use, or the different applications that I run at home as opposed to at work.
In any event, what I want to be able to do is maintain
a single patchset
in a mercurial repository, clone it to all my machines and then, using MQ,
filter which specific patches are applied. This is all possible using a killer
feature of MQ called
guards.
Guards allow you to conditionally apply patches in a queue. Essentially, in
a queue, you “tag” a patch with a guard and—depending on whether or not the
guard is positive (to be applied), or negative (to be skipped)—when you
hg qpush -a
MQ takes care of applying the correct patches in the queue.
So, in the case of my work laptop, I begin by cloning dwm and intializing a patch queue:
1 2 3 |
|
I setup my .hgrc within the patches directory so that it points at the correct mercurial repository:
1 2 3 4 5 6 |
|
Then I pull down my dwm patchset from the mercurial repository
with hg pull
:
1 2 3 4 5 6 7 |
|
After I update my local repo,1 I can see the full patchset with
hg qseries
:
1 2 3 4 5 6 7 |
|
Then, as I decribed in my previous post, I make the changes to config.def.h that are specific to this machine:
1 2 3 4 |
|
My patchset now has an additional patch in it:
1 2 3 4 5 6 7 8 9 10 |
|
This is where guards come in to play. If I wasn’t interested in sharing the patchset, it would just be a matter of deleting the patch for Centurion. However, what I want to do is direct MQ to ignore that specific patch when applying the queue. I do that by creating a negative guard and then activating it:
1 2 3 |
|
That’s it! Adding a verbose flag to hg qseries
2 will print out the
patchset and the accompanying guard status:
1 2 3 4 5 6 7 8 9 10 |
|
The real test, of course, is pushing the patchset onto the fresh dwm code:
1 2 3 4 5 6 7 8 9 10 11 |
|
How cool is that? One central patchset, applied conditionally depending upon the machine you are using at the time.
Notes
- Any guards applied on other machines will be present in the newly pulled series file: these conflicts will need to be manually merged…
- The options for all of the
hg
commands can be read withhg -v help $command
. For those related to queues, just prepend aq
to$command
.
Creative Commons image on Flickr by Thorsten Becker