changeset 30519:20a42325fdef

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.
author Pulkit Goyal <7895pulkit@gmail.com>
date Wed, 23 Nov 2016 00:03:11 +0530
parents a8b17859684a
children 4338f87dbf6f
files hgext/convert/cvs.py hgext/convert/subversion.py hgext/mq.py mercurial/bundlerepo.py mercurial/cmdutil.py mercurial/commands.py mercurial/commandserver.py mercurial/debugcommands.py mercurial/dirstate.py mercurial/dispatch.py mercurial/hook.py mercurial/merge.py mercurial/ui.py mercurial/unionrepo.py
diffstat 14 files changed, 35 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/convert/cvs.py	Wed Aug 17 20:57:15 2016 -0700
+++ 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
--- a/hgext/convert/subversion.py	Wed Aug 17 20:57:15 2016 -0700
+++ 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)
--- a/hgext/mq.py	Wed Aug 17 20:57:15 2016 -0700
+++ 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)'))
--- a/mercurial/bundlerepo.py	Wed Aug 17 20:57:15 2016 -0700
+++ 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:
--- a/mercurial/cmdutil.py	Wed Aug 17 20:57:15 2016 -0700
+++ b/mercurial/cmdutil.py	Wed Nov 23 00:03:11 2016 +0530
@@ -38,6 +38,7 @@
     patch,
     pathutil,
     phases,
+    pycompat,
     repair,
     revlog,
     revset,
@@ -570,7 +571,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
 
@@ -2744,7 +2745,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
--- a/mercurial/commands.py	Wed Aug 17 20:57:15 2016 -0700
+++ b/mercurial/commands.py	Wed Nov 23 00:03:11 2016 +0530
@@ -2630,7 +2630,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 [], []
--- a/mercurial/commandserver.py	Wed Aug 17 20:57:15 2016 -0700
+++ 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)
--- a/mercurial/debugcommands.py	Wed Aug 17 20:57:15 2016 -0700
+++ b/mercurial/debugcommands.py	Wed Nov 23 00:03:11 2016 +0530
@@ -8,7 +8,6 @@
 from __future__ import absolute_import
 
 import operator
-import os
 import random
 
 from .i18n import _
@@ -30,6 +29,7 @@
     hg,
     localrepo,
     lock as lockmod,
+    pycompat,
     revlog,
     scmutil,
     setdiscovery,
@@ -50,7 +50,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:
@@ -385,7 +385,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:
--- a/mercurial/dirstate.py	Wed Aug 17 20:57:15 2016 -0700
+++ 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.
--- a/mercurial/dispatch.py	Wed Aug 17 20:57:15 2016 -0700
+++ 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
--- a/mercurial/hook.py	Wed Aug 17 20:57:15 2016 -0700
+++ 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
--- a/mercurial/merge.py	Wed Aug 17 20:57:15 2016 -0700
+++ 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
--- a/mercurial/ui.py	Wed Aug 17 20:57:15 2016 -0700
+++ 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.
--- a/mercurial/unionrepo.py	Wed Aug 17 20:57:15 2016 -0700
+++ 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: