diff -r 17941fc53ae9 -r 593f6359681d mercurial/util.py --- a/mercurial/util.py Wed Jan 16 16:49:15 2019 -0800 +++ b/mercurial/util.py Thu Jan 10 14:57:01 2019 +0100 @@ -2045,7 +2045,7 @@ function if need.''' return path.split(pycompat.ossep) -def mktempcopy(name, emptyok=False, createmode=None): +def mktempcopy(name, emptyok=False, createmode=None, enforcewritable=False): """Create a temporary file with the same contents from name The permission bits are copied from the original file. @@ -2061,7 +2061,8 @@ # Temporary files are created with mode 0600, which is usually not # what we want. If the original file already exists, just copy # its mode. Otherwise, manually obey umask. - copymode(name, temp, createmode) + copymode(name, temp, createmode, enforcewritable) + if emptyok: return temp try: @@ -2204,7 +2205,9 @@ def __init__(self, name, mode='w+b', createmode=None, checkambig=False): self.__name = name # permanent name self._tempname = mktempcopy(name, emptyok=('w' in mode), - createmode=createmode) + createmode=createmode, + enforcewritable=('w' in mode)) + self._fp = posixfile(self._tempname, mode) self._checkambig = checkambig