[PATCH] py3: use pycompat.getcwd() instead of os.getcwd()

Pulkit Goyal 7895pulkit at gmail.com
Tue Nov 22 18:35:45 UTC 2016


# HG changeset patch
# User Pulkit Goyal <7895pulkit at gmail.com>
# Date 1479839591 -19800
#      Wed Nov 23 00:03:11 2016 +0530
# Node ID a05a33c431e39ea250261287863f4b6ede91ca91
# Parent  b8e4cce34013b1f564a334465813e8ef171e8834
py3: use pycompat.getcwd() instead of os.getcwd()

We have pycompat.getcwd() which returns bytes path on Python 3. This patch
changes most of the occurences of the os.getcwd() with pycompat one.

diff -r b8e4cce34013 -r a05a33c431e3 hgext/convert/cvs.py
--- a/hgext/convert/cvs.py	Tue Nov 22 22:40:37 2016 +0530
+++ b/hgext/convert/cvs.py	Wed Nov 23 00:03:11 2016 +0530
@@ -15,6 +15,7 @@
 from mercurial import (
     encoding,
     error,
+    pycompat,
     util,
 )
 
@@ -69,7 +70,7 @@
                 raise error.Abort(_('revision %s is not a patchset number')
                                  % self.revs[0])
 
-        d = os.getcwd()
+        d = pycompat.getcwd()
         try:
             os.chdir(self.path)
             id = None
