changeset 37084:f0b6fbea00cf

stringutil: bulk-replace call sites to point to new module This might conflict with other patches floating around, sorry.
author Yuya Nishihara <yuya@tcha.org>
date Thu, 22 Mar 2018 21:56:20 +0900
parents f99d64e8a4e4
children 7ae6e3529e37
files hgext/bugzilla.py hgext/convert/cvsps.py hgext/convert/p4.py hgext/convert/subversion.py hgext/eol.py hgext/extdiff.py hgext/highlight/highlight.py hgext/histedit.py hgext/journal.py hgext/keyword.py hgext/largefiles/remotestore.py hgext/lfs/wrapper.py hgext/mq.py hgext/narrow/narrowbundle2.py hgext/notify.py hgext/relink.py hgext/shelve.py hgext/transplant.py hgext/win32text.py mercurial/branchmap.py mercurial/bundle2.py mercurial/changegroup.py mercurial/changelog.py mercurial/cmdutil.py mercurial/color.py mercurial/commands.py mercurial/context.py mercurial/crecord.py mercurial/dagparser.py mercurial/debugcommands.py mercurial/dispatch.py mercurial/exchange.py mercurial/extensions.py mercurial/filemerge.py mercurial/fileset.py mercurial/hg.py mercurial/hgweb/webcommands.py mercurial/hgweb/webutil.py mercurial/localrepo.py mercurial/logcmdutil.py mercurial/mail.py mercurial/match.py mercurial/minirst.py mercurial/parser.py mercurial/patch.py mercurial/repair.py mercurial/revlog.py mercurial/revset.py mercurial/revsetlang.py mercurial/scmutil.py mercurial/simplemerge.py mercurial/sslutil.py mercurial/subrepo.py mercurial/subrepoutil.py mercurial/tags.py mercurial/templatefilters.py mercurial/templatekw.py mercurial/templater.py mercurial/templateutil.py mercurial/ui.py mercurial/url.py mercurial/util.py mercurial/wireproto.py mercurial/wireprotoframing.py tests/test-simplemerge.py
diffstat 65 files changed, 414 insertions(+), 198 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/bugzilla.py	Thu Mar 22 21:19:31 2018 +0900
+++ b/hgext/bugzilla.py	Thu Mar 22 21:56:20 2018 +0900
@@ -307,6 +307,9 @@
     url,
     util,
 )
+from mercurial.utils import (
+    stringutil,
+)
 
 xmlrpclib = util.xmlrpclib
 
@@ -1099,7 +1102,8 @@
                root=self.repo.root,
                webroot=webroot(self.repo.root))
         data = self.ui.popbuffer()
-        self.bzdriver.updatebug(bugid, newstate, data, util.email(ctx.user()))
+        self.bzdriver.updatebug(bugid, newstate, data,
+                                stringutil.email(ctx.user()))
 
     def notify(self, bugs, committer):
         '''ensure Bugzilla users are notified of bug change.'''
@@ -1119,6 +1123,6 @@
         if bugs:
             for bug in bugs:
                 bz.update(bug, bugs[bug], ctx)
-            bz.notify(bugs, util.email(ctx.user()))
+            bz.notify(bugs, stringutil.email(ctx.user()))
     except Exception as e:
         raise error.Abort(_('Bugzilla error: %s') % e)
--- a/hgext/convert/cvsps.py	Thu Mar 22 21:19:31 2018 +0900
+++ b/hgext/convert/cvsps.py	Thu Mar 22 21:56:20 2018 +0900
@@ -17,7 +17,10 @@
     pycompat,
     util,
 )
-from mercurial.utils import dateutil
+from mercurial.utils import (
+    dateutil,
+    stringutil,
+)
 
 pickle = util.pickle
 
@@ -452,7 +455,8 @@
             rcsmap[e.rcs.replace('/Attic/', '/')] = e.rcs
 
             if len(log) % 100 == 0:
-                ui.status(util.ellipsis('%d %s' % (len(log), e.file), 80)+'\n')
+                ui.status(stringutil.ellipsis('%d %s' % (len(log), e.file), 80)
+                          + '\n')
 
     log.sort(key=lambda x: (x.rcs, x.revision))
 
@@ -608,7 +612,7 @@
             files = set()
             if len(changesets) % 100 == 0:
                 t = '%d %s' % (len(changesets), repr(e.comment)[1:-1])
-                ui.status(util.ellipsis(t, 80) + '\n')
+                ui.status(stringutil.ellipsis(t, 80) + '\n')
 
         c.entries.append(e)
         files.add(e.file)
--- a/hgext/convert/p4.py	Thu Mar 22 21:19:31 2018 +0900
+++ b/hgext/convert/p4.py	Thu Mar 22 21:56:20 2018 +0900
@@ -14,7 +14,10 @@
     error,
     util,
 )
-from mercurial.utils import dateutil
+from mercurial.utils import (
+    dateutil,
+    stringutil,
+)
 
 from . import common
 
@@ -169,7 +172,7 @@
                 shortdesc = '**empty changelist description**'
 
             t = '%s %s' % (c.rev, repr(shortdesc)[1:-1])
-            ui.status(util.ellipsis(t, 80) + '\n')
+            ui.status(stringutil.ellipsis(t, 80) + '\n')
 
             files = []
             copies = {}
--- a/hgext/convert/subversion.py	Thu Mar 22 21:19:31 2018 +0900
+++ b/hgext/convert/subversion.py	Thu Mar 22 21:56:20 2018 +0900
@@ -16,7 +16,10 @@
     util,
     vfs as vfsmod,
 )
-from mercurial.utils import dateutil
+from mercurial.utils import (
+    dateutil,
+    stringutil,
+)
 
 from . import common
 
@@ -147,7 +150,7 @@
         # Caller may interrupt the iteration
         pickle.dump(None, fp, protocol)
     except Exception as inst:
-        pickle.dump(util.forcebytestr(inst), fp, protocol)
+        pickle.dump(stringutil.forcebytestr(inst), fp, protocol)
     else:
         pickle.dump(None, fp, protocol)
     fp.flush()
@@ -1315,7 +1318,7 @@
         fp.close()
         try:
             output = self.run0('commit',
-                               username=util.shortuser(commit.author),
+                               username=stringutil.shortuser(commit.author),
                                file=messagefile,
                                encoding='utf-8')
             try:
--- a/hgext/eol.py	Thu Mar 22 21:19:31 2018 +0900
+++ b/hgext/eol.py	Thu Mar 22 21:56:20 2018 +0900
@@ -105,6 +105,9 @@
     registrar,
     util,
 )
+from mercurial.utils import (
+    stringutil,
+)
 
 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
@@ -133,7 +136,7 @@
 
 def tolf(s, params, ui, **kwargs):
     """Filter to convert to LF EOLs."""
-    if util.binary(s):
+    if stringutil.binary(s):
         return s
     if ui.configbool('eol', 'only-consistent') and inconsistenteol(s):
         return s
@@ -144,7 +147,7 @@
 
 def tocrlf(s, params, ui, **kwargs):
     """Filter to convert to CRLF EOLs."""
-    if util.binary(s):
+    if stringutil.binary(s):
         return s
     if ui.configbool('eol', 'only-consistent') and inconsistenteol(s):
         return s
@@ -403,7 +406,7 @@
                 if fctx is None:
                     continue
                 data = fctx.data()
-                if util.binary(data):
+                if stringutil.binary(data):
                     # We should not abort here, since the user should
                     # be able to say "** = native" to automatically
                     # have all non-binary files taken care of.
--- a/hgext/extdiff.py	Thu Mar 22 21:19:31 2018 +0900
+++ b/hgext/extdiff.py	Thu Mar 22 21:56:20 2018 +0900
@@ -82,6 +82,9 @@
     scmutil,
     util,
 )
+from mercurial.utils import (
+    stringutil,
+)
 
 cmdtable = {}
 command = registrar.command(cmdtable)
@@ -367,8 +370,8 @@
     def __init__(self, path, cmdline):
         # We can't pass non-ASCII through docstrings (and path is
         # in an unknown encoding anyway)
-        docpath = util.escapestr(path)
-        self.__doc__ %= {r'path': pycompat.sysstr(util.uirepr(docpath))}
+        docpath = stringutil.escapestr(path)
+        self.__doc__ %= {r'path': pycompat.sysstr(stringutil.uirepr(docpath))}
         self._cmdline = cmdline
 
     def __call__(self, ui, repo, *pats, **opts):
--- a/hgext/highlight/highlight.py	Thu Mar 22 21:19:31 2018 +0900
+++ b/hgext/highlight/highlight.py	Thu Mar 22 21:56:20 2018 +0900
@@ -15,7 +15,10 @@
 
 from mercurial import (
     encoding,
-    util,
+)
+
+from mercurial.utils import (
+    stringutil,
 )
 
 with demandimport.deactivated():
@@ -47,7 +50,7 @@
         tmpl.cache['header'] = new_header
 
     text = fctx.data()
-    if util.binary(text):
+    if stringutil.binary(text):
         return
 
     # str.splitlines() != unicode.splitlines() because "reasons"
--- a/hgext/histedit.py	Thu Mar 22 21:19:31 2018 +0900
+++ b/hgext/histedit.py	Thu Mar 22 21:56:20 2018 +0900
@@ -209,6 +209,9 @@
     scmutil,
     util,
 )
+from mercurial.utils import (
+    stringutil,
+)
 
 pickle = util.pickle
 release = lock.release
@@ -465,7 +468,7 @@
         # (the 5 more are left for verb)
         maxlen = self.repo.ui.configint('histedit', 'linelen')
         maxlen = max(maxlen, 22) # avoid truncating hash
-        return util.ellipsis(line, maxlen)
+        return stringutil.ellipsis(line, maxlen)
 
     def tostate(self):
         """Print an action in format used by histedit state files
--- a/hgext/journal.py	Thu Mar 22 21:19:31 2018 +0900
+++ b/hgext/journal.py	Thu Mar 22 21:56:20 2018 +0900
@@ -36,7 +36,10 @@
     registrar,
     util,
 )
-from mercurial.utils import dateutil
+from mercurial.utils import (
+    dateutil,
+    stringutil,
+)
 
 cmdtable = {}
 command = registrar.command(cmdtable)
@@ -376,9 +379,9 @@
 
         """
         if namespace is not None:
-            namespace = util.stringmatcher(namespace)[-1]
+            namespace = stringutil.stringmatcher(namespace)[-1]
         if name is not None:
