changeset 39818:24e493ec2229

py3: rename pycompat.getcwd() to encoding.getcwd() (API) We need to avoid os.getcwdb() on Windows to avoid DeprecationWarnings, and we need encoding.strtolocal() to encode the result of os.getcwd().
author Matt Harbison <matt_harbison@yahoo.com>
date Fri, 21 Sep 2018 19:48:23 -0400
parents 94c25f694ec3
children fb628c048d64
files contrib/check-code.py hgext/convert/cvs.py hgext/convert/subversion.py hgext/fastannotate/commands.py hgext/mq.py hgext/narrow/narrowcommands.py mercurial/bundlerepo.py mercurial/cmdutil.py mercurial/commandserver.py mercurial/debugcommands.py mercurial/dirstate.py mercurial/dispatch.py mercurial/encoding.py mercurial/hook.py mercurial/merge.py mercurial/pycompat.py mercurial/ui.py mercurial/unionrepo.py mercurial/win32.py
diffstat 19 files changed, 40 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/contrib/check-code.py	Mon Sep 24 22:46:22 2018 -0400
+++ b/contrib/check-code.py	Fri Sep 21 19:48:23 2018 -0400
@@ -503,7 +503,7 @@
   [
     (r'os\.environ', "use encoding.environ instead (py3)", r'#.*re-exports'),
     (r'os\.name', "use pycompat.osname instead (py3)"),
-    (r'os\.getcwd', "use pycompat.getcwd instead (py3)"),
+    (r'os\.getcwd', "use encoding.getcwd instead (py3)", r'#.*re-exports'),
     (r'os\.sep', "use pycompat.ossep instead (py3)"),
     (r'os\.pathsep', "use pycompat.ospathsep instead (py3)"),
     (r'os\.altsep', "use pycompat.osaltsep instead (py3)"),
--- a/hgext/convert/cvs.py	Mon Sep 24 22:46:22 2018 -0400
+++ b/hgext/convert/cvs.py	Fri Sep 21 19:48:23 2018 -0400
@@ -15,7 +15,6 @@
 from mercurial import (
     encoding,
     error,
-    pycompat,
     util,
 )
 from mercurial.utils import (
@@ -74,7 +73,7 @@
                 raise error.Abort(_('revision %s is not a patchset number')
                                  % self.revs[0])
 
-        d = pycompat.getcwd()
+        d = encoding.getcwd()
         try:
             os.chdir(self.path)
             id = None
--- a/hgext/convert/subversion.py	Mon Sep 24 22:46:22 2018 -0400
+++ b/hgext/convert/subversion.py	Fri Sep 21 19:48:23 2018 -0400
@@ -1127,7 +1127,7 @@
         self.delexec = []
         self.copies = []
         self.wc = None
-        self.cwd = pycompat.getcwd()
+        self.cwd = encoding.getcwd()
 
         created = False
         if os.path.isfile(os.path.join(path, '.svn', 'entries')):
@@ -1147,7 +1147,7 @@
                         path = '/' + path
                     path = 'file://' + path
 
-            wcpath = os.path.join(pycompat.getcwd(), os.path.basename(path) +
+            wcpath = os.path.join(encoding.getcwd(), os.path.basename(path) +
                                 '-wc')
             ui.status(_('initializing svn working copy %r\n')
                       % os.path.basename(wcpath))
--- a/hgext/fastannotate/commands.py	Mon Sep 24 22:46:22 2018 -0400
+++ b/hgext/fastannotate/commands.py	Fri Sep 21 19:48:23 2018 -0400
@@ -12,6 +12,7 @@
 from mercurial.i18n import _
 from mercurial import (
     commands,
+    encoding,
     error,
     extensions,
     patch,
@@ -41,7 +42,7 @@
     if perfhack:
         # cwd related to reporoot
         reporoot = os.path.dirname(repo.path)
-        reldir = os.path.relpath(pycompat.getcwd(), reporoot)
+        reldir = os.path.relpath(encoding.getcwd(), reporoot)
         if reldir == '.':
             reldir = ''
         if any(opts.get(o[1]) for o in commands.walkopts): # a)
--- a/hgext/mq.py	Mon Sep 24 22:46:22 2018 -0400
+++ b/hgext/mq.py	Fri Sep 21 19:48:23 2018 -0400
@@ -3585,7 +3585,7 @@
             raise error.Abort(_('only a local queue repository '
                                'may be initialized'))
     else:
-        repopath = cmdutil.findrepo(pycompat.getcwd())
+        repopath = cmdutil.findrepo(encoding.getcwd())
         if not repopath:
             raise error.Abort(_('there is no Mercurial repository here '
                                '(.hg not found)'))
--- a/hgext/narrow/narrowcommands.py	Mon Sep 24 22:46:22 2018 -0400
+++ b/hgext/narrow/narrowcommands.py	Fri Sep 21 19:48:23 2018 -0400
@@ -69,7 +69,7 @@
     narrowspecfile = opts['narrowspec']
 
     if narrowspecfile:
-        filepath = os.path.join(pycompat.getcwd(), narrowspecfile)
+        filepath = os.path.join(encoding.getcwd(), narrowspecfile)
         ui.status(_("reading narrowspec from '%s'\n") % filepath)
         try:
             fdata = util.readfile(filepath)
@@ -349,7 +349,7 @@
     newrules = opts.get('import_rules')
     if newrules:
         try:
-            filepath = os.path.join(pycompat.getcwd(), newrules)
+            filepath = os.path.join(encoding.getcwd(), newrules)
             fdata = util.readfile(filepath)
         except IOError as inst:
             raise error.Abort(_("cannot read narrowspecs from '%s': %s") %
--- a/mercurial/bundlerepo.py	Mon Sep 24 22:46:22 2018 -0400
+++ b/mercurial/bundlerepo.py	Fri Sep 21 19:48:23 2018 -0400
@@ -25,6 +25,7 @@
     changelog,
     cmdutil,
     discovery,
+    encoding,
     error,
     exchange,
     filelog,
@@ -432,7 +433,7 @@
         return bundlepeer(self)
 
     def getcwd(self):
-        return pycompat.getcwd() # always outside the repo
+        return encoding.getcwd() # always outside the repo
 
     # Check if parents exist in localrepo before setting
     def setparents(self, p1, p2=nullid):
@@ -452,13 +453,13 @@
     parentpath = ui.config("bundle", "mainreporoot")
     if not parentpath:
         # try to find the correct path to the working directory repo
-        parentpath = cmdutil.findrepo(pycompat.getcwd())
+        parentpath = cmdutil.findrepo(encoding.getcwd())
         if parentpath is None:
             parentpath = ''
     if parentpath:
         # Try to make the full path relative so we get a nice, short URL.
         # In particular, we don't want temp dir names in test outputs.
-        cwd = pycompat.getcwd()
+        cwd = encoding.getcwd()
         if parentpath == cwd:
             parentpath = ''
         else:
--- a/mercurial/cmdutil.py	Mon Sep 24 22:46:22 2018 -0400
+++ b/mercurial/cmdutil.py	Fri Sep 21 19:48:23 2018 -0400
@@ -581,7 +581,7 @@
     unresolvedlist = [f for f in mergestate.unresolved() if m(f)]
     if unresolvedlist:
         mergeliststr = '\n'.join(
-            ['    %s' % util.pathto(repo.root, pycompat.getcwd(), path)
+            ['    %s' % util.pathto(repo.root, encoding.getcwd(), path)
              for path in unresolvedlist])
         msg = _('''Unresolved merge conflicts:
 
@@ -1110,7 +1110,7 @@
             raise error.CommandError(cmd, _('invalid arguments'))
         if not os.path.isfile(file_):
             raise error.Abort(_("revlog '%s' not found") % file_)
-        r = revlog.revlog(vfsmod.vfs(pycompat.getcwd(), audit=False),
+        r = revlog.revlog(vfsmod.vfs(encoding.getcwd(), audit=False),
                           file_[:-2] + ".i")
     return r
 
@@ -2629,7 +2629,7 @@
         committext = buildcommittext(repo, ctx, subs, extramsg)
 
     # run editor in the repository root
-    olddir = pycompat.getcwd()
+    olddir = encoding.getcwd()
     os.chdir(repo.root)
 
     # make in-memory changes visible to external process
--- a/mercurial/commandserver.py	Mon Sep 24 22:46:22 2018 -0400
+++ b/mercurial/commandserver.py	Fri Sep 21 19:48:23 2018 -0400
@@ -26,7 +26,6 @@
 from . import (
     encoding,
     error,
-    pycompat,
     util,
 )
 from .utils import (
@@ -161,7 +160,7 @@
     based stream to fout.
     """
     def __init__(self, ui, repo, fin, fout):
-        self.cwd = pycompat.getcwd()
+        self.cwd = encoding.getcwd()
 
         # developer config: cmdserver.log
         logpath = ui.config("cmdserver", "log")
--- a/mercurial/debugcommands.py	Mon Sep 24 22:46:22 2018 -0400
+++ b/mercurial/debugcommands.py	Fri Sep 21 19:48:23 2018 -0400
@@ -99,7 +99,7 @@
     """find the ancestor revision of two revisions in a given index"""
     if len(args) == 3:
         index, rev1, rev2 = args
-        r = revlog.revlog(vfsmod.vfs(pycompat.getcwd(), audit=False), index)
+        r = revlog.revlog(vfsmod.vfs(encoding.getcwd(), audit=False), index)
         lookup = r.lookup
     elif len(args) == 2:
         if not repo:
@@ -503,7 +503,7 @@
     spaces = opts.get(r'spaces')
     dots = opts.get(r'dots')
     if file_:
-        rlog = revlog.revlog(vfsmod.vfs(pycompat.getcwd(), audit=False),
+        rlog = revlog.revlog(vfsmod.vfs(encoding.getcwd(), audit=False),
                              file_)
         revs = set((int(r) for r in revs))
         def events():
@@ -1754,7 +1754,7 @@
 
     def complete(path, acceptable):
         dirstate = repo.dirstate
-        spec = os.path.normpath(os.path.join(pycompat.getcwd(), path))
+        spec = os.path.normpath(os.path.join(encoding.getcwd(), path))
         rootdir = repo.root + pycompat.ossep
         if spec != repo.root and not spec.startswith(rootdir):
             return [], []
--- a/mercurial/dirstate.py	Mon Sep 24 22:46:22 2018 -0400
+++ b/mercurial/dirstate.py	Fri Sep 21 19:48:23 2018 -0400
@@ -210,7 +210,7 @@
         forcecwd = self._ui.config('ui', 'forcecwd')
         if forcecwd:
             return forcecwd
-        return pycompat.getcwd()
+        return encoding.getcwd()
 
     def getcwd(self):
         '''Return the path from which a canonical path is calculated.
--- a/mercurial/dispatch.py	Mon Sep 24 22:46:22 2018 -0400
+++ b/mercurial/dispatch.py	Fri Sep 21 19:48:23 2018 -0400
@@ -748,7 +748,7 @@
     """
     if wd is None:
         try:
-            wd = pycompat.getcwd()
+            wd = encoding.getcwd()
         except OSError as e:
             raise error.Abort(_("error getting current working directory: %s") %
                               encoding.strtolocal(e.strerror))
@@ -968,7 +968,7 @@
                         if not path:
                             raise error.RepoError(_("no repository found in"
                                                     " '%s' (.hg not found)")
-                                                  % pycompat.getcwd())
+                                                  % encoding.getcwd())
                         raise
             if repo:
                 ui = repo.ui
--- a/mercurial/encoding.py	Mon Sep 24 22:46:22 2018 -0400
+++ b/mercurial/encoding.py	Fri Sep 21 19:48:23 2018 -0400
@@ -233,6 +233,13 @@
     environ = dict((tolocal(k.encode(u'utf-8')), tolocal(v.encode(u'utf-8')))
                    for k, v in os.environ.items())  # re-exports
 
+if pycompat.ispy3:
+    # os.getcwd() on Python 3 returns string, but it has os.getcwdb() which
+    # returns bytes.
+    getcwd = os.getcwdb  # re-exports
+else:
+    getcwd = os.getcwd  # re-exports
+
 # How to treat ambiguous-width characters. Set to 'wide' to treat as wide.
 _wide = _sysstr(environ.get("HGENCODINGAMBIGUOUS", "narrow") == "wide"
                 and "WFA" or "WF")
--- a/mercurial/hook.py	Mon Sep 24 22:46:22 2018 -0400
+++ b/mercurial/hook.py	Fri Sep 21 19:48:23 2018 -0400
@@ -150,7 +150,7 @@
     if repo:
         cwd = repo.root
     else:
-        cwd = pycompat.getcwd()
+        cwd = encoding.getcwd()
     r = ui.system(cmd, environ=env, cwd=cwd, blockedtag='exthook-%s' % (name,))
 
     duration = util.timer() - starttime
--- a/mercurial/merge.py	Mon Sep 24 22:46:22 2018 -0400
+++ b/mercurial/merge.py	Fri Sep 21 19:48:23 2018 -0400
@@ -27,6 +27,7 @@
 )
 from . import (
     copies,
+    encoding,
     error,
     filemerge,
     match as matchmod,
@@ -1436,7 +1437,7 @@
 
 def _getcwd():
     try:
-        return pycompat.getcwd()
+        return encoding.getcwd()
     except OSError as err:
         if err.errno == errno.ENOENT:
             return None
--- a/mercurial/pycompat.py	Mon Sep 24 22:46:22 2018 -0400
+++ b/mercurial/pycompat.py	Fri Sep 21 19:48:23 2018 -0400
@@ -97,9 +97,7 @@
     osaltsep = os.altsep
     if osaltsep:
         osaltsep = osaltsep.encode('ascii')
-    # os.getcwd() on Python 3 returns string, but it has os.getcwdb() which
-    # returns bytes.
-    getcwd = os.getcwdb
+
     sysplatform = sys.platform.encode('ascii')
     sysexecutable = sys.executable
     if sysexecutable:
@@ -393,7 +391,6 @@
     if getattr(sys, 'argv', None) is not None:
         sysargv = sys.argv
     sysplatform = sys.platform
-    getcwd = os.getcwd
     sysexecutable = sys.executable
     shlexsplit = shlex.split
     bytesio = cStringIO.StringIO
--- a/mercurial/ui.py	Mon Sep 24 22:46:22 2018 -0400
+++ b/mercurial/ui.py	Fri Sep 21 19:48:23 2018 -0400
@@ -447,7 +447,7 @@
         if section in (None, 'paths'):
             # expand vars and ~
             # translate paths relative to root (or home) into absolute paths
-            root = root or pycompat.getcwd()
+            root = root or encoding.getcwd()
             for c in self._tcfg, self._ucfg, self._ocfg:
                 for n, p in c.items('paths'):
                     # Ignore sub-options.
--- a/mercurial/unionrepo.py	Mon Sep 24 22:46:22 2018 -0400
+++ b/mercurial/unionrepo.py	Fri Sep 21 19:48:23 2018 -0400
@@ -19,13 +19,13 @@
 from . import (
     changelog,
     cmdutil,
+    encoding,
     error,
     filelog,
     localrepo,
     manifest,
     mdiff,
     pathutil,
-    pycompat,
     revlog,
     util,
     vfs as vfsmod,
@@ -240,7 +240,7 @@
         return unionpeer(self)
 
     def getcwd(self):
-        return pycompat.getcwd() # always outside the repo
+        return encoding.getcwd() # always outside the repo
 
 def instance(ui, path, create, intents=None, createopts=None):
     if create:
@@ -248,13 +248,13 @@
     parentpath = ui.config("bundle", "mainreporoot")
     if not parentpath:
         # try to find the correct path to the working directory repo
-        parentpath = cmdutil.findrepo(pycompat.getcwd())
+        parentpath = cmdutil.findrepo(encoding.getcwd())
         if parentpath is None:
             parentpath = ''
     if parentpath:
         # Try to make the full path relative so we get a nice, short URL.
         # In particular, we don't want temp dir names in test outputs.
-        cwd = pycompat.getcwd()
+        cwd = encoding.getcwd()
         if parentpath == cwd:
             parentpath = ''
         else:
--- a/mercurial/win32.py	Mon Sep 24 22:46:22 2018 -0400
+++ b/mercurial/win32.py	Fri Sep 21 19:48:23 2018 -0400
@@ -584,7 +584,7 @@
     # TODO: CreateProcessW on py3?
     res = _kernel32.CreateProcessA(
         None, encoding.strtolocal(args), None, None, False, _CREATE_NO_WINDOW,
-        env, pycompat.getcwd(), ctypes.byref(si), ctypes.byref(pi))
+        env, encoding.getcwd(), ctypes.byref(si), ctypes.byref(pi))
     if not res:
         raise ctypes.WinError()