diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py index 8e00906066c9f170507a582d93b4b9171fbbe3cb_bWVyY3VyaWFsL2Rpc3BhdGNoLnB5..e4ab5ae193f21cb02c9a06dcde1d28c5665af3d7_bWVyY3VyaWFsL2Rpc3BhdGNoLnB5 100644 --- a/mercurial/dispatch.py +++ b/mercurial/dispatch.py @@ -182,10 +182,21 @@ return -1 -def aliasargs(fn): - if hasattr(fn, 'args'): - return fn.args - return [] +def aliasargs(fn, givenargs): + args = getattr(fn, 'args', []) + if args and givenargs: + cmd = ' '.join(map(util.shellquote, args)) + + nums = [] + def replacer(m): + num = int(m.group(1)) - 1 + nums.append(num) + return givenargs[num] + cmd = re.sub(r'\$(\d+|\$)', replacer, cmd) + givenargs = [x for i, x in enumerate(givenargs) + if i not in nums] + args = shlex.split(cmd) + return args + givenargs class cmdalias(object): def __init__(self, name, definition, cmdtable): @@ -263,7 +274,7 @@ else: self.fn, self.opts = tableentry - self.args = aliasargs(self.fn) + args + self.args = aliasargs(self.fn, args) if cmd not in commands.norepo.split(' '): self.norepo = False if self.help.startswith("hg " + cmd): @@ -330,7 +341,7 @@ aliases, entry = cmdutil.findcmd(cmd, commands.table, ui.config("ui", "strict")) cmd = aliases[0] - args = aliasargs(entry[0]) + args + args = aliasargs(entry[0], args) defaults = ui.config("defaults", cmd) if defaults: args = map(util.expandpath, shlex.split(defaults)) + args diff --git a/tests/test-alias.t b/tests/test-alias.t index 8e00906066c9f170507a582d93b4b9171fbbe3cb_dGVzdHMvdGVzdC1hbGlhcy50..e4ab5ae193f21cb02c9a06dcde1d28c5665af3d7_dGVzdHMvdGVzdC1hbGlhcy50 100644 --- a/tests/test-alias.t +++ b/tests/test-alias.t @@ -17,6 +17,7 @@ > mylog = log > lognull = log -r null > shortlog = log --template '{rev} {node|short} | {date|isodate}\n' + > positional = log --template '{\$2} {\$1} | {date|isodate}\n' > dln = lognull --debug > nousage = rollback > put = export -r 0 -o "\$FOO/%R.diff" @@ -127,6 +128,10 @@ $ hg shortlog 0 e63c23eaa88a | 1970-01-01 00:00 +0000 +positional arguments + + $ hg positional 'node|short' rev + 0 e63c23eaa88a | 1970-01-01 00:00 +0000 interaction with defaults