-            name = util.stringmatcher(name)[-1]
+            name = stringutil.stringmatcher(name)[-1]
         for entry in self:
             if namespace is not None and not namespace(entry.namespace):
                 continue
--- a/hgext/keyword.py	Thu Mar 22 21:19:31 2018 +0900
+++ b/hgext/keyword.py	Thu Mar 22 21:56:20 2018 +0900
@@ -111,7 +111,10 @@
     templatefilters,
     util,
 )
-from mercurial.utils import dateutil
+from mercurial.utils import (
+    dateutil,
+    stringutil,
+)
 
 cmdtable = {}
 command = registrar.command(cmdtable)
@@ -272,7 +275,8 @@
 
     def expand(self, path, node, data):
         '''Returns data with keywords expanded.'''
-        if not self.restrict and self.match(path) and not util.binary(data):
+        if (not self.restrict and self.match(path)
+            and not stringutil.binary(data)):
             ctx = self.linkctx(path, node)
             return self.substitute(data, path, ctx, self.rekw.sub)
         return data
@@ -304,7 +308,7 @@
                 data = self.repo.file(f).read(mf[f])
             else:
                 data = self.repo.wread(f)
-            if util.binary(data):
+            if stringutil.binary(data):
                 continue
             if expand:
                 parents = ctx.parents()
@@ -335,7 +339,7 @@
 
     def shrink(self, fname, text):
         '''Returns text with all keyword substitutions removed.'''
-        if self.match(fname) and not util.binary(text):
+        if self.match(fname) and not stringutil.binary(text):
             return _shrinktext(text, self.rekwexp.sub)
         return text
 
@@ -343,7 +347,7 @@
         '''Returns lines with keyword substitutions removed.'''
         if self.match(fname):
             text = ''.join(lines)
-            if not util.binary(text):
+            if not stringutil.binary(text):
                 return _shrinktext(text, self.rekwexp.sub).splitlines(True)
         return lines
 
--- a/hgext/largefiles/remotestore.py	Thu Mar 22 21:19:31 2018 +0900
+++ b/hgext/largefiles/remotestore.py	Thu Mar 22 21:56:20 2018 +0900
@@ -14,6 +14,10 @@
     util,
 )
 
+from mercurial.utils import (
+    stringutil,
+)
+
 from . import (
     basestore,
     lfutil,
@@ -52,7 +56,7 @@
         except IOError as e:
             raise error.Abort(
                 _('remotestore: could not open file %s: %s')
-                % (filename, util.forcebytestr(e)))
+                % (filename, stringutil.forcebytestr(e)))
 
     def _getfile(self, tmpfile, filename, hash):
         try:
@@ -61,7 +65,7 @@
             # 401s get converted to error.Aborts; everything else is fine being
             # turned into a StoreError
             raise basestore.StoreError(filename, hash, self.url,
-                                       util.forcebytestr(e))
+                                       stringutil.forcebytestr(e))
         except urlerr.urlerror as e:
             # This usually indicates a connection problem, so don't
             # keep trying with the other files... they will probably
@@ -70,7 +74,7 @@
                              (util.hidepassword(self.url), e.reason))
         except IOError as e:
             raise basestore.StoreError(filename, hash, self.url,
-                                       util.forcebytestr(e))
+                                       stringutil.forcebytestr(e))
 
         return lfutil.copyandhash(chunks, tmpfile)
 
--- a/hgext/lfs/wrapper.py	Thu Mar 22 21:19:31 2018 +0900
+++ b/hgext/lfs/wrapper.py	Thu Mar 22 21:56:20 2018 +0900
@@ -19,6 +19,10 @@
     util,
 )
 
+from mercurial.utils import (
+    stringutil,
+)
+
 from ..largefiles import lfutil
 
 from . import (
@@ -95,7 +99,7 @@
     # by default, we expect the content to be binary. however, LFS could also
     # be used for non-binary content. add a special entry for non-binary data.
     # this will be used by filectx.isbinary().
-    if not util.binary(text):
+    if not stringutil.binary(text):
         # not hg filelog metadata (affecting commit hash), no "x-hg-" prefix
         metadata['x-is-binary'] = '0'
 
--- a/hgext/mq.py	Thu Mar 22 21:19:31 2018 +0900
+++ b/hgext/mq.py	Thu Mar 22 21:56:20 2018 +0900
@@ -98,7 +98,10 @@
     util,
     vfs as vfsmod,
 )
-from mercurial.utils import dateutil
+from mercurial.utils import (
+    dateutil,
+    stringutil,
+)
 
 release = lockmod.release
 seriesopts = [('s', 'summary', None, _('print first line of patch header'))]
@@ -469,7 +472,7 @@
         self.guardsdirty = False
         # Handle mq.git as a bool with extended values
         gitmode = ui.config('mq', 'git').lower()
-        boolmode = util.parsebool(gitmode)
+        boolmode = stringutil.parsebool(gitmode)
         if boolmode is not None:
             if boolmode:
                 gitmode = 'yes'
@@ -724,7 +727,7 @@
             os.unlink(undo)
         except OSError as inst:
             self.ui.warn(_('error removing undo: %s\n') %
-                         util.forcebytestr(inst))
+                         stringutil.forcebytestr(inst))
 
     def backup(self, repo, files, copy=False):
         # backup local changes in --force case
@@ -857,7 +860,7 @@
                                   files=files, eolmode=None)
             return (True, list(files), fuzz)
         except Exception as inst:
-            self.ui.note(util.forcebytestr(inst) + '\n')
+            self.ui.note(stringutil.forcebytestr(inst) + '\n')
             if not self.ui.verbose:
                 self.ui.warn(_("patch failed, unable to continue (try -v)\n"))
             self.ui.traceback()
@@ -1917,7 +1920,7 @@
                 if self.ui.formatted():
                     width = self.ui.termwidth() - len(pfx) - len(patchname) - 2
                     if width > 0:
-                        msg = util.ellipsis(msg, width)
+                        msg = stringutil.ellipsis(msg, width)
                     else:
                         msg = ''
                 self.ui.write(patchname, label='qseries.' + state)
--- a/hgext/narrow/narrowbundle2.py	Thu Mar 22 21:19:31 2018 +0900
+++ b/hgext/narrow/narrowbundle2.py	Thu Mar 22 21:56:20 2018 +0900
@@ -29,6 +29,9 @@
     util,
     wireproto,
 )
+from mercurial.utils import (
+    stringutil,
+)
 
 NARROWCAP = 'narrow'
 _NARROWACL_SECTION = 'narrowhgacl'
@@ -449,7 +452,7 @@
         except OSError as e:
             if e.errno != errno.ENOENT:
                 ui.warn(_('error removing %s: %s\n') %
-                        (undovfs.join(undofile), util.forcebytestr(e)))
+                        (undovfs.join(undofile), stringutil.forcebytestr(e)))
 
     # Remove partial backup only if there were no exceptions
     vfs.unlink(chgrpfile)
--- a/hgext/notify.py	Thu Mar 22 21:19:31 2018 +0900
+++ b/hgext/notify.py	Thu Mar 22 21:56:20 2018 +0900
@@ -149,7 +149,10 @@
     registrar,
     util,
 )
-from mercurial.utils import dateutil
+from mercurial.utils import (
+    dateutil,
+    stringutil,
+)
 
 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
@@ -277,7 +280,7 @@
     def fixmail(self, addr):
         '''try to clean up email addresses.'''
 
-        addr = util.email(addr.strip())
+        addr = stringutil.email(addr.strip())
         if self.domain:
             a = addr.find('@localhost')
             if a != -1:
@@ -372,7 +375,7 @@
                 subject = '%s: %s' % (self.root, s)
         maxsubject = int(self.ui.config('notify', 'maxsubject'))
         if maxsubject:
-            subject = util.ellipsis(subject, maxsubject)
+            subject = stringutil.ellipsis(subject, maxsubject)
         msg['Subject'] = mail.headencode(self.ui, subject,
                                          self.charsets, self.test)
 
@@ -399,7 +402,7 @@
         else:
             self.ui.status(_('notify: sending %d subscribers %d changes\n') %
                            (len(subs), count))
-            mail.sendmail(self.ui, util.email(msg['From']),
+            mail.sendmail(self.ui, stringutil.email(msg['From']),
                           subs, msgtext, mbox=self.mbox)
 
     def diff(self, ctx, ref=None):
--- a/hgext/relink.py	Thu Mar 22 21:19:31 2018 +0900
+++ b/hgext/relink.py	Thu Mar 22 21:56:20 2018 +0900
@@ -18,6 +18,9 @@
     registrar,
     util,
 )
+from mercurial.utils import (
+    stringutil,
+)
 
 cmdtable = {}
 command = registrar.command(cmdtable)
@@ -187,7 +190,7 @@
             relinked += 1
             savedbytes += sz
         except OSError as inst:
-            ui.warn('%s: %s\n' % (tgt, util.forcebytestr(inst)))
+            ui.warn('%s: %s\n' % (tgt, stringutil.forcebytestr(inst)))
 
     ui.progress(_('relinking'), None)
 
--- a/hgext/shelve.py	Thu Mar 22 21:19:31 2018 +0900
+++ b/hgext/shelve.py	Thu Mar 22 21:56:20 2018 +0900
@@ -56,7 +56,10 @@
 from . import (
     rebase,
 )
-from mercurial.utils import dateutil
+from mercurial.utils import (
+    dateutil,
+    stringutil,
+)
 
 cmdtable = {}
 command = registrar.command(cmdtable)
@@ -477,7 +480,7 @@
         _shelvecreatedcommit(repo, node, name)
 
         if ui.formatted():
-            desc = util.ellipsis(desc, ui.termwidth())
+            desc = stringutil.ellipsis(desc, ui.termwidth())
         ui.status(_('shelved as %s\n') % name)
         hg.update(repo, parent.node())
         if origbranch != repo['.'].branch() and not _isbareshelve(pats, opts):
@@ -578,7 +581,7 @@
                 if not line.startswith('#'):
                     desc = line.rstrip()
                     if ui.formatted():
-                        desc = util.ellipsis(desc, width - used)
+                        desc = stringutil.ellipsis(desc, width - used)
                     ui.write(desc)
                     break
             ui.write('\n')
--- a/hgext/transplant.py	Thu Mar 22 21:19:31 2018 +0900
+++ b/hgext/transplant.py	Thu Mar 22 21:56:20 2018 +0900
@@ -38,6 +38,9 @@
     util,
     vfs as vfsmod,
 )
