[PATCH V2] url: use open and not url.open for local files (issue3624)

Siddharth Agarwal sid0 at fb.com
Tue Oct 30 20:25:37 CDT 2012


# HG changeset patch
# User Siddharth Agarwal <sid0 at fb.com>
# Date 1350534608 25200
# Node ID 7e319668f2a9a032b0211652fd86e4b480396a33
# Parent  917a37b76845811aaea1dc9b1ad0a8110e8b7439
url: use open and not url.open for local files (issue3624)

diff -r 917a37b76845 -r 7e319668f2a9 contrib/synthrepo.py
--- a/contrib/synthrepo.py	Tue Oct 23 09:28:42 2012 +0200
+++ b/contrib/synthrepo.py	Wed Oct 17 21:30:08 2012 -0700
@@ -36,7 +36,7 @@
 '''
 
 import bisect, collections, json, os, random, time
-from mercurial import cmdutil, context, patch, scmutil, url, util
+from mercurial import cmdutil, context, patch, scmutil, url, util, hg
 from mercurial.i18n import _
 from mercurial.node import nullrev, nullid
 
@@ -224,7 +224,7 @@
     path to an alternate dictionary to use.
     '''
     try:
-        fp = url.open(ui, descpath)
+        fp = hg.openpath(ui, descpath)
     except Exception, err:
         raise util.Abort('%s: %s' % (descpath, err[0].strerror))
     desc = json.load(fp)
diff -r 917a37b76845 -r 7e319668f2a9 hgext/mq.py
--- a/hgext/mq.py	Tue Oct 23 09:28:42 2012 +0200
+++ b/hgext/mq.py	Wed Oct 17 21:30:08 2012 -0700
@@ -63,7 +63,7 @@
 from mercurial.node import bin, hex, short, nullid, nullrev
 from mercurial.lock import release
 from mercurial import commands, cmdutil, hg, scmutil, util, revset
-from mercurial import repair, extensions, url, error, phases, bookmarks
+from mercurial import repair, extensions, error, phases, bookmarks
 from mercurial import patch as patchmod
 import os, re, errno, shutil
 
@@ -2004,7 +2004,7 @@
                     if filename == '-':
                         text = self.ui.fin.read()
                     else:
-                        fp = url.open(self.ui, filename)
+                        fp = hg.openpath(self.ui, filename)
                         text = fp.read()
                         fp.close()
                 except (OSError, IOError):
diff -r 917a37b76845 -r 7e319668f2a9 mercurial/commands.py
--- a/mercurial/commands.py	Tue Oct 23 09:28:42 2012 +0200
+++ b/mercurial/commands.py	Wed Oct 17 21:30:08 2012 -0700
@@ -10,7 +10,7 @@
 from i18n import _, gettext
 import os, re, difflib, time, tempfile, errno
 import hg, scmutil, util, revlog, extensions, copies, error, bookmarks
-import patch, help, url, encoding, templatekw, discovery
+import patch, help, encoding, templatekw, discovery
 import archival, changegroup, cmdutil, hbisect
 import sshserver, hgweb, hgweb.server, commandserver
 import merge as mergemod
@@ -1590,7 +1590,7 @@
 @command('debugbundle', [('a', 'all', None, _('show all details'))], _('FILE'))
 def debugbundle(ui, bundlepath, all=None, **opts):
     """lists the contents of a bundle"""
-    f = url.open(ui, bundlepath)
+    f = hg.openpath(ui, bundlepath)
     try:
         gen = changegroup.readbundle(f, bundlepath)
         if all:
@@ -3856,7 +3856,7 @@
                 else:
                     patchurl = os.path.join(base, patchurl)
                     ui.status(_('applying %s\n') % patchurl)
-                    patchfile = url.open(ui, patchurl)
+                    patchfile = hg.openpath(ui, patchurl)
 
                 haspatch = False
                 for hunk in patch.split(patchfile):
@@ -5804,7 +5804,7 @@
     wc = repo['.']
     try:
         for fname in fnames:
-            f = url.open(ui, fname)
+            f = hg.openpath(ui, fname)
             gen = changegroup.readbundle(f, fname)
             modheads = repo.addchangegroup(gen, 'unbundle', 'bundle:' + fname)
     finally:
diff -r 917a37b76845 -r 7e319668f2a9 mercurial/hg.py
--- a/mercurial/hg.py	Tue Oct 23 09:28:42 2012 +0200
+++ b/mercurial/hg.py	Wed Oct 17 21:30:08 2012 -0700
@@ -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, *args, **kwargs):
+    '''open path with open if local, url.open if remote'''
+    if islocal(path):
+        return open(util.urllocalpath(path))
+    else:
+        return url.open(ui, path, *args, **kwargs)
+
 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