diff -r b8e4cce34013 -r a05a33c431e3 hgext/convert/subversion.py
--- a/hgext/convert/subversion.py	Tue Nov 22 22:40:37 2016 +0530
+++ b/hgext/convert/subversion.py	Wed Nov 23 00:03:11 2016 +0530
@@ -12,6 +12,7 @@
 from mercurial import (
     encoding,
     error,
+    pycompat,
     scmutil,
     strutil,
     util,
@@ -1119,7 +1120,7 @@
         self.delexec = []
         self.copies = []
         self.wc = None
-        self.cwd = os.getcwd()
+        self.cwd = pycompat.getcwd()
 
         created = False
         if os.path.isfile(os.path.join(path, '.svn', 'entries')):
@@ -1139,7 +1140,8 @@
                         path = '/' + path
                     path = 'file://' + path
 
-            wcpath = os.path.join(os.getcwd(), os.path.basename(path) + '-wc')
+            wcpath = os.path.join(pycompat.getcwd(), os.path.basename(path) +
+                                '-wc')
             ui.status(_('initializing svn working copy %r\n')
                       % os.path.basename(wcpath))
             self.run0('checkout', path, wcpath)
diff -r b8e4cce34013 -r a05a33c431e3 hgext/mq.py
--- a/hgext/mq.py	Tue Nov 22 22:40:37 2016 +0530
+++ b/hgext/mq.py	Wed Nov 23 00:03:11 2016 +0530
@@ -87,6 +87,7 @@
     lock as lockmod,
     patch as patchmod,
     phases,
+    pycompat,
     registrar,
     revset,
     scmutil,
@@ -3523,7 +3524,7 @@
             raise error.Abort(_('only a local queue repository '
                                'may be initialized'))
     else:
-        repopath = cmdutil.findrepo(os.getcwd())
+        repopath = cmdutil.findrepo(pycompat.getcwd())
         if not repopath:
             raise error.Abort(_('there is no Mercurial repository here '
                                '(.hg not found)'))
diff -r b8e4cce34013 -r a05a33c431e3 mercurial/bundlerepo.py
--- a/mercurial/bundlerepo.py	Tue Nov 22 22:40:37 2016 +0530
+++ b/mercurial/bundlerepo.py	Wed Nov 23 00:03:11 2016 +0530
@@ -35,6 +35,7 @@
     node as nodemod,
     pathutil,
     phases,
+    pycompat,
     revlog,
     scmutil,
     util,
@@ -392,7 +393,7 @@
         return bundlepeer(self)
 
     def getcwd(self):
-        return os.getcwd() # always outside the repo
+        return pycompat.getcwd() # always outside the repo
 
     # Check if parents exist in localrepo before setting
     def setparents(self, p1, p2=nullid):
@@ -412,13 +413,13 @@
     parentpath = ui.config("bundle", "mainreporoot", "")
     if not parentpath:
         # try to find the correct path to the working directory repo
-        parentpath = cmdutil.findrepo(os.getcwd())
+        parentpath = cmdutil.findrepo(pycompat.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 = os.getcwd()
+        cwd = pycompat.getcwd()
         if parentpath == cwd:
             parentpath = ''
         else:
diff -r b8e4cce34013 -r a05a33c431e3 mercurial/cmdutil.py
--- a/mercurial/cmdutil.py	Tue Nov 22 22:40:37 2016 +0530
+++ b/mercurial/cmdutil.py	Wed Nov 23 00:03:11 2016 +0530
@@ -39,6 +39,7 @@
     patch,
     pathutil,
     phases,
+    pycompat,
     repair,
     revlog,
     revset,
@@ -571,7 +572,7 @@
             raise error.CommandError(cmd, _('invalid arguments'))
         if not os.path.isfile(file_):
             raise error.Abort(_("revlog '%s' not found") % file_)
-        r = revlog.revlog(scmutil.opener(os.getcwd(), audit=False),
+        r = revlog.revlog(scmutil.opener(pycompat.getcwd(), audit=False),
                           file_[:-2] + ".i")
     return r
 
@@ -2832,7 +2833,7 @@
         committext = buildcommittext(repo, ctx, subs, extramsg)
 
     # run editor in the repository root
-    olddir = os.getcwd()
+    olddir = pycompat.getcwd()
     os.chdir(repo.root)
 
     # make in-memory changes visible to external process
diff -r b8e4cce34013 -r a05a33c431e3 mercurial/commands.py
--- a/mercurial/commands.py	Tue Nov 22 22:40:37 2016 +0530
+++ b/mercurial/commands.py	Wed Nov 23 00:03:11 2016 +0530
@@ -2036,7 +2036,8 @@
     spaces = opts.get('spaces')
     dots = opts.get('dots')
     if file_:
-        rlog = revlog.revlog(scmutil.opener(os.getcwd(), audit=False), file_)
+        rlog = revlog.revlog(scmutil.opener(pycompat.getcwd(),
+                                audit=False), file_)
         revs = set((int(r) for r in revs))
         def events():
             for r in rlog:
@@ -2993,7 +2994,7 @@
 
     def complete(path, acceptable):
         dirstate = repo.dirstate
-        spec = os.path.normpath(os.path.join(os.getcwd(), path))
+        spec = os.path.normpath(os.path.join(pycompat.getcwd(), path))
         rootdir = repo.root + os.sep
         if spec != repo.root and not spec.startswith(rootdir):
             return [], []
diff -r b8e4cce34013 -r a05a33c431e3 mercurial/commandserver.py
--- a/mercurial/commandserver.py	Tue Nov 22 22:40:37 2016 +0530
+++ b/mercurial/commandserver.py	Wed Nov 23 00:03:11 2016 +0530
@@ -21,6 +21,7 @@
 from . import (
     encoding,
     error,
+    pycompat,
     util,
 )
 
@@ -152,7 +153,7 @@
     based stream to fout.
     """
     def __init__(self, ui, repo, fin, fout):
-        self.cwd = os.getcwd()
+        self.cwd = pycompat.getcwd()
 
         # developer config: cmdserver.log
         logpath = ui.config("cmdserver", "log", None)
diff -r b8e4cce34013 -r a05a33c431e3 mercurial/debugcommands.py
--- a/mercurial/debugcommands.py	Tue Nov 22 22:40:37 2016 +0530
+++ b/mercurial/debugcommands.py	Wed Nov 23 00:03:11 2016 +0530
@@ -7,8 +7,6 @@
 
 from __future__ import absolute_import
 
-import os
-
 from .i18n import _
 from .node import (
     hex,
@@ -20,6 +18,7 @@
     dagparser,
     error,
     lock as lockmod,
+    pycompat,
     revlog,
     scmutil,
     simplemerge,
@@ -36,7 +35,7 @@
     """find the ancestor revision of two revisions in a given index"""
     if len(args) == 3:
         index, rev1, rev2 = args
-        r = revlog.revlog(scmutil.opener(os.getcwd(), audit=False), index)
+        r = revlog.revlog(scmutil.opener(pycompat.getcwd(), audit=False), index)
         lookup = r.lookup
     elif len(args) == 2:
         if not repo:
diff -r b8e4cce34013 -r a05a33c431e3 mercurial/dirstate.py
--- a/mercurial/dirstate.py	Tue Nov 22 22:40:37 2016 +0530
+++ b/mercurial/dirstate.py	Wed Nov 23 00:03:11 2016 +0530
@@ -271,7 +271,7 @@
 
     @propertycache
     def _cwd(self):
-        return os.getcwd()
+        return pycompat.getcwd()
 
     def getcwd(self):
         '''Return the path from which a canonical path is calculated.
diff -r b8e4cce34013 -r a05a33c431e3 mercurial/dispatch.py
--- a/mercurial/dispatch.py	Tue Nov 22 22:40:37 2016 +0530
+++ b/mercurial/dispatch.py	Wed Nov 23 00:03:11 2016 +0530
@@ -880,7 +880,7 @@
                         if not path:
                             raise error.RepoError(_("no repository found in"
                                                     " '%s' (.hg not found)")
-                                                  % os.getcwd())
+                                                  % pycompat.getcwd())
                         raise
             if repo:
                 ui = repo.ui
diff -r b8e4cce34013 -r a05a33c431e3 mercurial/hook.py
--- a/mercurial/hook.py	Tue Nov 22 22:40:37 2016 +0530
+++ b/mercurial/hook.py	Wed Nov 23 00:03:11 2016 +0530
@@ -16,6 +16,7 @@
     demandimport,
     error,
     extensions,
+    pycompat,
     util,
 )
 
@@ -141,7 +142,7 @@
     if repo:
         cwd = repo.root
     else:
-        cwd = os.getcwd()
+        cwd = pycompat.getcwd()
     r = ui.system(cmd, environ=env, cwd=cwd)
 
     duration = time.time() - starttime
diff -r b8e4cce34013 -r a05a33c431e3 mercurial/merge.py
--- a/mercurial/merge.py	Tue Nov 22 22:40:37 2016 +0530
+++ b/mercurial/merge.py	Wed Nov 23 00:03:11 2016 +0530
@@ -28,6 +28,7 @@
     error,
     filemerge,
     obsolete,
+    pycompat,
     scmutil,
     subrepo,
     util,
@@ -1040,7 +1041,7 @@
     wjoin = repo.wjoin
     audit = repo.wvfs.audit
     try:
-        cwd = os.getcwd()
+        cwd = pycompat.getcwd()
     except OSError as err:
         if err.errno != errno.ENOENT:
             raise
@@ -1066,7 +1067,7 @@
         # cwd was present before we started to remove files
         # let's check if it is present after we removed them
         try:
-            os.getcwd()
+            pycompat.getcwd()
         except OSError as err:
             if err.errno != errno.ENOENT:
                 raise
diff -r b8e4cce34013 -r a05a33c431e3 mercurial/ui.py
--- a/mercurial/ui.py	Tue Nov 22 22:40:37 2016 +0530
+++ b/mercurial/ui.py	Wed Nov 23 00:03:11 2016 +0530
@@ -27,6 +27,7 @@
     error,
     formatter,
     progress,
+    pycompat,
     scmutil,
     util,
 )
@@ -227,7 +228,7 @@
         if section in (None, 'paths'):
             # expand vars and ~
             # translate paths relative to root (or home) into absolute paths
-            root = root or os.getcwd()
+            root = root or pycompat.getcwd()
             for c in self._tcfg, self._ucfg, self._ocfg:
                 for n, p in c.items('paths'):
                     # Ignore sub-options.
diff -r b8e4cce34013 -r a05a33c431e3 mercurial/unionrepo.py
--- a/mercurial/unionrepo.py	Tue Nov 22 22:40:37 2016 +0530
+++ b/mercurial/unionrepo.py	Wed Nov 23 00:03:11 2016 +0530
@@ -13,8 +13,6 @@
 
 from __future__ import absolute_import
 
-import os
-
 from .i18n import _
 from .node import nullid
 
@@ -27,6 +25,7 @@
     manifest,
     mdiff,
     pathutil,
+    pycompat,
     revlog,
     scmutil,
     util,
@@ -229,7 +228,7 @@
         return unionpeer(self)
 
     def getcwd(self):
-        return os.getcwd() # always outside the repo
+        return pycompat.getcwd() # always outside the repo
 
 def instance(ui, path, create):
     if create:
@@ -237,13 +236,13 @@
     parentpath = ui.config("bundle", "mainreporoot", "")
     if not parentpath:
         # try to find the correct path to the working directory repo
-        parentpath = cmdutil.findrepo(os.getcwd())
+        parentpath = cmdutil.findrepo(pycompat.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 = os.getcwd()
+        cwd = pycompat.getcwd()
         if parentpath == cwd:
             parentpath = ''
         else:


More information about the Mercurial-devel mailing list