+from mercurial.utils import (
+    stringutil,
+)
 
 class TransplantError(error.Abort):
     pass
@@ -311,7 +314,7 @@
                 p1 = repo.dirstate.p1()
                 p2 = node
                 self.log(user, date, message, p1, p2, merge=merge)
-                self.ui.write(util.forcebytestr(inst) + '\n')
+                self.ui.write(stringutil.forcebytestr(inst) + '\n')
                 raise TransplantError(_('fix up the working directory and run '
                                         'hg transplant --continue'))
         else:
--- a/hgext/win32text.py	Thu Mar 22 21:19:31 2018 +0900
+++ b/hgext/win32text.py	Thu Mar 22 21:56:20 2018 +0900
@@ -50,7 +50,9 @@
 )
 from mercurial import (
     registrar,
-    util,
+)
+from mercurial.utils import (
+    stringutil,
 )
 
 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
@@ -100,22 +102,22 @@
     return s.replace('\r', '\n')
 
 def cleverdecode(s, cmd, **kwargs):
-    if not util.binary(s):
+    if not stringutil.binary(s):
         return dumbdecode(s, cmd, **kwargs)
     return s
 
 def cleverencode(s, cmd):
-    if not util.binary(s):
+    if not stringutil.binary(s):
         return dumbencode(s, cmd)
     return s
 
 def macdecode(s, cmd, **kwargs):
-    if not util.binary(s):
+    if not stringutil.binary(s):
         return macdumbdecode(s, cmd, **kwargs)
     return s
 
 def macencode(s, cmd):
-    if not util.binary(s):
+    if not stringutil.binary(s):
         return macdumbencode(s, cmd)
     return s
 
@@ -146,7 +148,7 @@
                 continue
             seen.add(f)
             data = c[f].data()
-            if not util.binary(data) and newline in data:
+            if not stringutil.binary(data) and newline in data:
                 if not halt:
                     ui.warn(_('attempt to commit or push text file(s) '
                               'using %s line endings\n') %
--- a/mercurial/branchmap.py	Thu Mar 22 21:19:31 2018 +0900
+++ b/mercurial/branchmap.py	Thu Mar 22 21:56:20 2018 +0900
@@ -22,6 +22,9 @@
     scmutil,
     util,
 )
+from .utils import (
+    stringutil,
+)
 
 calcsize = struct.calcsize
 pack_into = struct.pack_into
@@ -256,7 +259,7 @@
         except (IOError, OSError, error.Abort) as inst:
             # Abort may be raised by read only opener, so log and continue
             repo.ui.debug("couldn't write branch cache: %s\n" %
-                          util.forcebytestr(inst))
+                          stringutil.forcebytestr(inst))
 
     def update(self, repo, revgen):
         """Given a branchhead cache, self, that may have extra nodes or be
@@ -378,7 +381,7 @@
                 self._rbcrevs[:] = data
             except (IOError, OSError) as inst:
                 repo.ui.debug("couldn't read revision branch cache: %s\n" %
-                              util.forcebytestr(inst))
+                              stringutil.forcebytestr(inst))
         # remember number of good records on disk
         self._rbcrevslen = min(len(self._rbcrevs) // _rbcrecsize,
                                len(repo.changelog))
@@ -540,7 +543,7 @@
                 self._rbcrevslen = revs
         except (IOError, OSError, error.Abort, error.LockError) as inst:
             repo.ui.debug("couldn't write revision branch cache%s: %s\n"
-                          % (step, util.forcebytestr(inst)))
+                          % (step, stringutil.forcebytestr(inst)))
         finally:
             if wlock is not None:
                 wlock.release()
--- a/mercurial/bundle2.py	Thu Mar 22 21:19:31 2018 +0900
+++ b/mercurial/bundle2.py	Thu Mar 22 21:56:20 2018 +0900
@@ -171,6 +171,9 @@
     url,
     util,
 )
+from .utils import (
+    stringutil,
+)
 
 urlerr = util.urlerr
 urlreq = util.urlreq
@@ -1091,7 +1094,7 @@
             ui.debug('bundle2-generatorexit\n')
             raise
         except BaseException as exc:
-            bexc = util.forcebytestr(exc)
+            bexc = stringutil.forcebytestr(exc)
             # backup exception data for later
             ui.debug('bundle2-input-stream-interrupt: encoding exception %s'
                      % bexc)
--- a/mercurial/changegroup.py	Thu Mar 22 21:19:31 2018 +0900
+++ b/mercurial/changegroup.py	Thu Mar 22 21:56:20 2018 +0900
@@ -28,6 +28,10 @@
     util,
 )
 
+from .utils import (
+    stringutil,
+)
+
 _CHANGEGROUPV1_DELTA_HEADER = "20s20s20s20s"
 _CHANGEGROUPV2_DELTA_HEADER = "20s20s20s20s20s"
 _CHANGEGROUPV3_DELTA_HEADER = ">20s20s20s20s20sH"
@@ -514,7 +518,7 @@
         if reorder == 'auto':
             reorder = None
         else:
-            reorder = util.parsebool(reorder)
+            reorder = stringutil.parsebool(reorder)
         self._repo = repo
         self._reorder = reorder
         self._progress = repo.ui.progress
--- a/mercurial/changelog.py	Thu Mar 22 21:19:31 2018 +0900
+++ b/mercurial/changelog.py	Thu Mar 22 21:56:20 2018 +0900
@@ -24,7 +24,10 @@
     revlog,
     util,
 )
-from .utils import dateutil
+from .utils import (
+    dateutil,
+    stringutil,
+)
 
 _defaultextra = {'branch': 'default'}
 
@@ -36,7 +39,7 @@
     >>> s
     'ab\\ncd\\\\\\\\n\\x00ab\\rcd\\\\\\n'
     >>> res = _string_escape(s)
-    >>> s == util.unescapestr(res)
+    >>> s == stringutil.unescapestr(res)
     True
     """
     # subset of the string_escape codec
@@ -62,7 +65,7 @@
                 l = l.replace('\\\\', '\\\\\n')
                 l = l.replace('\\0', '\0')
                 l = l.replace('\n', '')
-            k, v = util.unescapestr(l).split(':', 1)
+            k, v = stringutil.unescapestr(l).split(':', 1)
             extra[k] = v
     return extra
 
--- a/mercurial/cmdutil.py	Thu Mar 22 21:19:31 2018 +0900
+++ b/mercurial/cmdutil.py	Thu Mar 22 21:56:20 2018 +0900
@@ -48,7 +48,12 @@
     util,
     vfs as vfsmod,
 )
-from .utils import dateutil
+
+from .utils import (
+    dateutil,
+    stringutil,
+)
+
 stringio = util.stringio
 
 # templates of common command options
@@ -962,9 +967,9 @@
         while i < end:
             n = pat.find(b'%', i, end)
             if n < 0:
-                newname.append(util.escapestr(pat[i:end]))
+                newname.append(stringutil.escapestr(pat[i:end]))
                 break
-            newname.append(util.escapestr(pat[i:n]))
+            newname.append(stringutil.escapestr(pat[i:n]))
             if n + 2 > end:
                 raise error.Abort(_("incomplete format spec in output "
                                     "filename"))
@@ -1479,7 +1484,7 @@
                     patch.patchrepo(ui, repo, p1, store, tmpname, strip, prefix,
                                     files, eolmode=None)
                 except error.PatchError as e:
-                    raise error.Abort(util.forcebytestr(e))
+                    raise error.Abort(stringutil.forcebytestr(e))
                 if opts.get('exact'):
                     editor = None
                 else:
--- a/mercurial/color.py	Thu Mar 22 21:19:31 2018 +0900
+++ b/mercurial/color.py	Thu Mar 22 21:56:20 2018 +0900
@@ -14,7 +14,10 @@
 from . import (
     encoding,
     pycompat,
-    util
+)
+
+from .utils import (
+    stringutil,
 )
 
 try:
@@ -200,7 +203,7 @@
 
     auto = (config == 'auto')
     always = False
-    if not auto and util.parsebool(config):
+    if not auto and stringutil.parsebool(config):
         # We want the config to behave like a boolean, "on" is actually auto,
         # but "always" value is treated as a special case to reduce confusion.
         if ui.configsource('ui', 'color') == '--color' or config == 'always':
--- a/mercurial/commands.py	Thu Mar 22 21:19:31 2018 +0900
+++ b/mercurial/commands.py	Thu Mar 22 21:56:20 2018 +0900
@@ -61,7 +61,10 @@
     util,
     wireprotoserver,
 )
-from .utils import dateutil
+from .utils import (
+    dateutil,
+    stringutil,
+)
 
 release = lockmod.release
 
@@ -2469,7 +2472,7 @@
         @util.cachefunc
         def binary():
             flog = getfile(fn)
-            return util.binary(flog.read(ctx.filenode(fn)))
+            return stringutil.binary(flog.read(ctx.filenode(fn)))
 
         fieldnamemap = {'filename': 'file', 'linenumber': 'line_number'}
         if opts.get('all'):
@@ -3914,7 +3917,7 @@
         try:
             return hg.updatetotally(ui, repo, checkout, brev)
         except error.UpdateAbort as inst:
-            msg = _("not updating: %s") % util.forcebytestr(inst)
+            msg = _("not updating: %s") % stringutil.forcebytestr(inst)
             hint = inst.hint
             raise error.UpdateAbort(msg, hint=hint)
     if modheads > 1:
--- a/mercurial/context.py	Thu Mar 22 21:19:31 2018 +0900
+++ b/mercurial/context.py	Thu Mar 22 21:56:20 2018 +0900
@@ -46,7 +46,10 @@
     subrepoutil,
     util,
 )
-from .utils import dateutil
+from .utils import (
+    dateutil,
+    stringutil,
+)
 
 propertycache = util.propertycache
 
@@ -818,7 +821,7 @@
 
     def isbinary(self):
         try:
-            return util.binary(self.data())
+            return stringutil.binary(self.data())
         except IOError:
             return False
     def isexec(self):
@@ -1500,7 +1503,8 @@
         for f in files:
             if self.flags(f) == 'l':
                 d = self[f].data()
-                if d == '' or len(d) >= 1024 or '\n' in d or util.binary(d):
+                if (d == '' or len(d) >= 1024 or '\n' in d
+                    or stringutil.binary(d)):
                     self._repo.ui.debug('ignoring suspect symlink placeholder'
                                         ' "%s"\n' % f)
                     continue
