diff --git a/contrib/dumprevlog b/contrib/dumprevlog --- a/contrib/dumprevlog +++ b/contrib/dumprevlog @@ -8,11 +8,13 @@ import sys from mercurial import ( node, revlog, - util, +) +from mercurial.utils import ( + procutil, ) for fp in (sys.stdin, sys.stdout, sys.stderr): - util.setbinary(fp) + procutil.setbinary(fp) def binopen(path, mode='rb'): if 'b' not in mode: diff --git a/contrib/phabricator.py b/contrib/phabricator.py --- a/contrib/phabricator.py +++ b/contrib/phabricator.py @@ -66,6 +66,9 @@ from mercurial import ( url as urlmod, util, ) +from mercurial.utils import ( + procutil, +) cmdtable = {} command = registrar.command(cmdtable) @@ -161,7 +164,8 @@ def callconduit(repo, name, params): data = urlencodenested(params) curlcmd = repo.ui.config('phabricator', 'curlcmd') if curlcmd: - sin, sout = util.popen2('%s -d @- %s' % (curlcmd, util.shellquote(url))) + sin, sout = procutil.popen2('%s -d @- %s' + % (curlcmd, procutil.shellquote(url))) sin.write(data) sin.close() body = sout.read() diff --git a/contrib/simplemerge b/contrib/simplemerge --- a/contrib/simplemerge +++ b/contrib/simplemerge @@ -14,7 +14,9 @@ from mercurial import ( fancyopts, simplemerge, ui as uimod, - util, +) +from mercurial.utils import ( + procutil, ) options = [('L', 'label', [], _('labels to use on conflict markers')), @@ -52,7 +54,7 @@ def showhelp(): try: for fp in (sys.stdin, sys.stdout, sys.stderr): - util.setbinary(fp) + procutil.setbinary(fp) opts = {} try: diff --git a/contrib/undumprevlog b/contrib/undumprevlog --- a/contrib/undumprevlog +++ b/contrib/undumprevlog @@ -10,12 +10,14 @@ from mercurial import ( node, revlog, transaction, - util, vfs as vfsmod, ) +from mercurial.utils import ( + procutil, +) for fp in (sys.stdin, sys.stdout, sys.stderr): - util.setbinary(fp) + procutil.setbinary(fp) opener = vfsmod.vfs('.', False) tr = transaction.transaction(sys.stderr.write, opener, {'store': opener}, diff --git a/hgext/acl.py b/hgext/acl.py --- a/hgext/acl.py +++ b/hgext/acl.py @@ -201,6 +201,9 @@ from mercurial import ( registrar, util, ) +from mercurial.utils import ( + procutil, +) urlreq = util.urlreq @@ -338,7 +341,7 @@ def hook(ui, repo, hooktype, node=None, user = urlreq.unquote(url[3]) if user is None: - user = util.getuser() + user = procutil.getuser() ui.debug('acl: checking access for user "%s"\n' % user) diff --git a/hgext/blackbox.py b/hgext/blackbox.py --- a/hgext/blackbox.py +++ b/hgext/blackbox.py @@ -49,7 +49,10 @@ from mercurial import ( ui as uimod, util, ) -from mercurial.utils import dateutil +from mercurial.utils import ( + dateutil, + procutil, +) # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should @@ -166,8 +169,8 @@ def wrapui(ui): ui._bbinlog = True default = self.configdate('devel', 'default-date') date = dateutil.datestr(default, '%Y/%m/%d %H:%M:%S') - user = util.getuser() - pid = '%d' % util.getpid() + user = procutil.getuser() + pid = '%d' % procutil.getpid() formattedmsg = msg[0] % msg[1:] rev = '(unknown)' changed = '' diff --git a/hgext/bugzilla.py b/hgext/bugzilla.py --- a/hgext/bugzilla.py +++ b/hgext/bugzilla.py @@ -308,6 +308,7 @@ from mercurial import ( util, ) from mercurial.utils import ( + procutil, stringutil, ) @@ -527,13 +528,13 @@ class bzmysql(bzaccess): except TypeError: cmd = cmdfmt % {'bzdir': bzdir, 'id': id, 'user': user} self.ui.note(_('running notify command %s\n') % cmd) - fp = util.popen('(%s) 2>&1' % cmd) + fp = procutil.popen('(%s) 2>&1' % cmd) out = fp.read() ret = fp.close() if ret: self.ui.warn(out) raise error.Abort(_('bugzilla notify command %s') % - util.explainexit(ret)[0]) + procutil.explainexit(ret)[0]) self.ui.status(_('done\n')) def get_user_id(self, user): diff --git a/hgext/convert/common.py b/hgext/convert/common.py --- a/hgext/convert/common.py +++ b/hgext/convert/common.py @@ -22,6 +22,9 @@ from mercurial import ( pycompat, util, ) +from mercurial.utils import ( + procutil, +) pickle = util.pickle propertycache = util.propertycache @@ -96,7 +99,7 @@ class MissingTool(Exception): def checktool(exe, name=None, abort=True): name = name or exe - if not util.findexe(exe): + if not procutil.findexe(exe): if abort: exc = error.Abort else: @@ -390,7 +393,7 @@ class commandline(object): cmdline[-1] += '=' + v except TypeError: pass - cmdline = [util.shellquote(arg) for arg in cmdline] + cmdline = [procutil.shellquote(arg) for arg in cmdline] if not self.ui.debugflag: cmdline += ['2>', pycompat.bytestr(os.devnull)] cmdline = ' '.join(cmdline) @@ -399,16 +402,16 @@ class commandline(object): def _run(self, cmd, *args, **kwargs): def popen(cmdline): p = subprocess.Popen(cmdline, shell=True, bufsize=-1, - close_fds=util.closefds, - stdout=subprocess.PIPE) + close_fds=procutil.closefds, + stdout=subprocess.PIPE) return p return self._dorun(popen, cmd, *args, **kwargs) def _run2(self, cmd, *args, **kwargs): - return self._dorun(util.popen2, cmd, *args, **kwargs) + return self._dorun(procutil.popen2, cmd, *args, **kwargs) def _run3(self, cmd, *args, **kwargs): - return self._dorun(util.popen3, cmd, *args, **kwargs) + return self._dorun(procutil.popen3, cmd, *args, **kwargs) def _dorun(self, openfunc, cmd, *args, **kwargs): cmdline = self._cmdline(cmd, *args, **kwargs) @@ -437,7 +440,7 @@ class commandline(object): if output: self.ui.warn(_('%s error:\n') % self.command) self.ui.warn(output) - msg = util.explainexit(status)[0] + msg = procutil.explainexit(status)[0] raise error.Abort('%s %s' % (self.command, msg)) def run0(self, cmd, *args, **kwargs): diff --git a/hgext/convert/cvs.py b/hgext/convert/cvs.py --- a/hgext/convert/cvs.py +++ b/hgext/convert/cvs.py @@ -18,7 +18,10 @@ from mercurial import ( pycompat, util, ) -from mercurial.utils import dateutil +from mercurial.utils import ( + dateutil, + procutil, +) from . import ( common, @@ -197,9 +200,9 @@ class convert_cvs(converter_source): cmd = [rsh, host] + cmd # popen2 does not support argument lists under Windows - cmd = [util.shellquote(arg) for arg in cmd] - cmd = util.quotecommand(' '.join(cmd)) - self.writep, self.readp = util.popen2(cmd) + cmd = [procutil.shellquote(arg) for arg in cmd] + cmd = procutil.quotecommand(' '.join(cmd)) + self.writep, self.readp = procutil.popen2(cmd) self.realroot = root diff --git a/hgext/convert/cvsps.py b/hgext/convert/cvsps.py --- a/hgext/convert/cvsps.py +++ b/hgext/convert/cvsps.py @@ -19,6 +19,7 @@ from mercurial import ( ) from mercurial.utils import ( dateutil, + procutil, stringutil, ) @@ -223,11 +224,11 @@ def createlog(ui, directory=None, root=" state = 0 store = False # set when a new record can be appended - cmd = [util.shellquote(arg) for arg in cmd] + cmd = [procutil.shellquote(arg) for arg in cmd] ui.note(_("running %s\n") % (' '.join(cmd))) ui.debug("prefix=%r directory=%r root=%r\n" % (prefix, directory, root)) - pfp = util.popen(' '.join(cmd)) + pfp = procutil.popen(' '.join(cmd)) peek = pfp.readline() while True: line = peek diff --git a/hgext/convert/gnuarch.py b/hgext/convert/gnuarch.py --- a/hgext/convert/gnuarch.py +++ b/hgext/convert/gnuarch.py @@ -17,9 +17,11 @@ from mercurial.i18n import _ from mercurial import ( encoding, error, - util, ) -from mercurial.utils import dateutil +from mercurial.utils import ( + dateutil, + procutil, +) from . import common class gnuarch_source(common.converter_source, common.commandline): @@ -46,10 +48,10 @@ class gnuarch_source(common.converter_so # Could use checktool, but we want to check for baz or tla. self.execmd = None - if util.findexe('baz'): + if procutil.findexe('baz'): self.execmd = 'baz' else: - if util.findexe('tla'): + if procutil.findexe('tla'): self.execmd = 'tla' else: raise error.Abort(_('cannot find a GNU Arch tool')) @@ -195,9 +197,9 @@ class gnuarch_source(common.converter_so def _execute(self, cmd, *args, **kwargs): cmdline = [self.execmd, cmd] cmdline += args - cmdline = [util.shellquote(arg) for arg in cmdline] + cmdline = [procutil.shellquote(arg) for arg in cmdline] cmdline += ['>', os.devnull, '2>', os.devnull] - cmdline = util.quotecommand(' '.join(cmdline)) + cmdline = procutil.quotecommand(' '.join(cmdline)) self.ui.debug(cmdline, '\n') return os.system(cmdline) diff --git a/hgext/convert/p4.py b/hgext/convert/p4.py --- a/hgext/convert/p4.py +++ b/hgext/convert/p4.py @@ -16,6 +16,7 @@ from mercurial import ( ) from mercurial.utils import ( dateutil, + procutil, stringutil, ) @@ -89,8 +90,8 @@ class p4_source(common.converter_source) def _parse_view(self, path): "Read changes affecting the path" - cmd = 'p4 -G changes -s submitted %s' % util.shellquote(path) - stdout = util.popen(cmd, mode='rb') + cmd = 'p4 -G changes -s submitted %s' % procutil.shellquote(path) + stdout = procutil.popen(cmd, mode='rb') p4changes = {} for d in loaditer(stdout): c = d.get("change", None) @@ -118,8 +119,8 @@ class p4_source(common.converter_source) else: views = {"//": ""} else: - cmd = 'p4 -G client -o %s' % util.shellquote(path) - clientspec = marshal.load(util.popen(cmd, mode='rb')) + cmd = 'p4 -G client -o %s' % procutil.shellquote(path) + clientspec = marshal.load(procutil.popen(cmd, mode='rb')) views = {} for client in clientspec: @@ -198,8 +199,8 @@ class p4_source(common.converter_source) oldname = depotname[filename] flcmd = 'p4 -G filelog %s' \ - % util.shellquote(oldname) - flstdout = util.popen(flcmd, mode='rb') + % procutil.shellquote(oldname) + flstdout = procutil.popen(flcmd, mode='rb') copiedfilename = None for d in loaditer(flstdout): @@ -272,11 +273,11 @@ class p4_source(common.converter_source) def getfile(self, name, rev): cmd = 'p4 -G print %s' \ - % util.shellquote("%s#%s" % (self.depotname[name], rev)) + % procutil.shellquote("%s#%s" % (self.depotname[name], rev)) lasterror = None while True: - stdout = util.popen(cmd, mode='rb') + stdout = procutil.popen(cmd, mode='rb') mode = None contents = [] @@ -358,7 +359,7 @@ class p4_source(common.converter_source) """Return an output of `p4 describe` including author, commit date as a dictionary.""" cmd = "p4 -G describe -s %s" % rev - stdout = util.popen(cmd, mode='rb') + stdout = procutil.popen(cmd, mode='rb') return marshal.load(stdout) def getcommit(self, rev): diff --git a/hgext/convert/subversion.py b/hgext/convert/subversion.py --- a/hgext/convert/subversion.py +++ b/hgext/convert/subversion.py @@ -18,6 +18,7 @@ from mercurial import ( ) from mercurial.utils import ( dateutil, + procutil, stringutil, ) @@ -1069,9 +1070,9 @@ class svn_source(converter_source): if not self.ui.configbool('convert', 'svn.debugsvnlog'): return directlogstream(*args) arg = encodeargs(args) - hgexe = util.hgexecutable() - cmd = '%s debugsvnlog' % util.shellquote(hgexe) - stdin, stdout = util.popen2(util.quotecommand(cmd)) + hgexe = procutil.hgexecutable() + cmd = '%s debugsvnlog' % procutil.shellquote(hgexe) + stdin, stdout = procutil.popen2(procutil.quotecommand(cmd)) stdin.write(arg) try: stdin.close() diff --git a/hgext/extdiff.py b/hgext/extdiff.py --- a/hgext/extdiff.py +++ b/hgext/extdiff.py @@ -83,6 +83,7 @@ from mercurial import ( util, ) from mercurial.utils import ( + procutil, stringutil, ) @@ -280,7 +281,7 @@ def dodiff(ui, repo, cmdline, pats, opts key = match.group(3) if not do3way and key == 'parent2': return pre - return pre + util.shellquote(replace[key]) + return pre + procutil.shellquote(replace[key]) # Match parent2 first, so 'parent1?' will match both parent1 and parent regex = (br'''(['"]?)([^\s'"$]*)''' @@ -349,7 +350,7 @@ def extdiff(ui, repo, *pats, **opts): if not program: program = 'diff' option = option or ['-Npru'] - cmdline = ' '.join(map(util.shellquote, [program] + option)) + cmdline = ' '.join(map(procutil.shellquote, [program] + option)) return dodiff(ui, repo, cmdline, pats, opts) class savedcmd(object): @@ -376,7 +377,7 @@ class savedcmd(object): def __call__(self, ui, repo, *pats, **opts): opts = pycompat.byteskwargs(opts) - options = ' '.join(map(util.shellquote, opts['option'])) + options = ' '.join(map(procutil.shellquote, opts['option'])) if options: options = ' ' + options return dodiff(ui, repo, self._cmdline + options, pats, opts) @@ -387,11 +388,11 @@ def uisetup(ui): if cmd.startswith('cmd.'): cmd = cmd[4:] if not path: - path = util.findexe(cmd) + path = procutil.findexe(cmd) if path is None: path = filemerge.findexternaltool(ui, cmd) or cmd diffopts = ui.config('extdiff', 'opts.' + cmd) - cmdline = util.shellquote(path) + cmdline = procutil.shellquote(path) if diffopts: cmdline += ' ' + diffopts elif cmd.startswith('opts.'): @@ -403,10 +404,10 @@ def uisetup(ui): diffopts = len(pycompat.shlexsplit(cmdline)) > 1 else: # case "cmd =" - path = util.findexe(cmd) + path = procutil.findexe(cmd) if path is None: path = filemerge.findexternaltool(ui, cmd) or cmd - cmdline = util.shellquote(path) + cmdline = procutil.shellquote(path) diffopts = False # look for diff arguments in [diff-tools] then [merge-tools] if not diffopts: diff --git a/hgext/githelp.py b/hgext/githelp.py --- a/hgext/githelp.py +++ b/hgext/githelp.py @@ -26,7 +26,9 @@ from mercurial import ( error, fancyopts, registrar, - util, +) +from mercurial.utils import ( + procutil, ) # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for @@ -625,7 +627,7 @@ def lsfiles(ui, repo, *args, **kwargs): cmd['-0'] = None cmd.append('.') for include in args: - cmd['-I'] = util.shellquote(include) + cmd['-I'] = procutil.shellquote(include) ui.status((bytes(cmd)), "\n") diff --git a/hgext/gpg.py b/hgext/gpg.py --- a/hgext/gpg.py +++ b/hgext/gpg.py @@ -19,9 +19,11 @@ from mercurial import ( node as hgnode, pycompat, registrar, - util, ) -from mercurial.utils import dateutil +from mercurial.utils import ( + dateutil, + procutil, +) cmdtable = {} command = registrar.command(cmdtable) @@ -52,7 +54,7 @@ class gpg(object): def sign(self, data): gpgcmd = "%s --sign --detach-sign%s" % (self.path, self.key) - return util.filter(data, gpgcmd) + return procutil.filter(data, gpgcmd) def verify(self, data, sig): """ returns of the good and bad signatures""" @@ -69,7 +71,7 @@ class gpg(object): fp.close() gpgcmd = ("%s --logger-fd 1 --status-fd 1 --verify " "\"%s\" \"%s\"" % (self.path, sigfile, datafile)) - ret = util.filter("", gpgcmd) + ret = procutil.filter("", gpgcmd) finally: for f in (sigfile, datafile): try: diff --git a/hgext/journal.py b/hgext/journal.py --- a/hgext/journal.py +++ b/hgext/journal.py @@ -38,6 +38,7 @@ from mercurial import ( ) from mercurial.utils import ( dateutil, + procutil, stringutil, ) @@ -255,7 +256,7 @@ class journalstorage(object): _lockref = None def __init__(self, repo): - self.user = util.getuser() + self.user = procutil.getuser() self.ui = repo.ui self.vfs = repo.vfs @@ -272,7 +273,7 @@ class journalstorage(object): @property def command(self): commandstr = ' '.join( - map(util.shellquote, journalstorage._currentcommand)) + map(procutil.shellquote, journalstorage._currentcommand)) if '\n' in commandstr: # truncate multi-line commands commandstr = commandstr.partition('\n')[0] + ' ...' diff --git a/hgext/transplant.py b/hgext/transplant.py --- a/hgext/transplant.py +++ b/hgext/transplant.py @@ -39,6 +39,7 @@ from mercurial import ( vfs as vfsmod, ) from mercurial.utils import ( + procutil, stringutil, ) @@ -271,8 +272,9 @@ class transplanter(object): fp.close() try: - self.ui.system('%s %s %s' % (filter, util.shellquote(headerfile), - util.shellquote(patchfile)), + self.ui.system('%s %s %s' % (filter, + procutil.shellquote(headerfile), + procutil.shellquote(patchfile)), environ={'HGUSER': changelog[1], 'HGREVISION': nodemod.hex(node), }, diff --git a/mercurial/chgserver.py b/mercurial/chgserver.py --- a/mercurial/chgserver.py +++ b/mercurial/chgserver.py @@ -205,12 +205,12 @@ def _newchgui(srcui, csystem, attachio): if (out is not self.fout or not util.safehasattr(self.fout, 'fileno') or self.fout.fileno() != procutil.stdout.fileno()): - return util.system(cmd, environ=environ, cwd=cwd, out=out) + return procutil.system(cmd, environ=environ, cwd=cwd, out=out) self.flush() - return self._csystem(cmd, util.shellenviron(environ), cwd) + return self._csystem(cmd, procutil.shellenviron(environ), cwd) def _runpager(self, cmd, env=None): - self._csystem(cmd, util.shellenviron(env), type='pager', + self._csystem(cmd, procutil.shellenviron(env), type='pager', cmdtable={'attachio': attachio}) return True @@ -271,7 +271,7 @@ class channeledsystem(object): self.channel = channel def __call__(self, cmd, environ, cwd=None, type='system', cmdtable=None): - args = [type, util.quotecommand(cmd), os.path.abspath(cwd or '.')] + args = [type, procutil.quotecommand(cmd), os.path.abspath(cwd or '.')] args.extend('%s=%s' % (k, v) for k, v in environ.iteritems()) data = '\0'.join(args) self.out.write(struct.pack('>cI', self.channel, len(data))) @@ -477,12 +477,12 @@ class chgcmdserver(commandserver.server) 'setenv': setenv, 'setumask': setumask}) - if util.safehasattr(util, 'setprocname'): + if util.safehasattr(procutil, 'setprocname'): def setprocname(self): """Change process title""" name = self._readstr() _log('setprocname: %r\n' % name) - util.setprocname(name) + procutil.setprocname(name) capabilities['setprocname'] = setprocname def _tempaddress(address): diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -63,6 +63,7 @@ from . import ( ) from .utils import ( dateutil, + procutil, stringutil, ) @@ -2316,9 +2317,9 @@ def _dograft(ui, repo, *revs, **opts): repo.vfs.write('graftstate', ''.join(nodelines)) extra = '' if opts.get('user'): - extra += ' --user %s' % util.shellquote(opts['user']) + extra += ' --user %s' % procutil.shellquote(opts['user']) if opts.get('date'): - extra += ' --date %s' % util.shellquote(opts['date']) + extra += ' --date %s' % procutil.shellquote(opts['date']) if opts.get('log'): extra += ' --log' hint=_("use 'hg resolve' and 'hg graft --continue%s'") % extra diff --git a/mercurial/commandserver.py b/mercurial/commandserver.py --- a/mercurial/commandserver.py +++ b/mercurial/commandserver.py @@ -288,7 +288,7 @@ class server(object): hellomsg += '\n' hellomsg += 'encoding: ' + encoding.encoding hellomsg += '\n' - hellomsg += 'pid: %d' % util.getpid() + hellomsg += 'pid: %d' % procutil.getpid() if util.safehasattr(os, 'getpgid'): hellomsg += '\n' hellomsg += 'pgid: %d' % os.getpgid(0) @@ -457,8 +457,8 @@ class unixforkingservice(object): def init(self): self._sock = socket.socket(socket.AF_UNIX) self._servicehandler.bindsocket(self._sock, self.address) - if util.safehasattr(util, 'unblocksignal'): - util.unblocksignal(signal.SIGCHLD) + if util.safehasattr(procutil, 'unblocksignal'): + procutil.unblocksignal(signal.SIGCHLD) o = signal.signal(signal.SIGCHLD, self._sigchldhandler) self._oldsigchldhandler = o self._socketunlinked = False diff --git a/mercurial/debugcommands.py b/mercurial/debugcommands.py --- a/mercurial/debugcommands.py +++ b/mercurial/debugcommands.py @@ -83,6 +83,7 @@ from . import ( ) from .utils import ( dateutil, + procutil, stringutil, ) @@ -1254,9 +1255,9 @@ def debuginstall(ui, **opts): # editor editor = ui.geteditor() editor = util.expandpath(editor) - editorbin = util.shellsplit(editor)[0] + editorbin = procutil.shellsplit(editor)[0] fm.write('editor', _("checking commit editor... (%s)\n"), editorbin) - cmdpath = util.findexe(editorbin) + cmdpath = procutil.findexe(editorbin) fm.condwrite(not cmdpath and editor == 'vi', 'vinotfound', _(" No commit editor set and can't find %s in PATH\n" " (specify a commit editor in your configuration" @@ -2813,7 +2814,7 @@ def debugwireproto(ui, repo, path=None, # We start the SSH server in its own process so there is process # separation. This prevents a whole class of potential bugs around # shared state from interfering with server operation. - args = util.hgcmd() + [ + args = procutil.hgcmd() + [ '-R', repo.root, 'debugserve', '--sshstdio', ] diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py --- a/mercurial/dispatch.py +++ b/mercurial/dispatch.py @@ -137,7 +137,7 @@ if pycompat.ispy3: else: def _initstdio(): for fp in (sys.stdin, sys.stdout, sys.stderr): - util.setbinary(fp) + procutil.setbinary(fp) def _silencestdio(): pass @@ -172,7 +172,7 @@ def _formatparse(write, inst): write(_("(%s)\n") % inst.hint) def _formatargs(args): - return ' '.join(util.shellquote(a) for a in args) + return ' '.join(procutil.shellquote(a) for a in args) def dispatch(req): "run the command specified in req.args" @@ -413,7 +413,7 @@ def aliasargs(fn, givenargs): if not util.safehasattr(fn, '_origfunc'): args = getattr(fn, 'args', args) if args: - cmd = ' '.join(map(util.shellquote, args)) + cmd = ' '.join(map(procutil.shellquote, args)) nums = [] def replacer(m): @@ -443,7 +443,7 @@ def aliasinterpolate(name, args, cmd): # parameters, separated out into words. Emulate the same behavior here by # quoting the arguments individually. POSIX shells will then typically # tokenize each argument into exactly one word. - replacemap['"$@"'] = ' '.join(util.shellquote(arg) for arg in args) + replacemap['"$@"'] = ' '.join(procutil.shellquote(arg) for arg in args) # escape '\$' for regex regex = '|'.join(replacemap.keys()).replace('$', br'\$') r = re.compile(regex) diff --git a/mercurial/filemerge.py b/mercurial/filemerge.py --- a/mercurial/filemerge.py +++ b/mercurial/filemerge.py @@ -32,6 +32,7 @@ from . import ( ) from .utils import ( + procutil, stringutil, ) @@ -122,11 +123,11 @@ def findexternaltool(ui, tool): continue p = util.lookupreg(k, _toolstr(ui, tool, "regname")) if p: - p = util.findexe(p + _toolstr(ui, tool, "regappend", "")) + p = procutil.findexe(p + _toolstr(ui, tool, "regappend", "")) if p: return p exe = _toolstr(ui, tool, "executable", tool) - return util.findexe(util.expandpath(exe)) + return procutil.findexe(util.expandpath(exe)) def _picktool(repo, ui, path, binary, symlink, changedelete): def supportscd(tool): @@ -149,7 +150,7 @@ def _picktool(repo, ui, path, binary, sy # the nomerge tools are the only tools that support change/delete # conflicts pass - elif not util.gui() and _toolbool(ui, tool, "gui"): + elif not procutil.gui() and _toolbool(ui, tool, "gui"): ui.warn(_("tool %s requires a GUI\n") % tmsg) else: return True @@ -164,7 +165,7 @@ def _picktool(repo, ui, path, binary, sy return ":prompt", None else: if toolpath: - return (force, util.shellquote(toolpath)) + return (force, procutil.shellquote(toolpath)) else: # mimic HGMERGE if given tool not found return (force, force) @@ -182,7 +183,7 @@ def _picktool(repo, ui, path, binary, sy mf = match.match(repo.root, '', [pat]) if mf(path) and check(tool, pat, symlink, False, changedelete): toolpath = _findtool(ui, tool) - return (tool, util.shellquote(toolpath)) + return (tool, procutil.shellquote(toolpath)) # then merge tools tools = {} @@ -207,7 +208,7 @@ def _picktool(repo, ui, path, binary, sy for p, t in tools: if check(t, None, symlink, binary, changedelete): toolpath = _findtool(ui, t) - return (t, util.shellquote(toolpath)) + return (t, procutil.shellquote(toolpath)) # internal merge or prompt as last resort if symlink or binary or changedelete: @@ -547,8 +548,9 @@ def _xmerge(repo, mynode, orig, fcd, fco replace = {'local': localpath, 'base': basepath, 'other': otherpath, 'output': outpath, 'labellocal': mylabel, 'labelother': otherlabel, 'labelbase': baselabel} - args = util.interpolate(br'\$', replace, args, - lambda s: util.shellquote(util.localpath(s))) + args = util.interpolate( + br'\$', replace, args, + lambda s: procutil.shellquote(util.localpath(s))) cmd = toolpath + ' ' + args if _toolbool(ui, tool, "gui"): repo.ui.status(_('running merge tool %s for file %s\n') % diff --git a/mercurial/hgweb/__init__.py b/mercurial/hgweb/__init__.py --- a/mercurial/hgweb/__init__.py +++ b/mercurial/hgweb/__init__.py @@ -15,7 +15,10 @@ from ..i18n import _ from .. import ( error, pycompat, - util, +) + +from ..utils import ( + procutil, ) from . import ( @@ -51,7 +54,7 @@ class httpservice(object): self.opts = opts def init(self): - util.setsignalhandler() + procutil.setsignalhandler() self.httpd = server.create_server(self.ui, self.app) if self.opts['port'] and not self.ui.verbose: diff --git a/mercurial/hgweb/wsgicgi.py b/mercurial/hgweb/wsgicgi.py --- a/mercurial/hgweb/wsgicgi.py +++ b/mercurial/hgweb/wsgicgi.py @@ -12,7 +12,6 @@ from __future__ import absolute_import from .. import ( encoding, - util, ) from ..utils import ( @@ -24,8 +23,8 @@ from . import ( ) def launch(application): - util.setbinary(procutil.stdin) - util.setbinary(procutil.stdout) + procutil.setbinary(procutil.stdin) + procutil.setbinary(procutil.stdout) environ = dict(encoding.environ.iteritems()) environ.setdefault(r'PATH_INFO', '') diff --git a/mercurial/hook.py b/mercurial/hook.py --- a/mercurial/hook.py +++ b/mercurial/hook.py @@ -44,7 +44,7 @@ def _pythonhook(ui, repo, htype, hname, % (hname, funcname)) modname = funcname[:d] oldpaths = sys.path - if util.mainfrozen(): + if procutil.mainfrozen(): # binary installs require sys.path manipulation modpath, modfile = os.path.split(modname) if modpath and modfile: @@ -154,7 +154,7 @@ def _exthook(ui, repo, htype, name, cmd, ui.log('exthook', 'exthook-%s: %s finished in %0.2f seconds\n', name, cmd, duration) if r: - desc, r = util.explainexit(r) + desc, r = procutil.explainexit(r) if throw: raise error.HookAbort(_('%s hook %s') % (name, desc)) ui.warn(_('warning: %s hook %s\n') % (name, desc)) diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py --- a/mercurial/localrepo.py +++ b/mercurial/localrepo.py @@ -65,6 +65,7 @@ from . import ( vfs as vfsmod, ) from .utils import ( + procutil, stringutil, ) @@ -1106,7 +1107,7 @@ class localrepository(object): params = cmd[len(name):].lstrip() break if not fn: - fn = lambda s, c, **kwargs: util.filter(s, c) + fn = lambda s, c, **kwargs: procutil.filter(s, c) # Wrap old filters not supporting keyword arguments if not pycompat.getargspec(fn)[2]: oldfn = fn diff --git a/mercurial/lock.py b/mercurial/lock.py --- a/mercurial/lock.py +++ b/mercurial/lock.py @@ -21,7 +21,10 @@ from . import ( encoding, error, pycompat, - util, +) + +from .utils import ( + procutil, ) def _getlockprefix(): @@ -212,8 +215,8 @@ class lock(object): self.release() def _getpid(self): - # wrapper around util.getpid() to make testing easier - return util.getpid() + # wrapper around procutil.getpid() to make testing easier + return procutil.getpid() def lock(self): timeout = self.timeout @@ -299,7 +302,7 @@ class lock(object): pid = int(pid) except ValueError: return locker - if util.testpid(pid): + if procutil.testpid(pid): return locker # if locker dead, break lock. must do this with another lock # held, or can race and break valid lock. diff --git a/mercurial/mail.py b/mercurial/mail.py --- a/mercurial/mail.py +++ b/mercurial/mail.py @@ -25,6 +25,7 @@ from . import ( util, ) from .utils import ( + procutil, stringutil, ) @@ -143,13 +144,13 @@ def _sendmail(ui, sender, recipients, ms cmdline = '%s -f %s %s' % (program, stringutil.email(sender), ' '.join(map(stringutil.email, recipients))) ui.note(_('sending mail: %s\n') % cmdline) - fp = util.popen(cmdline, 'w') + fp = procutil.popen(cmdline, 'w') fp.write(msg) ret = fp.close() if ret: raise error.Abort('%s %s' % ( os.path.basename(program.split(None, 1)[0]), - util.explainexit(ret)[0])) + procutil.explainexit(ret)[0])) def _mbox(mbox, sender, recipients, msg): '''write mails to mbox''' @@ -184,7 +185,7 @@ def validateconfig(ui): raise error.Abort(_('smtp specified as email transport, ' 'but no smtp host configured')) else: - if not util.findexe(method): + if not procutil.findexe(method): raise error.Abort(_('%r specified as email transport, ' 'but not in PATH') % method) diff --git a/mercurial/patch.py b/mercurial/patch.py --- a/mercurial/patch.py +++ b/mercurial/patch.py @@ -42,6 +42,7 @@ from . import ( ) from .utils import ( dateutil, + procutil, stringutil, ) @@ -2100,9 +2101,9 @@ def _externalpatch(ui, repo, patcher, pa args = [] cwd = repo.root if cwd: - args.append('-d %s' % util.shellquote(cwd)) - fp = util.popen('%s %s -p%d < %s' % (patcher, ' '.join(args), strip, - util.shellquote(patchname))) + args.append('-d %s' % procutil.shellquote(cwd)) + fp = procutil.popen('%s %s -p%d < %s' % (patcher, ' '.join(args), strip, + procutil.shellquote(patchname))) try: for line in util.iterfile(fp): line = line.rstrip() @@ -2130,7 +2131,7 @@ def _externalpatch(ui, repo, patcher, pa code = fp.close() if code: raise PatchError(_("patch command failed: %s") % - util.explainexit(code)[0]) + procutil.explainexit(code)[0]) return fuzz def patchbackend(ui, backend, patchobj, strip, prefix, files=None, diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py --- a/mercurial/scmutil.py +++ b/mercurial/scmutil.py @@ -42,6 +42,7 @@ from . import ( ) from .utils import ( + procutil, stringutil, ) @@ -293,7 +294,7 @@ def checkportable(ui, f): if abort or warn: msg = util.checkwinfilename(f) if msg: - msg = "%s: %s" % (msg, util.shellquote(f)) + msg = "%s: %s" % (msg, procutil.shellquote(f)) if abort: raise error.Abort(msg) ui.warn(_("warning: %s\n") % msg) @@ -1090,7 +1091,7 @@ def extdatasource(repo, source): # external commands should be run relative to the repo root cmd = spec[6:] proc = subprocess.Popen(cmd, shell=True, bufsize=-1, - close_fds=util.closefds, + close_fds=procutil.closefds, stdout=subprocess.PIPE, cwd=repo.root) src = proc.stdout else: @@ -1114,7 +1115,7 @@ def extdatasource(repo, source): src.close() if proc and proc.returncode != 0: raise error.Abort(_("extdata command '%s' failed: %s") - % (cmd, util.explainexit(proc.returncode)[0])) + % (cmd, procutil.explainexit(proc.returncode)[0])) return data diff --git a/mercurial/server.py b/mercurial/server.py --- a/mercurial/server.py +++ b/mercurial/server.py @@ -46,7 +46,7 @@ def runservice(opts, parentfn=None, init os.close(lockfd) try: if not runargs: - runargs = util.hgcmd() + pycompat.sysargv[1:] + runargs = procutil.hgcmd() + pycompat.sysargv[1:] runargs.append('--daemon-postexec=unlink:%s' % lockpath) # Don't pass --cwd to the child process, because we've already # changed directory. @@ -59,7 +59,7 @@ def runservice(opts, parentfn=None, init break def condfn(): return not os.path.exists(lockpath) - pid = util.rundetached(runargs, condfn) + pid = procutil.rundetached(runargs, condfn) if pid < 0: raise error.Abort(_('child process failed to start')) writepid(pid) @@ -74,7 +74,7 @@ def runservice(opts, parentfn=None, init initfn() if not opts['daemon']: - writepid(util.getpid()) + writepid(procutil.getpid()) if opts['daemon_postexec']: try: @@ -90,7 +90,7 @@ def runservice(opts, parentfn=None, init elif inst != 'none': raise error.Abort(_('invalid value for --daemon-postexec: %s') % inst) - util.hidewindow() + procutil.hidewindow() procutil.stdout.flush() procutil.stderr.flush() diff --git a/mercurial/sshpeer.py b/mercurial/sshpeer.py --- a/mercurial/sshpeer.py +++ b/mercurial/sshpeer.py @@ -19,6 +19,9 @@ from . import ( wireprotoserver, wireprototypes, ) +from .utils import ( + procutil, +) def _serverquote(s): """quote a string for the remote shell ... which we assume is sh""" @@ -33,7 +36,7 @@ def _forwardoutput(ui, pipe): This is non blocking.""" if pipe: - s = util.readpipe(pipe) + s = procutil.readpipe(pipe) if s: for l in s.splitlines(): ui.status(_("remote: "), l, '\n') @@ -147,16 +150,16 @@ def _makeconnection(ui, sshcmd, args, re cmd = '%s %s %s' % ( sshcmd, args, - util.shellquote('%s -R %s serve --stdio' % ( + procutil.shellquote('%s -R %s serve --stdio' % ( _serverquote(remotecmd), _serverquote(path)))) ui.debug('running %s\n' % cmd) - cmd = util.quotecommand(cmd) + cmd = procutil.quotecommand(cmd) # no buffer allow the use of 'select' # feel free to remove buffering and select usage when we ultimately # move to threading. - stdin, stdout, stderr, proc = util.popen4(cmd, bufsize=0, env=sshenv) + stdin, stdout, stderr, proc = procutil.popen4(cmd, bufsize=0, env=sshenv) return proc, stdin, stdout, stderr @@ -593,14 +596,14 @@ def instance(ui, path, create): sshcmd = ui.config('ui', 'ssh') remotecmd = ui.config('ui', 'remotecmd') sshaddenv = dict(ui.configitems('sshenv')) - sshenv = util.shellenviron(sshaddenv) + sshenv = procutil.shellenviron(sshaddenv) remotepath = u.path or '.' - args = util.sshargs(sshcmd, u.host, u.user, u.port) + args = procutil.sshargs(sshcmd, u.host, u.user, u.port) if create: cmd = '%s %s %s' % (sshcmd, args, - util.shellquote('%s init %s' % + procutil.shellquote('%s init %s' % (_serverquote(remotecmd), _serverquote(remotepath)))) ui.debug('running %s\n' % cmd) res = ui.system(cmd, blockedtag='sshpeer', environ=sshenv) diff --git a/mercurial/sslutil.py b/mercurial/sslutil.py --- a/mercurial/sslutil.py +++ b/mercurial/sslutil.py @@ -22,6 +22,7 @@ from . import ( util, ) from .utils import ( + procutil, stringutil, ) @@ -686,7 +687,7 @@ def _plainapplepython(): for using system certificate store CAs in addition to the provided cacerts file """ - if (not pycompat.isdarwin or util.mainfrozen() or + if (not pycompat.isdarwin or procutil.mainfrozen() or not pycompat.sysexecutable): return False exe = os.path.realpath(pycompat.sysexecutable).lower() diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py --- a/mercurial/subrepo.py +++ b/mercurial/subrepo.py @@ -38,6 +38,7 @@ from . import ( ) from .utils import ( dateutil, + procutil, stringutil, ) @@ -912,7 +913,7 @@ class svnsubrepo(abstractsubrepo): def __init__(self, ctx, path, state, allowcreate): super(svnsubrepo, self).__init__(ctx, path) self._state = state - self._exe = util.findexe('svn') + self._exe = procutil.findexe('svn') if not self._exe: raise error.Abort(_("'svn' executable not found for subrepo '%s'") % self._path) @@ -942,7 +943,7 @@ class svnsubrepo(abstractsubrepo): env['LANG'] = lc_all del env['LC_ALL'] env['LC_MESSAGES'] = 'C' - p = subprocess.Popen(cmd, bufsize=-1, close_fds=util.closefds, + p = subprocess.Popen(cmd, bufsize=-1, close_fds=procutil.closefds, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True, env=env, **extrakw) stdout, stderr = p.communicate() @@ -1260,7 +1261,7 @@ class gitsubrepo(abstractsubrepo): # the end of git diff arguments is used for paths commands.insert(1, '--color') p = subprocess.Popen([self._gitexecutable] + commands, bufsize=-1, - cwd=cwd, env=env, close_fds=util.closefds, + cwd=cwd, env=env, close_fds=procutil.closefds, stdout=subprocess.PIPE, stderr=errpipe) if stream: return p.stdout, None diff --git a/mercurial/ui.py b/mercurial/ui.py --- a/mercurial/ui.py +++ b/mercurial/ui.py @@ -808,7 +808,7 @@ class ui(object): user = self.prompt(_("enter a commit username:"), default=None) if user is None and not self.interactive(): try: - user = '%s@%s' % (util.getuser(), + user = '%s@%s' % (procutil.getuser(), encoding.strtolocal(socket.getfqdn())) self.warn(_("no username found, using '%s' instead\n") % user) except KeyError: @@ -992,7 +992,7 @@ class ui(object): def _isatty(self, fh): if self.configbool('ui', 'nontty'): return False - return util.isatty(fh) + return procutil.isatty(fh) def disablepager(self): self._disablepager = True @@ -1088,7 +1088,7 @@ class ui(object): # user so we can also get sane bad PAGER behavior. MSYS has # `more.exe`, so do a cmd.exe style resolution of the executable to # determine which one to use. - fullcmd = util.findexe(command) + fullcmd = procutil.findexe(command) if not fullcmd: self.warn(_("missing pager command '%s', skipping pager\n") % command) @@ -1099,9 +1099,9 @@ class ui(object): try: pager = subprocess.Popen( command, shell=shell, bufsize=-1, - close_fds=util.closefds, stdin=subprocess.PIPE, + close_fds=procutil.closefds, stdin=subprocess.PIPE, stdout=procutil.stdout, stderr=procutil.stderr, - env=util.shellenviron(env)) + env=procutil.shellenviron(env)) except OSError as e: if e.errno == errno.ENOENT and not shell: self.warn(_("missing pager command '%s', skipping pager\n") @@ -1277,7 +1277,8 @@ class ui(object): # we use rawinput() only if call_readline() will be invoked by # PyOS_Readline(), so no I/O will be made at Python layer. usereadline = (self._isatty(self.fin) and self._isatty(self.fout) - and util.isstdin(self.fin) and util.isstdout(self.fout)) + and procutil.isstdin(self.fin) + and procutil.isstdout(self.fout)) if usereadline: try: # magically add command line editing support, where @@ -1504,7 +1505,7 @@ class ui(object): rc = self._runsystem(cmd, environ=environ, cwd=cwd, out=out) if rc and onerr: errmsg = '%s %s' % (os.path.basename(cmd.split(None, 1)[0]), - util.explainexit(rc)[0]) + procutil.explainexit(rc)[0]) if errprefix: errmsg = '%s: %s' % (errprefix, errmsg) raise onerr(errmsg) @@ -1513,7 +1514,7 @@ class ui(object): def _runsystem(self, cmd, environ, cwd, out): """actually execute the given shell command (can be overridden by extensions like chg)""" - return util.system(cmd, environ=environ, cwd=cwd, out=out) + return procutil.system(cmd, environ=environ, cwd=cwd, out=out) def traceback(self, exc=None, force=False): '''print exception traceback if traceback printing enabled or forced. diff --git a/mercurial/wireprotoserver.py b/mercurial/wireprotoserver.py --- a/mercurial/wireprotoserver.py +++ b/mercurial/wireprotoserver.py @@ -22,6 +22,9 @@ from . import ( wireprotoframing, wireprototypes, ) +from .utils import ( + procutil, +) stringio = util.stringio @@ -1030,8 +1033,8 @@ class sshserver(object): ui.fout = repo.ui.fout = ui.ferr # Prevent insertion/deletion of CRs - util.setbinary(self._fin) - util.setbinary(self._fout) + procutil.setbinary(self._fin) + procutil.setbinary(self._fout) def serve_forever(self): self.serveuntil(threading.Event()) diff --git a/tests/mockblackbox.py b/tests/mockblackbox.py --- a/tests/mockblackbox.py +++ b/tests/mockblackbox.py @@ -1,6 +1,6 @@ from __future__ import absolute_import -from mercurial import ( - util, +from mercurial.utils import ( + procutil, ) # XXX: we should probably offer a devel option to do this in blackbox directly @@ -11,5 +11,5 @@ def getpid(): # mock the date and user apis so the output is always the same def uisetup(ui): - util.getuser = getuser - util.getpid = getpid + procutil.getuser = getuser + procutil.getpid = getpid diff --git a/tests/test-acl.t b/tests/test-acl.t --- a/tests/test-acl.t +++ b/tests/test-acl.t @@ -23,11 +23,12 @@ > cat > posixgetuser.py <<'EOF' > import getpass - > from mercurial import pycompat, util + > from mercurial import pycompat + > from mercurial.utils import procutil > def posixgetuser(): > return pycompat.fsencode(getpass.getuser()) > if not pycompat.isposix: - > util.getuser = posixgetuser # forcibly trust $LOGNAME + > procutil.getuser = posixgetuser # forcibly trust $LOGNAME > EOF > init_config() diff --git a/tests/test-annotate.t b/tests/test-annotate.t --- a/tests/test-annotate.t +++ b/tests/test-annotate.t @@ -910,9 +910,9 @@ Annotate with orphaned CR (issue5798) $ cat <<'EOF' >> "$TESTTMP/substcr.py" > import sys - > from mercurial import util - > util.setbinary(sys.stdin) - > util.setbinary(sys.stdout) + > from mercurial.utils import procutil + > procutil.setbinary(sys.stdin) + > procutil.setbinary(sys.stdout) > stdin = getattr(sys.stdin, 'buffer', sys.stdin) > stdout = getattr(sys.stdout, 'buffer', sys.stdout) > stdout.write(stdin.read().replace(b'\r', b'[CR]')) diff --git a/tests/test-journal-share.t b/tests/test-journal-share.t --- a/tests/test-journal-share.t +++ b/tests/test-journal-share.t @@ -1,9 +1,10 @@ Journal extension test: tests the share extension support $ cat >> testmocks.py << EOF - > # mock out util.getuser() and util.makedate() to supply testable values + > # mock out procutil.getuser() and util.makedate() to supply testable values > import os > from mercurial import util + > from mercurial.utils import procutil > def mockgetuser(): > return 'foobar' > @@ -18,7 +19,7 @@ Journal extension test: tests the share > timef.write(str(time)) > return (time, 0) > - > util.getuser = mockgetuser + > procutil.getuser = mockgetuser > util.makedate = mockmakedate > EOF diff --git a/tests/test-journal.t b/tests/test-journal.t --- a/tests/test-journal.t +++ b/tests/test-journal.t @@ -1,10 +1,10 @@ Tests for the journal extension; records bookmark locations. $ cat >> testmocks.py << EOF - > # mock out util.getuser() and util.makedate() to supply testable values + > # mock out procutil.getuser() and util.makedate() to supply testable values > import os > from mercurial import util - > from mercurial.utils import dateutil + > from mercurial.utils import dateutil, procutil > def mockgetuser(): > return 'foobar' > @@ -19,7 +19,7 @@ Tests for the journal extension; records > timef.write(str(time)) > return (time, 0) > - > util.getuser = mockgetuser + > procutil.getuser = mockgetuser > dateutil.makedate = mockmakedate > EOF diff --git a/tests/test-sshserver.py b/tests/test-sshserver.py --- a/tests/test-sshserver.py +++ b/tests/test-sshserver.py @@ -6,11 +6,14 @@ import unittest import silenttestrunner from mercurial import ( - util, wireproto, wireprotoserver, ) +from mercurial.utils import ( + procutil, +) + class SSHServerGetArgsTests(unittest.TestCase): def testparseknown(self): tests = [ @@ -46,5 +49,5 @@ class mockui(object): if __name__ == '__main__': # Don't call into msvcrt to set BytesIO to binary mode - util.setbinary = lambda fp: True + procutil.setbinary = lambda fp: True silenttestrunner.main(__name__)