py3: wrap tempfile.mkdtemp() to use bytes path
authorYuya Nishihara <yuya@tcha.org>
Sat, 26 May 2018 12:20:36 +0900
changeset 38165 2ce60954b1b7
parent 38164 aac4be30e250
child 38166 cc9aa88792fe
py3: wrap tempfile.mkdtemp() to use bytes path This also flips the default to use a bytes path on Python 3.
hgext/convert/darcs.py
hgext/extdiff.py
hgext/keyword.py
hgext/patchbomb.py
mercurial/bundlerepo.py
mercurial/filemerge.py
mercurial/patch.py
mercurial/pycompat.py
mercurial/upgrade.py
--- a/hgext/convert/darcs.py	Sat May 26 12:14:04 2018 +0900
+++ b/hgext/convert/darcs.py	Sat May 26 12:20:36 2018 +0900
@@ -10,10 +10,11 @@
 import os
 import re
 import shutil
-import tempfile
+
 from mercurial.i18n import _
 from mercurial import (
     error,
+    pycompat,
     util,
 )
 from mercurial.utils import dateutil
@@ -76,7 +77,7 @@
             self.ui.warn(_('failed to detect repository format!'))
 
     def before(self):
-        self.tmppath = tempfile.mkdtemp(
+        self.tmppath = pycompat.mkdtemp(
             prefix='convert-' + os.path.basename(self.path) + '-')
         output, status = self.run('init', repodir=self.tmppath)
         self.checkexit(status)
--- a/hgext/extdiff.py	Sat May 26 12:14:04 2018 +0900
+++ b/hgext/extdiff.py	Sat May 26 12:20:36 2018 +0900
@@ -71,7 +71,7 @@
 import re
 import shutil
 import stat
-import tempfile
+
 from mercurial.i18n import _
 from mercurial.node import (
     nullid,
@@ -210,7 +210,7 @@
         if not common:
             return 0
 
-    tmproot = tempfile.mkdtemp(prefix='extdiff.')
+    tmproot = pycompat.mkdtemp(prefix='extdiff.')
     try:
         if not opts.get('patch'):
             # Always make a copy of node1a (and node1b, if applicable)
--- a/hgext/keyword.py	Sat May 26 12:14:04 2018 +0900
+++ b/hgext/keyword.py	Sat May 26 12:20:36 2018 +0900
@@ -87,7 +87,6 @@
 
 import os
 import re
-import tempfile
 import weakref
 
 from mercurial.i18n import _
@@ -434,7 +433,7 @@
             ui.write('%s = %s\n' % (k, v))
 
     fn = 'demo.txt'
-    tmpdir = tempfile.mkdtemp('', 'kwdemo.')
+    tmpdir = pycompat.mkdtemp('', 'kwdemo.')
     ui.note(_('creating temporary repository at %s\n') % tmpdir)
     if repo is None:
         baseui = ui
--- a/hgext/patchbomb.py	Sat May 26 12:14:04 2018 +0900
+++ b/hgext/patchbomb.py	Sat May 26 12:20:36 2018 +0900
@@ -79,7 +79,6 @@
 import errno
 import os
 import socket
-import tempfile
 
 from mercurial.i18n import _
 from mercurial import (
@@ -317,7 +316,7 @@
     The bundle is a returned as a single in-memory binary blob.
     """
     ui = repo.ui
-    tmpdir = tempfile.mkdtemp(prefix='hg-email-bundle-')
+    tmpdir = pycompat.mkdtemp(prefix='hg-email-bundle-')
     tmpfn = os.path.join(tmpdir, 'bundle')
     btype = ui.config('patchbomb', 'bundletype')
     if btype:
--- a/mercurial/bundlerepo.py	Sat May 26 12:14:04 2018 +0900
+++ b/mercurial/bundlerepo.py	Sat May 26 12:20:36 2018 +0900
@@ -15,7 +15,6 @@
 
 import os
 import shutil
-import tempfile
 
 from .i18n import _
 from .node import nullid
@@ -270,7 +269,7 @@
         try:
             localrepo.localrepository.__init__(self, ui, repopath)
         except error.RepoError:
-            self._tempparent = tempfile.mkdtemp()
+            self._tempparent = pycompat.mkdtemp()
             localrepo.instance(ui, self._tempparent, 1)
             localrepo.localrepository.__init__(self, ui, self._tempparent)
         self.ui.setconfig('phases', 'publish', False, 'bundlerepo')
--- a/mercurial/filemerge.py	Sat May 26 12:14:04 2018 +0900
+++ b/mercurial/filemerge.py	Sat May 26 12:20:36 2018 +0900
@@ -11,7 +11,6 @@
 import os
 import re
 import shutil
-import tempfile
 
 from .i18n import _
 from .node import nullid, short
@@ -713,7 +712,7 @@
     tmproot = None
     tmprootprefix = repo.ui.config('experimental', 'mergetempdirprefix')
     if tmprootprefix:
-        tmproot = tempfile.mkdtemp(prefix=tmprootprefix)
+        tmproot = pycompat.mkdtemp(prefix=tmprootprefix)
 
     def maketempfrompath(prefix, path):
         fullbase, ext = os.path.splitext(path)
--- a/mercurial/patch.py	Sat May 26 12:14:04 2018 +0900
+++ b/mercurial/patch.py	Sat May 26 12:20:36 2018 +0900
@@ -18,7 +18,6 @@
 import posixpath
 import re
 import shutil
-import tempfile
 import zlib
 
 from .i18n import _
@@ -573,7 +572,7 @@
             self.size += len(data)
         else:
             if self.opener is None:
-                root = tempfile.mkdtemp(prefix='hg-patch-')
+                root = pycompat.mkdtemp(prefix='hg-patch-')
                 self.opener = vfsmod.vfs(root)
             # Avoid filename issues with these simple names
             fn = '%d' % self.created
--- a/mercurial/pycompat.py	Sat May 26 12:14:04 2018 +0900
+++ b/mercurial/pycompat.py	Sat May 26 12:20:36 2018 +0900
@@ -386,6 +386,9 @@
 def gnugetoptb(args, shortlist, namelist):
     return _getoptbwrapper(getopt.gnu_getopt, args, shortlist, namelist)
 
+def mkdtemp(suffix=b'', prefix=b'tmp', dir=None):
+    return tempfile.mkdtemp(suffix, prefix, dir)
+
 # text=True is not supported; use util.from/tonativeeol() instead
 def mkstemp(suffix=b'', prefix=b'tmp', dir=None):
     return tempfile.mkstemp(suffix, prefix, dir)
--- a/mercurial/upgrade.py	Sat May 26 12:14:04 2018 +0900
+++ b/mercurial/upgrade.py	Sat May 26 12:20:36 2018 +0900
@@ -8,7 +8,6 @@
 from __future__ import absolute_import
 
 import stat
-import tempfile
 
 from .i18n import _
 from . import (
@@ -18,6 +17,7 @@
     hg,
     localrepo,
     manifest,
+    pycompat,
     revlog,
     scmutil,
     util,
@@ -657,7 +657,7 @@
 
     ui.write(_('data fully migrated to temporary repository\n'))
 
-    backuppath = tempfile.mkdtemp(prefix='upgradebackup.', dir=srcrepo.path)
+    backuppath = pycompat.mkdtemp(prefix='upgradebackup.', dir=srcrepo.path)
     backupvfs = vfsmod.vfs(backuppath)
 
     # Make a backup of requires file first, as it is the first to be modified.
@@ -842,7 +842,7 @@
         # data. There are less heavyweight ways to do this, but it is easier
         # to create a new repo object than to instantiate all the components
         # (like the store) separately.
-        tmppath = tempfile.mkdtemp(prefix='upgrade.', dir=repo.path)
+        tmppath = pycompat.mkdtemp(prefix='upgrade.', dir=repo.path)
         backuppath = None
         try:
             ui.write(_('creating temporary repository to stage migrated '