Conditionally Applying Patches with Guards
Perhaps the best way to maintain sanity with so many
targets is to be able to choose specific patches to apply for a given
situation. MQ provides a feature called “guards” (which
originated from quilt’s guards
command) that does
just this. To start off, let’s create a simple repository for
experimenting in.
$
hg qinit
$
hg qnew hello.patch
$
echo hello > hello
$
hg add hello
$
hg qrefresh
$
hg qnew goodbye.patch
$
echo goodbye > goodbye
$
hg add goodbye
$
hg qrefresh
This gives us a tiny repository that contains two patches that don’t have any dependencies on each other, because they touch different files.
The idea behind conditional application is that you can “tag” a patch with a guard, which is simply a text string of your choosing, then tell MQ to select specific guards to use when applying patches. MQ will then either apply, or skip over, a guarded patch, depending on the guards that you have selected.
A patch can have an arbitrary number of guards; each one is positive (“apply this patch if this guard is selected”) or negative (“skip this patch if this guard is selected”). A patch with no guards is always applied.
Get Mercurial: The Definitive Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.