--- a/mercurial/crecord.py	Thu Mar 22 21:19:31 2018 +0900
+++ b/mercurial/crecord.py	Thu Mar 22 21:56:20 2018 +0900
@@ -23,6 +23,9 @@
     scmutil,
     util,
 )
+from .utils import (
+    stringutil,
+)
 stringio = util.stringio
 
 # This is required for ncurses to display non-ASCII characters in default user
@@ -585,7 +588,7 @@
         # long as not explicitly set to a falsy value - especially,
         # when not set at all. This is to stay most compatible with
         # previous (color only) behaviour.
-        uicolor = util.parsebool(self.ui.config('ui', 'color'))
+        uicolor = stringutil.parsebool(self.ui.config('ui', 'color'))
         self.usecolor = uicolor is not False
 
         # the currently selected header, hunk, or hunk-line
@@ -1058,7 +1061,7 @@
         if len(lines) != self.numstatuslines:
             self.numstatuslines = len(lines)
             self.statuswin.resize(self.numstatuslines, self.xscreensize)
-        return [util.ellipsis(l, self.xscreensize - 1) for l in lines]
+        return [stringutil.ellipsis(l, self.xscreensize - 1) for l in lines]
 
     def updatescreen(self):
         self.statuswin.erase()
--- a/mercurial/dagparser.py	Thu Mar 22 21:19:31 2018 +0900
+++ b/mercurial/dagparser.py	Thu Mar 22 21:56:20 2018 +0900
@@ -14,7 +14,9 @@
 from . import (
     error,
     pycompat,
-    util,
+)
+from .utils import (
+    stringutil,
 )
 
 def parsedag(desc):
@@ -372,8 +374,8 @@
                 else:
                     raise error.Abort(_("invalid event type in dag: "
                                         "('%s', '%s')")
-                                      % (util.escapestr(kind),
-                                         util.escapestr(data)))
+                                      % (stringutil.escapestr(kind),
+                                         stringutil.escapestr(data)))
         if run:
             yield '+%d' % run
 
--- a/mercurial/debugcommands.py	Thu Mar 22 21:19:31 2018 +0900
+++ b/mercurial/debugcommands.py	Thu Mar 22 21:56:20 2018 +0900
@@ -81,7 +81,10 @@
     wireprotoframing,
     wireprotoserver,
 )
-from .utils import dateutil
+from .utils import (
+    dateutil,
+    stringutil,
+)
 
 release = lockmod.release
 
@@ -1141,7 +1144,7 @@
     try:
         codecs.lookup(pycompat.sysstr(encoding.encoding))
     except LookupError as inst:
-        err = util.forcebytestr(inst)
+        err = stringutil.forcebytestr(inst)
         problems += 1
     fm.condwrite(err, 'encodingerror', _(" %s\n"
                  " (check that your locale is properly set)\n"), err)
@@ -1197,7 +1200,7 @@
             )
             dir(bdiff), dir(mpatch), dir(base85), dir(osutil) # quiet pyflakes
         except Exception as inst:
-            err = util.forcebytestr(inst)
+            err = stringutil.forcebytestr(inst)
             problems += 1
         fm.condwrite(err, 'extensionserror', " %s\n", err)
 
@@ -1234,7 +1237,7 @@
             try:
                 templater.templater.frommapfile(m)
             except Exception as inst:
-                err = util.forcebytestr(inst)
+                err = stringutil.forcebytestr(inst)
                 p = None
             fm.condwrite(err, 'defaulttemplateerror', " %s\n", err)
         else:
@@ -1271,7 +1274,7 @@
     try:
         username = ui.username()
     except error.Abort as e:
-        err = util.forcebytestr(e)
+        err = stringutil.forcebytestr(e)
         problems += 1
 
     fm.condwrite(username, 'username',  _("checking username (%s)\n"), username)
@@ -1822,8 +1825,8 @@
         return not r
     else:
         for k, v in sorted(target.listkeys(namespace).iteritems()):
-            ui.write("%s\t%s\n" % (util.escapestr(k),
-                                   util.escapestr(v)))
+            ui.write("%s\t%s\n" % (stringutil.escapestr(k),
+                                   stringutil.escapestr(v)))
 
 @command('debugpvec', [], _('A B'))
 def debugpvec(ui, repo, a, b=None):
@@ -2909,7 +2912,7 @@
 
             # Concatenate the data together.
             data = ''.join(l.lstrip() for l in lines)
-            data = util.unescapestr(data)
+            data = stringutil.unescapestr(data)
             stdin.write(data)
 
             if action == 'raw+':
@@ -2935,7 +2938,7 @@
                 else:
                     key, value = fields
 
-                args[key] = util.unescapestr(value)
+                args[key] = stringutil.unescapestr(value)
 
             if batchedcommands is not None:
                 batchedcommands.append((command, args))
@@ -2948,12 +2951,12 @@
                     del args['PUSHFILE']
                     res, output = peer._callpush(command, fh,
                                                  **pycompat.strkwargs(args))
-                    ui.status(_('result: %s\n') % util.escapedata(res))
+                    ui.status(_('result: %s\n') % stringutil.escapedata(res))
                     ui.status(_('remote output: %s\n') %
-                              util.escapedata(output))
+                              stringutil.escapedata(output))
             else:
                 res = peer._call(command, **pycompat.strkwargs(args))
-                ui.status(_('response: %s\n') % util.escapedata(res))
+                ui.status(_('response: %s\n') % stringutil.escapedata(res))
 
         elif action == 'batchbegin':
             if batchedcommands is not None:
@@ -2967,7 +2970,8 @@
             ui.status(_('sending batch with %d sub-commands\n') %
                       len(batchedcommands))
             for i, chunk in enumerate(peer._submitbatch(batchedcommands)):
-                ui.status(_('response #%d: %s\n') % (i, util.escapedata(chunk)))
+                ui.status(_('response #%d: %s\n') %
+                          (i, stringutil.escapedata(chunk)))
 
             batchedcommands = None
 
--- a/mercurial/dispatch.py	Thu Mar 22 21:19:31 2018 +0900
+++ b/mercurial/dispatch.py	Thu Mar 22 21:56:20 2018 +0900
@@ -41,6 +41,10 @@
     util,
 )
 
+from .utils import (
+    stringutil,
+)
+
 unrecoverablewrite = registrar.command.unrecoverablewrite
 
 class request(object):
@@ -496,7 +500,7 @@
             args = pycompat.shlexsplit(self.definition)
         except ValueError as inst:
             self.badalias = (_("error in definition for alias '%s': %s")
-                             % (self.name, util.forcebytestr(inst)))
+                             % (self.name, stringutil.forcebytestr(inst)))
             return
         earlyopts, args = _earlysplitopts(args)
         if earlyopts:
@@ -623,7 +627,7 @@
     try:
         args = fancyopts.fancyopts(args, commands.globalopts, options)
     except getopt.GetoptError as inst:
-        raise error.CommandError(None, util.forcebytestr(inst))
+        raise error.CommandError(None, stringutil.forcebytestr(inst))
 
     if args:
         cmd, args = args[0], args[1:]
@@ -647,7 +651,7 @@
     try:
         args = fancyopts.fancyopts(args, c, cmdoptions, gnu=True)
     except getopt.GetoptError as inst:
-        raise error.CommandError(cmd, util.forcebytestr(inst))
+        raise error.CommandError(cmd, stringutil.forcebytestr(inst))
 
     # separate global options back out
     for o in commands.globalopts:
@@ -872,7 +876,7 @@
                 ui_.setconfig('ui', 'color', coloropt, '--color')
             color.setup(ui_)
 
-        if util.parsebool(options['pager']):
+        if stringutil.parsebool(options['pager']):
             # ui.pager() expects 'internal-always-' prefix in this case
             ui.pager('internal-always-' + cmd)
         elif options['pager'] != 'auto':
@@ -968,7 +972,7 @@
         for name, mod in extensions.extensions():
             # 'testedwith' should be bytes, but not all extensions are ported
             # to py3 and we don't want UnicodeException because of that.
-            testedwith = util.forcebytestr(getattr(mod, 'testedwith', ''))
+            testedwith = stringutil.forcebytestr(getattr(mod, 'testedwith', ''))
             report = getattr(mod, 'buglink', _('the extension author.'))
             if not testedwith.strip():
                 # We found an untested extension. It's likely the culprit.
@@ -990,7 +994,8 @@
     if worst[0] is not None:
         name, testedwith, report = worst
         if not isinstance(testedwith, (bytes, str)):
-            testedwith = '.'.join([util.forcebytestr(c) for c in testedwith])
+            testedwith = '.'.join([stringutil.forcebytestr(c)
+                                   for c in testedwith])
         warning = (_('** Unknown exception encountered with '
                      'possibly-broken third-party extension %s\n'
                      '** which supports versions %s of Mercurial.\n'
--- a/mercurial/exchange.py	Thu Mar 22 21:19:31 2018 +0900
+++ b/mercurial/exchange.py	Thu Mar 22 21:56:20 2018 +0900
@@ -35,6 +35,9 @@
     url as urlmod,
     util,
 )
+from .utils import (
+    stringutil,
+)
 
 urlerr = util.urlerr
 urlreq = util.urlreq
@@ -2180,7 +2183,7 @@
             except error.UnsupportedBundleSpecification as e:
                 repo.ui.debug('filtering %s because unsupported bundle '
                               'spec: %s\n' % (
-                                  entry['URL'], util.forcebytestr(e)))
+                                  entry['URL'], stringutil.forcebytestr(e)))
                 continue
         # If we don't have a spec and requested a stream clone, we don't know
         # what the entry is so don't attempt to apply it.
@@ -2286,9 +2289,9 @@
             return True
         except urlerr.httperror as e:
             ui.warn(_('HTTP error fetching bundle: %s\n') %
-                    util.forcebytestr(e))
+                    stringutil.forcebytestr(e))
         except urlerr.urlerror as e:
             ui.warn(_('error fetching bundle: %s\n') %
-                    util.forcebytestr(e.reason))
+                    stringutil.forcebytestr(e.reason))
 
         return False
--- a/mercurial/extensions.py	Thu Mar 22 21:19:31 2018 +0900
+++ b/mercurial/extensions.py	Thu Mar 22 21:56:20 2018 +0900
@@ -25,6 +25,10 @@
     util,
 )
 
