[patch 0e2846b2482c in main] url: use open and not url.open for local files (issue3624)

Adrian Buehlmann adrian at cadifra.com
Thu Nov 1 02:43:47 CDT 2012


# 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)

diff --git a/contrib/synthrepo.py b/contrib/synthrepo.py
--- a/contrib/synthrepo.py
+++ b/contrib/synthrepo.py
@@ -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 --git a/hgext/mq.py b/hgext/mq.py
--- a/hgext/mq.py
+++ b/hgext/mq.py
@@ -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 --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -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 --git a/mercurial/hg.py b/mercurial/hg.py
--- 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))
+    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