py3: wrap tempfile.mkstemp() to use bytes path
This patch just flips the default to use a bytes path on Python 3.
ca1cf9b3cce7 is backed out as the bundlepath should be bytes now.
--- a/hgext/convert/subversion.py Thu May 03 18:39:58 2018 +0900
+++ b/hgext/convert/subversion.py Sat May 26 12:14:04 2018 +0900
@@ -5,7 +5,6 @@
import os
import re
-import tempfile
import xml.dom.minidom
from mercurial.i18n import _
@@ -1225,7 +1224,7 @@
wdest = self.wjoin(dest)
exists = os.path.lexists(wdest)
if exists:
- fd, tempname = tempfile.mkstemp(
+ fd, tempname = pycompat.mkstemp(
prefix='hg-copy-', dir=os.path.dirname(wdest))
os.close(fd)
os.unlink(tempname)
@@ -1313,7 +1312,7 @@
self.xargs(self.setexec, 'propset', 'svn:executable', '*')
self.setexec = []
- fd, messagefile = tempfile.mkstemp(prefix='hg-convert-')
+ fd, messagefile = pycompat.mkstemp(prefix='hg-convert-')
fp = os.fdopen(fd, r'wb')
fp.write(util.tonativeeol(commit.desc))
fp.close()
--- a/hgext/gpg.py Thu May 03 18:39:58 2018 +0900
+++ b/hgext/gpg.py Sat May 26 12:14:04 2018 +0900
@@ -9,7 +9,6 @@
import binascii
import os
-import tempfile
from mercurial.i18n import _
from mercurial import (
@@ -61,11 +60,11 @@
sigfile = datafile = None
try:
# create temporary files
- fd, sigfile = tempfile.mkstemp(prefix="hg-gpg-", suffix=".sig")
+ fd, sigfile = pycompat.mkstemp(prefix="hg-gpg-", suffix=".sig")
fp = os.fdopen(fd, r'wb')
fp.write(sig)
fp.close()
- fd, datafile = tempfile.mkstemp(prefix="hg-gpg-", suffix=".txt")
+ fd, datafile = pycompat.mkstemp(prefix="hg-gpg-", suffix=".txt")
fp = os.fdopen(fd, r'wb')
fp.write(data)
fp.close()
--- a/hgext/infinitepush/__init__.py Thu May 03 18:39:58 2018 +0900
+++ b/hgext/infinitepush/__init__.py Sat May 26 12:14:04 2018 +0900
@@ -94,7 +94,6 @@
import re
import socket
import subprocess
-import tempfile
import time
from mercurial.node import (
@@ -912,7 +911,7 @@
# storing the bundle in the bundlestore
buf = util.chunkbuffer(bundler.getchunks())
- fd, bundlefile = tempfile.mkstemp()
+ fd, bundlefile = pycompat.mkstemp()
try:
try:
fp = os.fdopen(fd, r'wb')
@@ -998,7 +997,7 @@
# If commits were sent, store them
if cgparams:
buf = util.chunkbuffer(bundler.getchunks())
- fd, bundlefile = tempfile.mkstemp()
+ fd, bundlefile = pycompat.mkstemp()
try:
try:
fp = os.fdopen(fd, r'wb')
@@ -1023,8 +1022,7 @@
bundle = None
try: # guards bundle
- bundlepath = "bundle:%s+%s" % (op.repo.root,
- pycompat.fsencode(bundlefile))
+ bundlepath = "bundle:%s+%s" % (op.repo.root, bundlefile)
bundle = hg.repository(op.repo.ui, bundlepath)
bookmark = params.get('bookmark')
@@ -1111,7 +1109,7 @@
bundler.addpart(cgpart)
buf = util.chunkbuffer(bundler.getchunks())
- fd, bundlefile = tempfile.mkstemp()
+ fd, bundlefile = pycompat.mkstemp()
try:
try:
fp = os.fdopen(fd, r'wb')
--- a/hgext/infinitepush/common.py Thu May 03 18:39:58 2018 +0900
+++ b/hgext/infinitepush/common.py Sat May 26 12:14:04 2018 +0900
@@ -6,13 +6,13 @@
from __future__ import absolute_import
import os
-import tempfile
from mercurial.node import hex
from mercurial import (
error,
extensions,
+ pycompat,
)
def isremotebooksenabled(ui):
@@ -30,7 +30,7 @@
def _makebundlefromraw(data):
fp = None
- fd, bundlefile = tempfile.mkstemp()
+ fd, bundlefile = pycompat.mkstemp()
try: # guards bundlefile
try: # guards fp
fp = os.fdopen(fd, 'wb')
--- a/hgext/transplant.py Thu May 03 18:39:58 2018 +0900
+++ b/hgext/transplant.py Sat May 26 12:14:04 2018 +0900
@@ -16,7 +16,7 @@
from __future__ import absolute_import
import os
-import tempfile
+
from mercurial.i18n import _
from mercurial import (
bundlerepo,
@@ -215,7 +215,7 @@
if skipmerge:
patchfile = None
else:
- fd, patchfile = tempfile.mkstemp(prefix='hg-transplant-')
+ fd, patchfile = pycompat.mkstemp(prefix='hg-transplant-')
fp = os.fdopen(fd, r'wb')
gen = patch.diff(source, parent, node, opts=diffopts)
for chunk in gen:
@@ -263,7 +263,7 @@
self.ui.status(_('filtering %s\n') % patchfile)
user, date, msg = (changelog[1], changelog[2], changelog[4])
- fd, headerfile = tempfile.mkstemp(prefix='hg-transplant-')
+ fd, headerfile = pycompat.mkstemp(prefix='hg-transplant-')
fp = os.fdopen(fd, r'wb')
fp.write("# HG changeset patch\n")
fp.write("# User %s\n" % user)
--- a/mercurial/changegroup.py Thu May 03 18:39:58 2018 +0900
+++ b/mercurial/changegroup.py Sat May 26 12:14:04 2018 +0900
@@ -9,7 +9,6 @@
import os
import struct
-import tempfile
import weakref
from .i18n import _
@@ -80,7 +79,7 @@
# small (4k is common on Linux).
fh = open(filename, "wb", 131072)
else:
- fd, filename = tempfile.mkstemp(prefix="hg-bundle-", suffix=".hg")
+ fd, filename = pycompat.mkstemp(prefix="hg-bundle-", suffix=".hg")
fh = os.fdopen(fd, r"wb")
cleanup = filename
for c in chunks:
--- a/mercurial/cmdutil.py Thu May 03 18:39:58 2018 +0900
+++ b/mercurial/cmdutil.py Sat May 26 12:14:04 2018 +0900
@@ -10,7 +10,6 @@
import errno
import os
import re
-import tempfile
from .i18n import _
from .node import (
@@ -329,7 +328,7 @@
try:
# backup continues
for f in tobackup:
- fd, tmpname = tempfile.mkstemp(prefix=f.replace('/', '_')+'.',
+ fd, tmpname = pycompat.mkstemp(prefix=f.replace('/', '_') + '.',
dir=backupdir)
os.close(fd)
ui.debug('backup %r as %r\n' % (f, tmpname))
--- a/mercurial/debugcommands.py Thu May 03 18:39:58 2018 +0900
+++ b/mercurial/debugcommands.py Sat May 26 12:14:04 2018 +0900
@@ -1142,7 +1142,7 @@
opts = pycompat.byteskwargs(opts)
def writetemp(contents):
- (fd, name) = tempfile.mkstemp(prefix="hg-debuginstall-")
+ (fd, name) = pycompat.mkstemp(prefix="hg-debuginstall-")
f = os.fdopen(fd, r"wb")
f.write(contents)
f.close()
--- a/mercurial/filemerge.py Thu May 03 18:39:58 2018 +0900
+++ b/mercurial/filemerge.py Sat May 26 12:14:04 2018 +0900
@@ -724,7 +724,7 @@
name += ext
f = open(name, r"wb")
else:
- fd, name = tempfile.mkstemp(prefix=pre + '.', suffix=ext)
+ fd, name = pycompat.mkstemp(prefix=pre + '.', suffix=ext)
f = os.fdopen(fd, r"wb")
return f, name
--- a/mercurial/httppeer.py Thu May 03 18:39:58 2018 +0900
+++ b/mercurial/httppeer.py Sat May 26 12:14:04 2018 +0900
@@ -13,7 +13,6 @@
import os
import socket
import struct
-import tempfile
import weakref
from .i18n import _
@@ -519,7 +518,7 @@
filename = None
try:
# dump bundle to disk
- fd, filename = tempfile.mkstemp(prefix="hg-bundle-", suffix=".hg")
+ fd, filename = pycompat.mkstemp(prefix="hg-bundle-", suffix=".hg")
fh = os.fdopen(fd, r"wb")
d = fp.read(4096)
while d:
--- a/mercurial/patch.py Thu May 03 18:39:58 2018 +0900
+++ b/mercurial/patch.py Sat May 26 12:14:04 2018 +0900
@@ -211,7 +211,7 @@
Any item can be missing from the dictionary. If filename is missing,
fileobj did not contain a patch. Caller must unlink filename when done.'''
- fd, tmpname = tempfile.mkstemp(prefix='hg-patch-')
+ fd, tmpname = pycompat.mkstemp(prefix='hg-patch-')
tmpfp = os.fdopen(fd, r'wb')
try:
yield _extract(ui, fileobj, tmpname, tmpfp)
@@ -1109,7 +1109,7 @@
all lines of the hunk are removed, then the edit is aborted and
the hunk is left unchanged.
""")
- (patchfd, patchfn) = tempfile.mkstemp(prefix="hg-editor-",
+ (patchfd, patchfn) = pycompat.mkstemp(prefix="hg-editor-",
suffix=".diff")
ncpatchfp = None
try:
--- a/mercurial/posix.py Thu May 03 18:39:58 2018 +0900
+++ b/mercurial/posix.py Sat May 26 12:14:04 2018 +0900
@@ -216,7 +216,7 @@
# check directly in path and don't leave checkisexec behind
checkdir = path
checkisexec = None
- fh, fn = tempfile.mkstemp(dir=checkdir, prefix='hg-checkexec-')
+ fh, fn = pycompat.mkstemp(dir=checkdir, prefix='hg-checkexec-')
try:
os.close(fh)
m = os.stat(fn).st_mode
--- a/mercurial/pycompat.py Thu May 03 18:39:58 2018 +0900
+++ b/mercurial/pycompat.py Sat May 26 12:14:04 2018 +0900
@@ -15,6 +15,7 @@
import os
import shlex
import sys
+import tempfile
ispy3 = (sys.version_info[0] >= 3)
ispypy = (r'__pypy__' in sys.builtin_module_names)
@@ -384,3 +385,7 @@
def gnugetoptb(args, shortlist, namelist):
return _getoptbwrapper(getopt.gnu_getopt, args, shortlist, namelist)
+
+# 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/server.py Thu May 03 18:39:58 2018 +0900
+++ b/mercurial/server.py Sat May 26 12:14:04 2018 +0900
@@ -8,7 +8,6 @@
from __future__ import absolute_import
import os
-import tempfile
from .i18n import _
@@ -72,7 +71,7 @@
if opts['daemon'] and not opts['daemon_postexec']:
# Signal child process startup with file removal
- lockfd, lockpath = tempfile.mkstemp(prefix='hg-service-')
+ lockfd, lockpath = pycompat.mkstemp(prefix='hg-service-')
os.close(lockfd)
try:
if not runargs:
--- a/mercurial/statprof.py Thu May 03 18:39:58 2018 +0900
+++ b/mercurial/statprof.py Sat May 26 12:14:04 2018 +0900
@@ -112,7 +112,6 @@
import os
import signal
import sys
-import tempfile
import threading
import time
@@ -691,7 +690,7 @@
file=fp)
return
- fd, path = tempfile.mkstemp()
+ fd, path = pycompat.mkstemp()
file = open(path, "w+")
--- a/mercurial/streamclone.py Thu May 03 18:39:58 2018 +0900
+++ b/mercurial/streamclone.py Sat May 26 12:14:04 2018 +0900
@@ -10,7 +10,6 @@
import contextlib
import os
import struct
-import tempfile
import warnings
from .i18n import _
@@ -19,6 +18,7 @@
cacheutil,
error,
phases,
+ pycompat,
store,
util,
)
@@ -469,7 +469,7 @@
files = []
try:
def copy(src):
- fd, dst = tempfile.mkstemp()
+ fd, dst = pycompat.mkstemp()
os.close(fd)
files.append(dst)
util.copyfiles(src, dst, hardlink=True)
--- a/mercurial/ui.py Thu May 03 18:39:58 2018 +0900
+++ b/mercurial/ui.py Sat May 26 12:14:04 2018 +0900
@@ -18,7 +18,6 @@
import socket
import subprocess
import sys
-import tempfile
import traceback
from .i18n import _
@@ -1446,7 +1445,7 @@
rdir = None
if self.configbool('experimental', 'editortmpinhg'):
rdir = repopath
- (fd, name) = tempfile.mkstemp(prefix='hg-' + extra['prefix'] + '-',
+ (fd, name) = pycompat.mkstemp(prefix='hg-' + extra['prefix'] + '-',
suffix=suffix,
dir=rdir)
try:
--- a/mercurial/util.py Thu May 03 18:39:58 2018 +0900
+++ b/mercurial/util.py Sat May 26 12:14:04 2018 +0900
@@ -31,7 +31,6 @@
import socket
import stat
import sys
-import tempfile
import time
import traceback
import warnings
@@ -1893,7 +1892,7 @@
# work around issue2543 (or testfile may get lost on Samba shares)
f1, f2, fp = None, None, None
try:
- fd, f1 = tempfile.mkstemp(prefix='.%s-' % os.path.basename(testfile),
+ fd, f1 = pycompat.mkstemp(prefix='.%s-' % os.path.basename(testfile),
suffix='1~', dir=os.path.dirname(testfile))
os.close(fd)
f2 = '%s2~' % f1[:-2]
@@ -1939,7 +1938,7 @@
Returns the name of the temporary file.
"""
d, fn = os.path.split(name)
- fd, temp = tempfile.mkstemp(prefix='.%s-' % fn, suffix='~', dir=d)
+ fd, temp = pycompat.mkstemp(prefix='.%s-' % fn, suffix='~', dir=d)
os.close(fd)
# Temporary files are created with mode 0600, which is usually not
# what we want. If the original file already exists, just copy
--- a/mercurial/utils/procutil.py Thu May 03 18:39:58 2018 +0900
+++ b/mercurial/utils/procutil.py Sat May 26 12:14:04 2018 +0900
@@ -16,7 +16,6 @@
import signal
import subprocess
import sys
-import tempfile
import time
from ..i18n import _
@@ -164,11 +163,11 @@
the temporary files generated.'''
inname, outname = None, None
try:
- infd, inname = tempfile.mkstemp(prefix='hg-filter-in-')
+ infd, inname = pycompat.mkstemp(prefix='hg-filter-in-')
fp = os.fdopen(infd, r'wb')
fp.write(s)
fp.close()
- outfd, outname = tempfile.mkstemp(prefix='hg-filter-out-')
+ outfd, outname = pycompat.mkstemp(prefix='hg-filter-out-')
os.close(outfd)
cmd = cmd.replace('INFILE', inname)
cmd = cmd.replace('OUTFILE', outname)
--- a/mercurial/vfs.py Thu May 03 18:39:58 2018 +0900
+++ b/mercurial/vfs.py Sat May 26 12:14:04 2018 +0900
@@ -11,7 +11,6 @@
import os
import shutil
import stat
-import tempfile
import threading
from .i18n import _
@@ -171,7 +170,7 @@
return os.mkdir(self.join(path))
def mkstemp(self, suffix='', prefix='tmp', dir=None):
- fd, name = tempfile.mkstemp(suffix=suffix, prefix=prefix,
+ fd, name = pycompat.mkstemp(suffix=suffix, prefix=prefix,
dir=self.join(dir))
dname, fname = util.split(name)
if dir:
--- a/mercurial/wireprotov1server.py Thu May 03 18:39:58 2018 +0900
+++ b/mercurial/wireprotov1server.py Sat May 26 12:14:04 2018 +0900
@@ -8,7 +8,6 @@
from __future__ import absolute_import
import os
-import tempfile
from .i18n import _
from .node import (
@@ -568,7 +567,7 @@
fp.close()
if tempname:
os.unlink(tempname)
- fd, tempname = tempfile.mkstemp(prefix='hg-unbundle-')
+ fd, tempname = pycompat.mkstemp(prefix='hg-unbundle-')
repo.ui.debug('redirecting incoming bundle to %s\n' %
tempname)
fp = os.fdopen(fd, pycompat.sysstr('wb+'))