+from .utils import (
+    stringutil,
+)
+
 _extensions = {}
 _disabledextensions = {}
 _aftercallbacks = {}
@@ -118,7 +122,7 @@
     # note: this ui.debug happens before --debug is processed,
     #       Use --config ui.debug=1 to see them.
     ui.debug('could not import %s (%s): trying %s\n'
-             % (failed, util.forcebytestr(err), next))
+             % (failed, stringutil.forcebytestr(err), next))
     if ui.debugflag:
         ui.traceback()
 
@@ -129,7 +133,7 @@
     elif isinstance(xs, dict):
         for k, v in xs.items():
             _rejectunicode(name, k)
-            _rejectunicode(b'%s.%s' % (name, util.forcebytestr(k)), v)
+            _rejectunicode(b'%s.%s' % (name, stringutil.forcebytestr(k)), v)
     elif isinstance(xs, type(u'')):
         raise error.ProgrammingError(b"unicode %r found in %s" % (xs, name),
                                      hint="use b'' to make it byte string")
@@ -198,7 +202,7 @@
             uisetup(ui)
         except Exception as inst:
             ui.traceback(force=True)
-            msg = util.forcebytestr(inst)
+            msg = stringutil.forcebytestr(inst)
             ui.warn(_("*** failed to set up extension %s: %s\n") % (name, msg))
             return False
     return True
@@ -215,7 +219,7 @@
                 extsetup() # old extsetup with no ui argument
         except Exception as inst:
             ui.traceback(force=True)
-            msg = util.forcebytestr(inst)
+            msg = stringutil.forcebytestr(inst)
             ui.warn(_("*** failed to set up extension %s: %s\n") % (name, msg))
             return False
     return True
@@ -233,7 +237,7 @@
         try:
             load(ui, name, path)
         except Exception as inst:
-            msg = util.forcebytestr(inst)
+            msg = stringutil.forcebytestr(inst)
             if path:
                 ui.warn(_("*** failed to import extension %s from %s: %s\n")
                         % (name, path, msg))
--- a/mercurial/filemerge.py	Thu Mar 22 21:19:31 2018 +0900
+++ b/mercurial/filemerge.py	Thu Mar 22 21:56:20 2018 +0900
@@ -31,6 +31,10 @@
     util,
 )
 
+from .utils import (
+    stringutil,
+)
+
 def _toolstr(ui, tool, part, *args):
     return ui.config("merge-tools", tool + "." + part, *args)
 
@@ -573,7 +577,7 @@
         mark = mark.splitlines()[0] # split for safety
 
     # 8 for the prefix of conflict marker lines (e.g. '<<<<<<< ')
-    return util.ellipsis(mark, 80 - 8)
+    return stringutil.ellipsis(mark, 80 - 8)
 
 _defaultconflictlabels = ['local', 'other']
 
--- a/mercurial/fileset.py	Thu Mar 22 21:19:31 2018 +0900
+++ b/mercurial/fileset.py	Thu Mar 22 21:56:20 2018 +0900
@@ -20,6 +20,9 @@
     scmutil,
     util,
 )
+from .utils import (
+    stringutil,
+)
 
 elements = {
     # token-type: binding-strength, primary, prefix, infix, suffix
@@ -445,7 +448,7 @@
     s = []
     for f in mctx.existing():
         d = mctx.ctx[f].data()
-        if util.binary(d):
+        if stringutil.binary(d):
             continue
         if (enc == 'dos' or enc == 'win') and '\r\n' in d:
             s.append(f)
--- a/mercurial/hg.py	Thu Mar 22 21:19:31 2018 +0900
+++ b/mercurial/hg.py	Thu Mar 22 21:56:20 2018 +0900
@@ -48,6 +48,10 @@
     vfs as vfsmod,
 )
 
+from .utils import (
+    stringutil,
+)
+
 release = lock.release
 
 # shared features
@@ -270,7 +274,7 @@
             # ValueError is raised on Windows if the drive letters differ on
             # each path
             raise error.Abort(_('cannot calculate relative path'),
-                              hint=util.forcebytestr(e))
+                              hint=stringutil.forcebytestr(e))
     else:
         requirements += 'shared\n'
 
--- a/mercurial/hgweb/webcommands.py	Thu Mar 22 21:19:31 2018 +0900
+++ b/mercurial/hgweb/webcommands.py	Thu Mar 22 21:56:20 2018 +0900
@@ -36,7 +36,10 @@
     scmutil,
     smartset,
     templater,
-    util,
+)
+
+from ..utils import (
+    stringutil,
 )
 
 from . import (
@@ -121,7 +124,7 @@
     if guessmime:
         mt = mimetypes.guess_type(path)[0]
         if mt is None:
-            if util.binary(text):
+            if stringutil.binary(text):
                 mt = 'application/binary'
             else:
                 mt = 'text/plain'
@@ -141,7 +144,7 @@
     parity = paritygen(web.stripecount)
     ishead = fctx.filerev() in fctx.filelog().headrevs()
 
-    if util.binary(text):
+    if stringutil.binary(text):
         mt = mimetypes.guess_type(f)[0] or 'application/octet-stream'
         text = '(binary:%s)' % mt
 
--- a/mercurial/hgweb/webutil.py	Thu Mar 22 21:19:31 2018 +0900
+++ b/mercurial/hgweb/webutil.py	Thu Mar 22 21:56:20 2018 +0900
@@ -38,6 +38,10 @@
     util,
 )
 
+from ..utils import (
+    stringutil,
+)
+
 def up(p):
     if p[0:1] != "/":
         p = "/" + p
@@ -180,7 +184,7 @@
     for k in ('ignorews', 'ignorewsamount', 'ignorewseol', 'ignoreblanklines'):
         v = req.qsparams.get(k)
         if v is not None:
-            v = util.parsebool(v)
+            v = stringutil.parsebool(v)
             setattr(diffopts, k, v if v is not None else True)
 
     return diffopts
--- a/mercurial/localrepo.py	Thu Mar 22 21:19:31 2018 +0900
+++ b/mercurial/localrepo.py	Thu Mar 22 21:56:20 2018 +0900
@@ -64,6 +64,9 @@
     util,
     vfs as vfsmod,
 )
+from .utils import (
+    stringutil,
+)
 
 release = lockmod.release
 urlerr = util.urlerr
@@ -263,7 +266,7 @@
                 raise
         except error.PushRaced as exc:
             raise error.ResponseError(_('push failed:'),
-                                      util.forcebytestr(exc))
+                                      stringutil.forcebytestr(exc))
 
     # End of _basewirecommands interface.
 
--- a/mercurial/logcmdutil.py	Thu Mar 22 21:19:31 2018 +0900
+++ b/mercurial/logcmdutil.py	Thu Mar 22 21:56:20 2018 +0900
@@ -35,7 +35,10 @@
     templater,
     util,
 )
-from .utils import dateutil
+from .utils import (
+    dateutil,
+    stringutil,
+)
 
 def getlimit(opts):
     """get the log limit according to option -l/--limit"""
@@ -260,7 +263,8 @@
         extra = ctx.extra()
         if extra and self.ui.debugflag:
             for key, value in sorted(extra.items()):
-                self.ui.write(columns['extra'] % (key, util.escapestr(value)),
+                self.ui.write(columns['extra']
+                              % (key, stringutil.escapestr(value)),
                               label='ui.debug log.extra')
 
         description = ctx.description().strip()
--- a/mercurial/mail.py	Thu Mar 22 21:19:31 2018 +0900
+++ b/mercurial/mail.py	Thu Mar 22 21:56:20 2018 +0900
@@ -24,6 +24,9 @@
     sslutil,
     util,
 )
