diff mercurial/dispatch.py @ 13392:777cef34a890

dispatch: support for $ escaping in shell-alias definition Sigils in shell-alias can be escaped by doubling them.
author Roman Sokolov <sokolov.r.v@gmail.com>
date Fri, 11 Feb 2011 03:32:40 +0300
parents d747774ca9da
children d38d500deb08
line wrap: on
line diff
--- a/mercurial/dispatch.py	Fri Jan 28 13:38:34 2011 +0100
+++ b/mercurial/dispatch.py	Fri Feb 11 03:32:40 2011 +0300
@@ -221,15 +221,17 @@
             def fn(ui, *args):
                 env = {'HG_ARGS': ' '.join((self.name,) + args)}
                 def _checkvar(m):
-                    if int(m.groups()[0]) <= len(args):
+                    if m.groups()[0] == '$':
+                        return m.group()
+                    elif int(m.groups()[0]) <= len(args):
                         return m.group()
                     else:
                         return ''
-                cmd = re.sub(r'\$(\d+)', _checkvar, self.definition[1:])
+                cmd = re.sub(r'\$(\d+|\$)', _checkvar, self.definition[1:])
                 replace = dict((str(i + 1), arg) for i, arg in enumerate(args))
                 replace['0'] = self.name
                 replace['@'] = ' '.join(args)
-                cmd = util.interpolate(r'\$', replace, cmd)
+                cmd = util.interpolate(r'\$', replace, cmd, escape_prefix=True)
                 return util.system(cmd, environ=env)
             self.fn = fn
             return