[PATCH] dispatch: provide an HG_ARGS environment variable to shell aliases
Steve Losh
steve at stevelosh.com
Thu Jul 29 09:18:48 CDT 2010
On Jul 29, 2010, at 10:16 AM, Nicolas Dumazet wrote:
> 2010/7/29 Steve Losh <steve at stevelosh.com>:
>> # HG changeset patch
>> # User Steve Losh <steve at stevelosh.com>
>> # Date 1280375531 14400
>> # Node ID eb11d2fb96d16d5b8e55621260ea0e1d49d45aae
>> # Parent 84fb29f5e0d29bc95006947a62133032499e3fa3
>> dispatch: provide an HG_ARGS environment variable to shell aliases
>>
>> This patch changes the functionality of shell aliases to pass the extra command
>> line arguments as an HG_ARGS environment variable, instead of simply appending
>> them to the command.
>>
>> This allows for more flexible shell aliases:
>>
>> [alias]
>> echo = !echo $HG_ARGS
>> count = !hg log -r "$HG_ARGS" --template='.' | wc -c | sed -e 's/ //g'
>
> I dislike the new environment variable.
> I'd rather support something like $@, or %(args)s, or any syntax that
> you feel like, but introducting yet another variable seems wrong to
> me.
Matt mentioned in IRC that this is how hooks do it, so having shell extensions work the same way would keep things more consistent.
Though in this case the HG_ARGS variable is a tiny bit different than the HG_ARGS you get from a post-(command) hook, because it doesn't include the command (i.e. alias) name. I'm not sure I like this inconsistency.
>
> -Nicolas.
>
>>
>> In action:
>>
>> $ hg echo foo
>> foo
>>
>> $ hg count 'branch(default)'
>> 901
>>
>> $ hg count 'branch(stable) and keyword(fixes)'
>> 102
>>
>> diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
>> --- a/mercurial/dispatch.py
>> +++ b/mercurial/dispatch.py
>> @@ -212,12 +212,12 @@
>>
>> return
>>
>> if self.definition.startswith('!'):
>> def fn(ui, *args):
>> - cmd = '%s %s' % (self.definition[1:], ' '.join(args))
>> - return util.system(cmd)
>> + env = {'HG_ARGS': ' '.join(args)}
>> + return util.system(self.definition[1:], environ=env)
>> self.fn = fn
>> return
>>
>> args = shlex.split(self.definition)
>> cmd = args.pop(0)
>> diff --git a/tests/test-alias b/tests/test-alias
>> --- a/tests/test-alias
>> +++ b/tests/test-alias
>> @@ -12,11 +12,12 @@
>> lognull = log -r null
>> shortlog = log --template '{rev} {node|short} | {date|isodate}\n'
>> dln = lognull --debug
>> nousage = rollback
>> put = export -r 0 -o "\$FOO/%R.diff"
>> -echo = !echo
>> +echo = !echo \$HG_ARGS
>> +count = !hg log -r "\$HG_ARGS" --template='.' | wc -c | sed -e 's/ //g'
>>
>> [defaults]
>> mylog = -q
>> lognull = -q
>> log = -v
>> @@ -66,5 +67,11 @@
>> FOO=`pwd` hg put
>> cat 0.diff
>>
>> echo '% shell aliases'
>> hg echo foo
>> +
>> +echo bar > bar
>> +hg ci -qAmbar
>> +
>> +hg count .
>> +hg count 'branch(default)'
>> diff --git a/tests/test-alias.out b/tests/test-alias.out
>> --- a/tests/test-alias.out
>> +++ b/tests/test-alias.out
>> @@ -43,5 +43,7 @@
>> +++ b/foo Thu Jan 01 00:00:00 1970 +0000
>> @@ -0,0 +1,1 @@
>> +foo
>> % shell aliases
>> foo
>> +1
>> +2
>> _______________________________________________
>> Mercurial-devel mailing list
>> Mercurial-devel at selenic.com
>> http://selenic.com/mailman/listinfo/mercurial-devel
>>
>
>
>
> --
> Nicolas Dumazet — NicDumZ
More information about the Mercurial-devel
mailing list