+from .utils import (
+    stringutil,
+)
 
 class STARTTLS(smtplib.SMTP):
     '''Derived class to verify the peer certificate for STARTTLS.
@@ -81,7 +84,7 @@
     local_hostname = ui.config('smtp', 'local_hostname')
     tls = ui.config('smtp', 'tls')
     # backward compatible: when tls = true, we use starttls.
-    starttls = tls == 'starttls' or util.parsebool(tls)
+    starttls = tls == 'starttls' or stringutil.parsebool(tls)
     smtps = tls == 'smtps'
     if (starttls or smtps) and not util.safehasattr(socket, 'ssl'):
         raise error.Abort(_("can't use TLS: Python SSL support not installed"))
@@ -137,8 +140,8 @@
 def _sendmail(ui, sender, recipients, msg):
     '''send mail using sendmail.'''
     program = ui.config('email', 'method')
-    cmdline = '%s -f %s %s' % (program, util.email(sender),
-                               ' '.join(map(util.email, recipients)))
+    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.write(msg)
--- a/mercurial/match.py	Thu Mar 22 21:19:31 2018 +0900
+++ b/mercurial/match.py	Thu Mar 22 21:56:20 2018 +0900
@@ -19,6 +19,9 @@
     pycompat,
     util,
 )
+from .utils import (
+    stringutil,
+)
 
 allpatternkinds = ('re', 'glob', 'path', 'relglob', 'relpath', 'relre',
                    'listfile', 'listfile0', 'set', 'include', 'subinclude',
@@ -227,7 +230,7 @@
             except IOError as inst:
                 if warn:
                     warn(_("skipping unreadable pattern file '%s': %s\n") %
-                         (pat, util.forcebytestr(inst.strerror)))
+                         (pat, stringutil.forcebytestr(inst.strerror)))
             continue
         # else: re or relre - which cannot be normalized
         kindpats.append((kind, pat, ''))
--- a/mercurial/minirst.py	Thu Mar 22 21:19:31 2018 +0900
+++ b/mercurial/minirst.py	Thu Mar 22 21:56:20 2018 +0900
@@ -27,7 +27,9 @@
     encoding,
     pycompat,
     url,
-    util,
+)
+from .utils import (
+    stringutil,
 )
 
 def section(s):
@@ -459,9 +461,9 @@
     hanging = block['optstrwidth']
     initindent = '%s%s  ' % (block['optstr'], ' ' * ((hanging - colwidth)))
     hangindent = ' ' * (encoding.colwidth(initindent) + 1)
-    return ' %s\n' % (util.wrap(desc, usablewidth,
-                                           initindent=initindent,
-                                           hangindent=hangindent))
+    return ' %s\n' % (stringutil.wrap(desc, usablewidth,
+                                      initindent=initindent,
+                                      hangindent=hangindent))
 
 def formatblock(block, width):
     """Format a block according to width."""
@@ -477,9 +479,9 @@
         defindent = indent + hang * ' '
         text = ' '.join(map(bytes.strip, block['lines']))
         return '%s\n%s\n' % (indent + admonition,
-                             util.wrap(text, width=width,
-                                       initindent=defindent,
-                                       hangindent=defindent))
+                             stringutil.wrap(text, width=width,
+                                             initindent=defindent,
+                                             hangindent=defindent))
     if block['type'] == 'margin':
         return '\n'
     if block['type'] == 'literal':
@@ -503,7 +505,9 @@
                 pad = ' ' * (w - encoding.colwidth(v))
                 l.append(v + pad)
             l = ' '.join(l)
-            l = util.wrap(l, width=width, initindent=indent, hangindent=hang)
+            l = stringutil.wrap(l, width=width,
+                                initindent=indent,
+                                hangindent=hang)
             if not text and block['header']:
                 text = l + '\n' + indent + '-' * (min(width, span)) + '\n'
             else:
@@ -514,9 +518,9 @@
         hang = len(block['lines'][-1]) - len(block['lines'][-1].lstrip())
         defindent = indent + hang * ' '
         text = ' '.join(map(bytes.strip, block['lines'][1:]))
-        return '%s\n%s\n' % (term, util.wrap(text, width=width,
-                                             initindent=defindent,
-                                             hangindent=defindent))
+        return '%s\n%s\n' % (term, stringutil.wrap(text, width=width,
+                                                   initindent=defindent,
+                                                   hangindent=defindent))
     subindent = indent
     if block['type'] == 'bullet':
         if block['lines'][0].startswith('| '):
@@ -540,9 +544,9 @@
         return formatoption(block, width)
 
     text = ' '.join(map(bytes.strip, block['lines']))
-    return util.wrap(text, width=width,
-                     initindent=indent,
-                     hangindent=subindent) + '\n'
+    return stringutil.wrap(text, width=width,
+                           initindent=indent,
+                           hangindent=subindent) + '\n'
 
 def formathtml(blocks):
     """Format RST blocks as HTML"""
--- a/mercurial/parser.py	Thu Mar 22 21:19:31 2018 +0900
+++ b/mercurial/parser.py	Thu Mar 22 21:56:20 2018 +0900
@@ -25,6 +25,9 @@
     pycompat,
     util,
 )
+from .utils import (
+    stringutil,
+)
 
 class parser(object):
     def __init__(self, elements, methods=None):
@@ -190,14 +193,14 @@
 
 def unescapestr(s):
     try:
-        return util.unescapestr(s)
+        return stringutil.unescapestr(s)
     except ValueError as e:
         # mangle Python's exception into our format
         raise error.ParseError(pycompat.bytestr(e).lower())
 
 def _brepr(obj):
     if isinstance(obj, bytes):
-        return b"'%s'" % util.escapestr(obj)
+        return b"'%s'" % stringutil.escapestr(obj)
     return encoding.strtolocal(repr(obj))
 
 def _prettyformat(tree, leafnodes, level, lines):
--- a/mercurial/patch.py	Thu Mar 22 21:19:31 2018 +0900
+++ b/mercurial/patch.py	Thu Mar 22 21:56:20 2018 +0900
@@ -40,7 +40,10 @@
     util,
     vfs as vfsmod,
 )
-from .utils import dateutil
+from .utils import (
+    dateutil,
+    stringutil,
+)
 
 diffhelpers = policy.importmod(r'diffhelpers')
 stringio = util.stringio
@@ -1461,7 +1464,7 @@
                 dec.append(util.b85decode(line[1:])[:l])
             except ValueError as e:
                 raise PatchError(_('could not decode "%s" binary patch: %s')
-                                 % (self._fname, util.forcebytestr(e)))
+                                 % (self._fname, stringutil.forcebytestr(e)))
             line = getline(lr, self.hunk)
         text = zlib.decompress(''.join(dec))
         if len(text) != size:
--- a/mercurial/repair.py	Thu Mar 22 21:19:31 2018 +0900
+++ b/mercurial/repair.py	Thu Mar 22 21:56:20 2018 +0900
@@ -26,6 +26,9 @@
     obsutil,
     util,
 )
+from .utils import (
+    stringutil,
+)
 
 def backupbundle(repo, bases, heads, node, suffix, compress=True,
                  obsolescence=True):
@@ -236,7 +239,8 @@
             except OSError as e:
                 if e.errno != errno.ENOENT:
                     ui.warn(_('error removing %s: %s\n') %
-                            (undovfs.join(undofile), util.forcebytestr(e)))
+                            (undovfs.join(undofile),
+                             stringutil.forcebytestr(e)))
 
     except: # re-raises
         if backupfile:
--- a/mercurial/revlog.py	Thu Mar 22 21:19:31 2018 +0900
+++ b/mercurial/revlog.py	Thu Mar 22 21:56:20 2018 +0900
@@ -45,6 +45,9 @@
     templatefilters,
     util,
 )
+from .utils import (
+    stringutil,
+)
 
 parsers = policy.importmod(r'parsers')
 
@@ -2017,7 +2020,7 @@
                 return _zlibdecompress(data)
             except zlib.error as e:
                 raise RevlogError(_('revlog decompress error: %s') %
-                                  util.forcebytestr(e))
+                                  stringutil.forcebytestr(e))
         # '\0' is more common than 'u' so it goes first.
         elif t == '\0':
             return data
--- a/mercurial/revset.py	Thu Mar 22 21:19:31 2018 +0900
+++ b/mercurial/revset.py	Thu Mar 22 21:56:20 2018 +0900
@@ -31,7 +31,10 @@
     stack,
     util,
 )
-from .utils import dateutil
+from .utils import (
+    dateutil,
+    stringutil,
+)
 
 # helpers for processing parsed tree
 getsymbol = revsetlang.getsymbol
@@ -447,7 +450,7 @@
         bm = getstring(args[0],
                        # i18n: "bookmark" is a keyword
                        _('the argument to bookmark must be a string'))
-        kind, pattern, matcher = util.stringmatcher(bm)
+        kind, pattern, matcher = stringutil.stringmatcher(bm)
         bms = set()
         if kind == 'literal':
             bmrev = repo._bookmarks.get(pattern, None)
@@ -492,7 +495,7 @@
         # not a string, but another revspec, e.g. tip()
         pass
     else:
-        kind, pattern, matcher = util.stringmatcher(b)
+        kind, pattern, matcher = stringutil.stringmatcher(b)
         if kind == 'literal':
             # note: falls through to the revspec case if no branch with
             # this name exists and pattern kind is not specified explicitly
@@ -819,7 +822,7 @@
         # i18n: "extra" is a keyword
         value = getstring(args['value'], _('second argument to extra must be '
                                            'a string'))
-        kind, value, matcher = util.stringmatcher(value)
+        kind, value, matcher = stringutil.stringmatcher(value)
 
     def _matchvalue(r):
         extra = repo[r].extra()
@@ -1014,7 +1017,7 @@
         gr = re.compile(getstring(x, _("grep requires a string")))
     except re.error as e:
         raise error.ParseError(
-            _('invalid match pattern: %s') % util.forcebytestr(e))
+            _('invalid match pattern: %s') % stringutil.forcebytestr(e))
 
     def matches(x):
         c = repo[x]
@@ -1286,7 +1289,7 @@
     ns = getstring(args[0],
                    # i18n: "named" is a keyword
                    _('the argument to named must be a string'))
-    kind, pattern, matcher = util.stringmatcher(ns)
+    kind, pattern, matcher = stringutil.stringmatcher(ns)
     namespaces = set()
     if kind == 'literal':
         if pattern not in repo.names:
@@ -1942,7 +1945,7 @@
     m = matchmod.exact(repo.root, repo.root, ['.hgsubstate'])
 
     def submatches(names):
-        k, p, m = util.stringmatcher(pat)
+        k, p, m = stringutil.stringmatcher(pat)
         for name in names:
             if m(name):
                 yield name
@@ -1995,8 +1998,8 @@
     return subset & d
 
 def _substringmatcher(pattern, casesensitive=True):
-    kind, pattern, matcher = util.stringmatcher(pattern,
-                                                casesensitive=casesensitive)
+    kind, pattern, matcher = stringutil.stringmatcher(
+        pattern, casesensitive=casesensitive)
     if kind == 'literal':
         if not casesensitive:
             pattern = encoding.lower(pattern)
@@ -2019,7 +2022,7 @@
         pattern = getstring(args[0],
                             # i18n: "tag" is a keyword
                             _('the argument to tag must be a string'))
-        kind, pattern, matcher = util.stringmatcher(pattern)
+        kind, pattern, matcher = stringutil.stringmatcher(pattern)
         if kind == 'literal':
             # avoid resolving all tags
             tn = repo._tagscache.tags.get(pattern, None)
--- a/mercurial/revsetlang.py	Thu Mar 22 21:19:31 2018 +0900
+++ b/mercurial/revsetlang.py	Thu Mar 22 21:56:20 2018 +0900
@@ -17,6 +17,9 @@
     pycompat,
     util,
 )
+from .utils import (
+    stringutil,
+)
 
 elements = {
     # token-type: binding-strength, primary, prefix, infix, suffix
@@ -207,7 +210,7 @@
         raise error.ParseError(err)
 
 def getboolean(x, err):
-    value = util.parsebool(getsymbol(x))
+    value = stringutil.parsebool(getsymbol(x))
     if value is not None:
         return value
     raise error.ParseError(err)
@@ -565,7 +568,7 @@
     >>> _quote(1)
     "'1'"
     """
-    return "'%s'" % util.escapestr(pycompat.bytestr(s))
+    return "'%s'" % stringutil.escapestr(pycompat.bytestr(s))
 
 def _formatargtype(c, arg):
     if c == 'd':
--- a/mercurial/scmutil.py	Thu Mar 22 21:19:31 2018 +0900
+++ b/mercurial/scmutil.py	Thu Mar 22 21:56:20 2018 +0900
@@ -41,6 +41,10 @@
     vfs,
 )
 
+from .utils import (
+    stringutil,
+)
+
 if pycompat.iswindows:
     from . import scmwindows as scmplatform
 else:
@@ -163,12 +167,12 @@
         else:
             reason = _('lock held by %r') % inst.locker
         ui.warn(_("abort: %s: %s\n")
-                % (inst.desc or util.forcebytestr(inst.filename), reason))
+                % (inst.desc or stringutil.forcebytestr(inst.filename), reason))
         if not inst.locker:
             ui.warn(_("(lock might be very busy)\n"))
     except error.LockUnavailable as inst:
         ui.warn(_("abort: could not lock %s: %s\n") %
-                (inst.desc or util.forcebytestr(inst.filename),
+                (inst.desc or stringutil.forcebytestr(inst.filename),
                  encoding.strtolocal(inst.strerror)))
     except error.OutOfBandError as inst:
         if inst.args:
@@ -194,7 +198,7 @@
         elif not msg:
             ui.warn(_(" empty string\n"))
         else:
-            ui.warn("\n%r\n" % util.ellipsis(msg))
+            ui.warn("\n%r\n" % stringutil.ellipsis(msg))
     except error.CensoredNodeError as inst:
         ui.warn(_("abort: file censored %s!\n") % inst)
     except error.RevlogError as inst:
@@ -211,15 +215,15 @@
         if inst.hint:
             ui.warn(_("(%s)\n") % inst.hint)
     except ImportError as inst:
-        ui.warn(_("abort: %s!\n") % util.forcebytestr(inst))
-        m = util.forcebytestr(inst).split()[-1]
+        ui.warn(_("abort: %s!\n") % stringutil.forcebytestr(inst))
+        m = stringutil.forcebytestr(inst).split()[-1]
         if m in "mpatch bdiff".split():
             ui.warn(_("(did you forget to compile extensions?)\n"))
         elif m in "zlib".split():
             ui.warn(_("(is your Python install correct?)\n"))
     except IOError as inst:
         if util.safehasattr(inst, "code"):
-            ui.warn(_("abort: %s\n") % util.forcebytestr(inst))
+            ui.warn(_("abort: %s\n") % stringutil.forcebytestr(inst))
         elif util.safehasattr(inst, "reason"):
             try: # usually it is in the form (errno, strerror)
                 reason = inst.reason.args[1]
@@ -237,7 +241,7 @@
             if getattr(inst, "filename", None):
                 ui.warn(_("abort: %s: %s\n") % (
                     encoding.strtolocal(inst.strerror),
-                    util.forcebytestr(inst.filename)))
+                    stringutil.forcebytestr(inst.filename)))
             else:
                 ui.warn(_("abort: %s\n") % encoding.strtolocal(inst.strerror))
         else:
@@ -246,7 +250,7 @@
         if getattr(inst, "filename", None) is not None:
             ui.warn(_("abort: %s: '%s'\n") % (
                 encoding.strtolocal(inst.strerror),
-                util.forcebytestr(inst.filename)))
+                stringutil.forcebytestr(inst.filename)))
         else:
             ui.warn(_("abort: %s\n") % encoding.strtolocal(inst.strerror))
     except MemoryError:
@@ -256,7 +260,7 @@
         # Just in case catch this and and pass exit code to caller.
         return inst.code
     except socket.error as inst:
-        ui.warn(_("abort: %s\n") % util.forcebytestr(inst.args[-1]))
+        ui.warn(_("abort: %s\n") % stringutil.forcebytestr(inst.args[-1]))
 
     return -1
 
@@ -299,7 +303,7 @@
     non-portable filenames'''
     val = ui.config('ui', 'portablefilenames')
     lval = val.lower()
