[patch 0e2846b2482c in main] url: use open and not url.open for local files (issue3624)
Adrian Buehlmann
adrian at cadifra.com
Thu Nov 1 08:07:05 UTC 2012
On 2012-11-01 08:43, Adrian Buehlmann wrote:
> # HG changeset patch
> # User Siddharth Agarwal <sid0 at fb.com>
> # Date 1350534608 25200
> # Branch stable
> # Node ID 0e2846b2482ce9735858bd28ddc7400ae213771a
> # Parent d8905e2c1301841da1d76ccf396ec6be3ee4ea61
> url: use open and not url.open for local files (issue3624)
[..]
> --- a/mercurial/hg.py
> +++ b/mercurial/hg.py
> @@ -10,7 +10,7 @@
> from lock import release
> from node import hex, nullid
> import localrepo, bundlerepo, httppeer, sshpeer, statichttprepo, bookmarks
> -import lock, util, extensions, error, node, scmutil, phases
> +import lock, util, extensions, error, node, scmutil, phases, url
> import cmdutil, discovery
> import merge as mergemod
> import verify as verifymod
> @@ -89,6 +89,13 @@
> return False
> return repo.local()
>
> +def openpath(ui, path):
> + '''open path with open if local, url.open if remote'''
> + if islocal(path):
> + return open(util.urllocalpath(path))
I think this should probably open the file in binary mode, as this is used
for bundles, which I think are opened using rb elsewhere already.
Consider (on Windows 7):
$ python
Python 2.7.3 (default, Apr 10 2012, 23:24:47) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> f = open('bla.txt')
>>> x = f.read()
>>> x
'foo \nxxx\n'
>>> f.close()
>>> f = open('bla.txt', 'rb')
>>> x = f.read()
>>> x
'foo \r\nxxx\r\n'
>>>
While we're at it, we could also use util.posixfile [1]. But I don't know if this counts
as a "fix" and would be acceptable for 2.4 (re: "freeze").
Perhaps:
diff --git a/mercurial/hg.py b/mercurial/hg.py
--- a/mercurial/hg.py
+++ b/mercurial/hg.py
@@ -92,7 +92,7 @@
def openpath(ui, path):
'''open path with open if local, url.open if remote'''
if islocal(path):
- return open(util.urllocalpath(path))
+ return util.posixfile(util.urllocalpath(path), "rb")
else:
return url.open(ui, path)
[1] http://mercurial.selenic.com/wiki/UnlinkingFilesOnWindows
> + else:
> + return url.open(ui, path)
> +
> def _peerorrepo(ui, path, create=False):
> """return a repository object for the specified path"""
> obj = _peerlookup(path).instance(ui, path, create)
More information about the Mercurial-devel
mailing list