I'm trying to script hg diff
and want to accept an argument that will be passed to the -r
option, and if no argument is given, to default to the working directory. However, it appears there is no value that can be passed to -r
to indicate "working directory", and instead the option must be omitted entirely, which leads to the following logic in my script:
if [ -z "${to_rev}" ]; then
to_rev_args=""
else
to_rev_args="-r ${to_rev}"
fi
hg diff ... ${to_rev_args}
Am I correct in believing this is the only way? We can assume that making the script accept a -r
argument and passing the whole thing on to Mercurial is not an option; the arguments must conform to a style used by a suite of tools.
The following Mercurial extension should do what you need, by allowing you to specify the working directory as a pseudo revision named "
=
".The same logic can also fairly easily be encoded in a script or other program code if you don't want the hassle of dealing with an extension, you just have to distinguish between four different cases:
Assume that you want to diff REV1 and REV2, where either revision may be the working directory:
hg diff -r REV2
.hg diff --reverse -r REV1
.hg diff -r REV1 -r REV2
.