-    bval = util.parsebool(val)
+    bval = stringutil.parsebool(val)
     abort = pycompat.iswindows or lval == 'abort'
     warn = bval or lval == 'warn'
     if bval is None and not (warn or abort or lval == 'ignore'):
--- a/mercurial/simplemerge.py	Thu Mar 22 21:19:31 2018 +0900
+++ b/mercurial/simplemerge.py	Thu Mar 22 21:56:20 2018 +0900
@@ -23,7 +23,9 @@
     error,
     mdiff,
     pycompat,
-    util,
+)
+from .utils import (
+    stringutil,
 )
 
 class CantReprocessAndShowBase(Exception):
@@ -397,7 +399,7 @@
 def _verifytext(text, path, ui, opts):
     """verifies that text is non-binary (unless opts[text] is passed,
     then we just warn)"""
-    if util.binary(text):
+    if stringutil.binary(text):
         msg = _("%s looks like a binary file.") % path
         if not opts.get('quiet'):
             ui.warn(_('warning: %s\n') % msg)
--- a/mercurial/sslutil.py	Thu Mar 22 21:19:31 2018 +0900
+++ b/mercurial/sslutil.py	Thu Mar 22 21:56:20 2018 +0900
@@ -21,6 +21,9 @@
     pycompat,
     util,
 )
+from .utils import (
+    stringutil,
+)
 
 # Python 2.7.9+ overhauled the built-in SSL/TLS features of Python. It added
 # support for TLS 1.1, TLS 1.2, SNI, system CA stores, etc. These features are
@@ -374,7 +377,8 @@
             sslcontext.set_ciphers(pycompat.sysstr(settings['ciphers']))
         except ssl.SSLError as e:
             raise error.Abort(
-                _('could not set ciphers: %s') % util.forcebytestr(e.args[0]),
+                _('could not set ciphers: %s')
+                % stringutil.forcebytestr(e.args[0]),
                 hint=_('change cipher string (%s) in config') %
                 settings['ciphers'])
 
@@ -393,7 +397,7 @@
             else:
                 msg = e.args[1]
             raise error.Abort(_('error loading CA file %s: %s') % (
-                              settings['cafile'], util.forcebytestr(msg)),
+                              settings['cafile'], stringutil.forcebytestr(msg)),
                               hint=_('file is empty or malformed?'))
         caloaded = True
     elif settings['allowloaddefaultcerts']:
@@ -642,7 +646,7 @@
                 if _dnsnamematch(value, hostname):
                     return
             except wildcarderror as e:
-                return util.forcebytestr(e.args[0])
+                return stringutil.forcebytestr(e.args[0])
 
             dnsnames.append(value)
 
@@ -663,7 +667,7 @@
                         if _dnsnamematch(value, hostname):
                             return
                     except wildcarderror as e:
-                        return util.forcebytestr(e.args[0])
+                        return stringutil.forcebytestr(e.args[0])
 
                     dnsnames.append(value)
 
--- a/mercurial/subrepo.py	Thu Mar 22 21:19:31 2018 +0900
+++ b/mercurial/subrepo.py	Thu Mar 22 21:56:20 2018 +0900
@@ -36,7 +36,10 @@
     util,
     vfs as vfsmod,
 )
-from .utils import dateutil
+from .utils import (
+    dateutil,
+    stringutil,
+)
 
 hg = None
 reporelpath = subrepoutil.reporelpath
@@ -74,7 +77,7 @@
             raise ex
         except error.Abort as ex:
             subrepo = subrelpath(self)
-            errormsg = (util.forcebytestr(ex) + ' '
+            errormsg = (stringutil.forcebytestr(ex) + ' '
                         + _('(in subrepository "%s")') % subrepo)
             # avoid handling this exception by raising a SubrepoAbort exception
             raise SubrepoAbort(errormsg, hint=ex.hint, subrepo=subrepo,
--- a/mercurial/subrepoutil.py	Thu Mar 22 21:19:31 2018 +0900
+++ b/mercurial/subrepoutil.py	Thu Mar 22 21:56:20 2018 +0900
@@ -21,6 +21,9 @@
     phases,
     util,
 )
+from .utils import (
+    stringutil,
+)
 
 nullstate = ('', '', 'empty')
 
@@ -74,7 +77,7 @@
         for pattern, repl in p.items('subpaths'):
             # Turn r'C:\foo\bar' into r'C:\\foo\\bar' since re.sub
             # does a string decode.
-            repl = util.escapestr(repl)
+            repl = stringutil.escapestr(repl)
             # However, we still want to allow back references to go
             # through unharmed, so we turn r'\\1' into r'\1'. Again,
             # extra escapes are needed because re.sub string decodes.
--- a/mercurial/tags.py	Thu Mar 22 21:19:31 2018 +0900
+++ b/mercurial/tags.py	Thu Mar 22 21:56:20 2018 +0900
@@ -28,6 +28,9 @@
     scmutil,
     util,
 )
+from .utils import (
+    stringutil,
+)
 
 # Tags computation can be expensive and caches exist to make it fast in
 # the common case.
@@ -783,6 +786,6 @@
         except (IOError, OSError) as inst:
             repo.ui.log('tagscache',
                         "couldn't write cache/%s: %s\n" % (
-                        _fnodescachefile, util.forcebytestr(inst)))
+                            _fnodescachefile, stringutil.forcebytestr(inst)))
         finally:
             lock.release()
--- a/mercurial/templatefilters.py	Thu Mar 22 21:19:31 2018 +0900
+++ b/mercurial/templatefilters.py	Thu Mar 22 21:56:20 2018 +0900
@@ -21,7 +21,10 @@
     url,
     util,
 )
-from .utils import dateutil
+from .utils import (
+    dateutil,
+    stringutil,
+)
 
 urlerr = util.urlerr
 urlreq = util.urlreq
