mercurial/dispatch.py
changeset 37120 a8a902d7176e
parent 37119 d4a2e0d5d042
child 37134 6890b7e991a4
equal deleted inserted replaced
37119:d4a2e0d5d042 37120:a8a902d7176e
   135             except IOError:
   135             except IOError:
   136                 pass
   136                 pass
   137 else:
   137 else:
   138     def _initstdio():
   138     def _initstdio():
   139         for fp in (sys.stdin, sys.stdout, sys.stderr):
   139         for fp in (sys.stdin, sys.stdout, sys.stderr):
   140             util.setbinary(fp)
   140             procutil.setbinary(fp)
   141 
   141 
   142     def _silencestdio():
   142     def _silencestdio():
   143         pass
   143         pass
   144 
   144 
   145 def _getsimilar(symbols, value):
   145 def _getsimilar(symbols, value):
   170         _reportsimilar(write, similar)
   170         _reportsimilar(write, similar)
   171     if inst.hint:
   171     if inst.hint:
   172         write(_("(%s)\n") % inst.hint)
   172         write(_("(%s)\n") % inst.hint)
   173 
   173 
   174 def _formatargs(args):
   174 def _formatargs(args):
   175     return ' '.join(util.shellquote(a) for a in args)
   175     return ' '.join(procutil.shellquote(a) for a in args)
   176 
   176 
   177 def dispatch(req):
   177 def dispatch(req):
   178     "run the command specified in req.args"
   178     "run the command specified in req.args"
   179     if req.ferr:
   179     if req.ferr:
   180         ferr = req.ferr
   180         ferr = req.ferr
   411     args = []
   411     args = []
   412     # only care about alias 'args', ignore 'args' set by extensions.wrapfunction
   412     # only care about alias 'args', ignore 'args' set by extensions.wrapfunction
   413     if not util.safehasattr(fn, '_origfunc'):
   413     if not util.safehasattr(fn, '_origfunc'):
   414         args = getattr(fn, 'args', args)
   414         args = getattr(fn, 'args', args)
   415     if args:
   415     if args:
   416         cmd = ' '.join(map(util.shellquote, args))
   416         cmd = ' '.join(map(procutil.shellquote, args))
   417 
   417 
   418         nums = []
   418         nums = []
   419         def replacer(m):
   419         def replacer(m):
   420             num = int(m.group(1)) - 1
   420             num = int(m.group(1)) - 1
   421             nums.append(num)
   421             nums.append(num)
   441     replacemap['$@'] = ' '.join(args)
   441     replacemap['$@'] = ' '.join(args)
   442     # Typical Unix shells interpolate "$@" (with quotes) as all the positional
   442     # Typical Unix shells interpolate "$@" (with quotes) as all the positional
   443     # parameters, separated out into words. Emulate the same behavior here by
   443     # parameters, separated out into words. Emulate the same behavior here by
   444     # quoting the arguments individually. POSIX shells will then typically
   444     # quoting the arguments individually. POSIX shells will then typically
   445     # tokenize each argument into exactly one word.
   445     # tokenize each argument into exactly one word.
   446     replacemap['"$@"'] = ' '.join(util.shellquote(arg) for arg in args)
   446     replacemap['"$@"'] = ' '.join(procutil.shellquote(arg) for arg in args)
   447     # escape '\$' for regex
   447     # escape '\$' for regex
   448     regex = '|'.join(replacemap.keys()).replace('$', br'\$')
   448     regex = '|'.join(replacemap.keys()).replace('$', br'\$')
   449     r = re.compile(regex)
   449     r = re.compile(regex)
   450     return r.sub(lambda x: replacemap[x.group()], cmd)
   450     return r.sub(lambda x: replacemap[x.group()], cmd)
   451 
   451