[PATCH 0 of 2 RFC] Shell alias support
Bill Barry
after.fallout at gmail.com
Fri Jul 9 00:47:09 CDT 2010
Steve Losh wrote:
> This is a second version of a patch I sent a day or two ago to add shell
> aliases to Mercurial, like so:
>
> [alias]
> qempty = !hg qrefresh -X "`hg root`"
>
> This would help get rid of hacky "alias hgsomething='hg something'" aliases in
> people's .whateverrc files.
>
> A few issues brought up in IRC:
>
> * There's no guarantee that the 'hg' command in the alias refers to the same
> 'hg' script that is being used. For example, if you 'make local' and run
> "./hg qempty" the qrefresh command inside that alias will be run with the
> 'hg' on your path, not the local one.
>
I don't think this can be done. If you must do something like this, you
should probably run the command with some sort of [new?] expansion that
stands for the repository root and a relative path from that. Persons
who are knowledgeable enough to be running a "make local" copy of hg
should be able to discover this concept quickly.
> * The second patch (which adds "$@" expansion) simply replaces raw strings --
> it doesn't take quoting into account. This might be surprising, but makes the
> code much, much cleaner and makes quoting in the alias itself simpler:
> whatever is in the definition is exactly what will be passed to the shell.
>
Surely there is some code already available which can make the quoting
issues go away. OTOH, I doubt this is a big deal for anyone. The oddity
I can see with it is if you do something like:
hg countv "branch('foo 1.2') and decendant('foo 1.2.2')"
which would be translated in your testcase to:
echo 'Revisions in "branch('foo 1.2') and decendant('foo 1.2.2')":' ; hg
log --template='.\n' -r 'branch('foo 1.2') and decendant('foo 1.2.2')' |
wc -l
Which is probably not what you want.
> * If this is something people aren't comfortable with it could be turned into
> a 'shellalias' extension instead, but I don't know how that would affect
> quoting in the .hgrc file.
>
I think if it needs to be done this way, the cmdalias class can be
derived to add the new functionality fairly easily, and the addalias
function can be monkeypatched to use the new class instead of the
current one (thus mimicking the proposed functionality nearly exactly;
there may be an even better way to do this so that other extensions can
also replace that class). This can be done in the extsetup method for
the loading of the extension. Changing the help text appears much more
difficult though.
> * The '!' prefix was chosen because that's what git uses, but could be changed
> if desired.
>
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel
>
>
More information about the Mercurial-devel
mailing list