@@ -128,7 +131,7 @@
     address. Example: ``User <user@example.com>`` becomes
     ``user@example.com``.
     """
-    return util.email(text)
+    return stringutil.email(text)
 
 @templatefilter('escape')
 def escape(text):
@@ -162,8 +165,9 @@
             yield text[start:m.start(0)], m.group(1)
             start = m.end(1)
 
-    return "".join([util.wrap(space_re.sub(' ', util.wrap(para, width)),
-                              width, initindent, hangindent) + rest
+    return "".join([stringutil.wrap(space_re.sub(' ',
+                                                 stringutil.wrap(para, width)),
+                                    width, initindent, hangindent) + rest
                     for para, rest in findparas()])
 
 @templatefilter('fill68')
@@ -369,7 +373,7 @@
 
 @templatefilter('stringescape')
 def stringescape(text):
-    return util.escapestr(text)
+    return stringutil.escapestr(text)
 
 @templatefilter('stringify')
 def stringify(thing):
@@ -412,12 +416,12 @@
 def userfilter(text):
     """Any text. Returns a short representation of a user name or email
     address."""
-    return util.shortuser(text)
+    return stringutil.shortuser(text)
 
 @templatefilter('emailuser')
 def emailuser(text):
     """Any text. Returns the user portion of an email address."""
-    return util.emailuser(text)
+    return stringutil.emailuser(text)
 
 @templatefilter('utf8')
 def utf8(text):
--- a/mercurial/templatekw.py	Thu Mar 22 21:19:31 2018 +0900
+++ b/mercurial/templatekw.py	Thu Mar 22 21:56:20 2018 +0900
@@ -26,6 +26,9 @@
     templateutil,
     util,
 )
+from .utils import (
+    stringutil,
+)
 
 _hybrid = templateutil.hybrid
 _mappable = templateutil.mappable
@@ -72,7 +75,7 @@
     cachename = 'latesttags'
     if pattern is not None:
         cachename += '-' + pattern
-        match = util.stringmatcher(pattern)[2]
+        match = stringutil.stringmatcher(pattern)[2]
     else:
         match = util.always
 
@@ -307,7 +310,7 @@
     c = [makemap(k) for k in extras]
     f = _showcompatlist(context, mapping, 'extra', c, plural='extras')
     return _hybrid(f, extras, makemap,
-                   lambda k: '%s=%s' % (k, util.escapestr(extras[k])))
+                   lambda k: '%s=%s' % (k, stringutil.escapestr(extras[k])))
 
 def _showfilesbystat(context, mapping, name, index):
     repo = context.resource(mapping, 'repo')
--- a/mercurial/templater.py	Thu Mar 22 21:19:31 2018 +0900
+++ b/mercurial/templater.py	Thu Mar 22 21:56:20 2018 +0900
@@ -63,6 +63,9 @@
     templateutil,
     util,
 )
+from .utils import (
+    stringutil,
+)
 
 # template parsing
 
@@ -811,7 +814,8 @@
                     _('"%s" not in template map') % inst.args[0])
             except IOError as inst:
                 reason = (_('template file %s: %s')
-                          % (self.map[t][1], util.forcebytestr(inst.args[1])))
+                          % (self.map[t][1],
+                             stringutil.forcebytestr(inst.args[1])))
                 raise IOError(inst.args[0], encoding.strfromlocal(reason))
         return self.cache[t]
 
--- a/mercurial/templateutil.py	Thu Mar 22 21:19:31 2018 +0900
+++ b/mercurial/templateutil.py	Thu Mar 22 21:56:20 2018 +0900
@@ -15,6 +15,9 @@
     pycompat,
     util,
 )
+from .utils import (
+    stringutil,
+)
 
 class ResourceUnavailable(error.Abort):
     pass
@@ -281,7 +284,7 @@
         thing = func(context, mapping, data, default=None)
         if thing is None:
             # not a template keyword, takes as a boolean literal
-            thing = util.parsebool(data)
+            thing = stringutil.parsebool(data)
     else:
         thing = func(context, mapping, data)
     thing = unwrapvalue(thing)
--- a/mercurial/ui.py	Thu Mar 22 21:19:31 2018 +0900
+++ b/mercurial/ui.py	Thu Mar 22 21:56:20 2018 +0900
@@ -37,7 +37,10 @@
     scmutil,
     util,
 )
-from .utils import dateutil
+from .utils import (
+    dateutil,
+    stringutil,
+)
 
 urlreq = util.urlreq
 
@@ -371,7 +374,7 @@
         except error.ConfigError as inst:
             if trusted:
                 raise
-            self.warn(_("ignored: %s\n") % util.forcebytestr(inst))
+            self.warn(_("ignored: %s\n") % stringutil.forcebytestr(inst))
 
         if self.plain():
             for k in ('debug', 'fallbackencoding', 'quiet', 'slash',
@@ -591,7 +594,7 @@
             return default
         if isinstance(v, bool):
             return v
-        b = util.parsebool(v)
+        b = stringutil.parsebool(v)
         if b is None:
             raise error.ConfigError(_("%s.%s is not a boolean ('%s')")
                                     % (section, name, v))
@@ -821,7 +824,7 @@
     def shortuser(self, user):
         """Return a short representation of a user name or email address."""
         if not self.verbose:
-            user = util.shortuser(user)
+            user = stringutil.shortuser(user)
         return user
 
     def expandpath(self, loc, default=None):
--- a/mercurial/url.py	Thu Mar 22 21:19:31 2018 +0900
+++ b/mercurial/url.py	Thu Mar 22 21:56:20 2018 +0900
@@ -24,6 +24,9 @@
     urllibcompat,
     util,
 )
+from .utils import (
+    stringutil,
+)
 
 httplib = util.httplib
 stringio = util.stringio
@@ -477,7 +480,7 @@
             self.cookiejar = cookiejar
         except util.cookielib.LoadError as e:
             ui.warn(_('(error loading cookie file %s: %s; continuing without '
-                      'cookies)\n') % (cookiefile, util.forcebytestr(e)))
+                      'cookies)\n') % (cookiefile, stringutil.forcebytestr(e)))
 
     def http_request(self, request):
         if self.cookiejar:
--- a/mercurial/util.py	Thu Mar 22 21:19:31 2018 +0900
+++ b/mercurial/util.py	Thu Mar 22 21:56:20 2018 +0900
@@ -820,9 +820,10 @@
         # Simple case writes all data on a single line.
         if b'\n' not in data:
             if self.logdataapis:
-                self.fh.write(': %s\n' % escapedata(data))
+                self.fh.write(': %s\n' % stringutil.escapedata(data))
             else:
-                self.fh.write('%s>     %s\n' % (self.name, escapedata(data)))
+                self.fh.write('%s>     %s\n'
+                              % (self.name, stringutil.escapedata(data)))
             self.fh.flush()
             return
 
@@ -832,7 +833,8 @@
 
         lines = data.splitlines(True)
         for line in lines:
-            self.fh.write('%s>     %s\n' % (self.name, escapedata(line)))
+            self.fh.write('%s>     %s\n'
+                          % (self.name, stringutil.escapedata(line)))
         self.fh.flush()
 
 class fileobjectobserver(baseproxyobserver):
@@ -1915,7 +1917,7 @@
                          "on Windows") % c
             if ord(c) <= 31:
                 return _("filename contains '%s', which is invalid "
-                         "on Windows") % escapestr(c)
+                         "on Windows") % stringutil.escapestr(c)
         base = n.split('.')[0]
         if base and base.lower() in _winreservednames:
             return _("filename contains '%s', which is reserved "
@@ -3679,7 +3681,7 @@
                 return zlib.decompress(data)
             except zlib.error as e:
                 raise error.RevlogError(_('revlog decompress error: %s') %
-                                        forcebytestr(e))
+                                        stringutil.forcebytestr(e))
 
     def revlogcompressor(self, opts=None):
         return self.zlibrevlogcompressor()
@@ -3905,7 +3907,7 @@
                 return ''.join(chunks)
             except Exception as e:
                 raise error.RevlogError(_('revlog decompress error: %s') %
-                                        forcebytestr(e))
+                                        stringutil.forcebytestr(e))
 
     def revlogcompressor(self, opts=None):
         opts = opts or {}
--- a/mercurial/wireproto.py	Thu Mar 22 21:19:31 2018 +0900
+++ b/mercurial/wireproto.py	Thu Mar 22 21:56:20 2018 +0900
@@ -34,6 +34,10 @@
     wireprototypes,
 )
 
+from .utils import (
+    stringutil,
+)
+
 urlerr = util.urlerr
 urlreq = util.urlreq
 
@@ -994,7 +998,7 @@
         r = c.hex()
         success = 1
     except Exception as inst:
-        r = util.forcebytestr(inst)
+        r = stringutil.forcebytestr(inst)
         success = 0
     return bytesresponse('%d %s\n' % (success, r))
 
@@ -1007,7 +1011,7 @@
 def pushkey(repo, proto, namespace, key, old, new):
     # compatibility with pre-1.8 clients which were accidentally
     # sending raw binary nodes rather than utf-8-encoded hex
-    if len(new) == 20 and util.escapestr(new) != new:
+    if len(new) == 20 and stringutil.escapestr(new) != new:
         # looks like it could be a binary node
         try:
             new.decode('utf-8')
@@ -1123,7 +1127,7 @@
                 if exc.params:
                     errpart.addparam('params', '\0'.join(exc.params))
             except error.Abort as exc:
-                manargs = [('message', util.forcebytestr(exc))]
+                manargs = [('message', stringutil.forcebytestr(exc))]
                 advargs = []
                 if exc.hint is not None:
                     advargs.append(('hint', exc.hint))
@@ -1131,5 +1135,5 @@
                                                    manargs, advargs))
             except error.PushRaced as exc:
                 bundler.newpart('error:pushraced',
-                                [('message', util.forcebytestr(exc))])
+                                [('message', stringutil.forcebytestr(exc))])
             return streamres_legacy(gen=bundler.getchunks())
--- a/mercurial/wireprotoframing.py	Thu Mar 22 21:19:31 2018 +0900
+++ b/mercurial/wireprotoframing.py	Thu Mar 22 21:56:20 2018 +0900
@@ -21,6 +21,9 @@
     error,
     util,
 )
+from .utils import (
+    stringutil,
+)
 
 FRAME_HEADER_SIZE = 6
 DEFAULT_MAX_FRAME_SIZE = 32768
@@ -164,7 +167,7 @@
         else:
             finalflags |= int(flag)
 
-    payload = util.unescapestr(payload)
+    payload = stringutil.unescapestr(payload)
 
     return makeframe(requestid=requestid, typeid=frametype,
                      flags=finalflags, payload=payload)
--- a/tests/test-simplemerge.py	Thu Mar 22 21:19:31 2018 +0900
+++ b/tests/test-simplemerge.py	Thu Mar 22 21:56:20 2018 +0900
@@ -22,6 +22,10 @@
     util,
 )
 
+from mercurial.utils import (
+    stringutil,
+)
+
 TestCase = unittest.TestCase
 # bzr compatible interface, for the tests
 class Merge3(simplemerge.Merge3Text):
@@ -34,7 +38,8 @@
         basetext = '\n'.join([i.strip('\n') for i in base] + [''])
         atext = '\n'.join([i.strip('\n') for i in a] + [''])
         btext = '\n'.join([i.strip('\n') for i in b] + [''])
-        if util.binary(basetext) or util.binary(atext) or util.binary(btext):
+        if (stringutil.binary(basetext) or stringutil.binary(atext)
+            or stringutil.binary(btext)):
             raise error.Abort("don't know how to merge binary files")
         simplemerge.Merge3Text.__init__(self, basetext, atext, btext,
                                         base, a, b)
@@ -358,4 +363,3 @@
         unittest.main()
     finally:
         time.time = orig
-