changeset 917:6918f60d0e28

Merge hg 2.3 fixes from bos.
author Augie Fackler <raf@durin42.com>
date Sat, 21 Jul 2012 15:31:34 -0500
parents 9fff2b8217b6 (current diff) 7e9d805a0e1f (diff)
children 761a87134501
files hgsubversion/wrappers.py tests/test_util.py
diffstat 6 files changed, 42 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/hgsubversion/svnrepo.py
+++ b/hgsubversion/svnrepo.py
@@ -18,8 +18,13 @@ import errno
 
 from mercurial import error
 from mercurial import util as hgutil
-from mercurial import httprepo
-import mercurial.repo
+
+try:
+    from mercurial.peer import peerrepository
+    from mercurial import httppeer
+except ImportError:
+    from mercurial.repo import repository as peerrepository
+    from mercurial import httprepo as httppeer
 
 try:
     from mercurial import phases
@@ -107,7 +112,7 @@ def generate_repo_class(ui, repo):
 
     repo.__class__ = svnlocalrepo
 
-class svnremoterepo(mercurial.repo.repository):
+class svnremoterepo(peerrepository):
     """ the dumb wrapper for actual Subversion repositories """
 
     def __init__(self, ui, path=None):
@@ -127,6 +132,9 @@ class svnremoterepo(mercurial.repo.repos
         else:
             self.password_stores = None
 
+    def _capabilities(self):
+        return self.capabilities
+
     @propertycache
     def svnauth(self):
         # DO NOT default the user to hg's getuser(). If you provide
@@ -177,7 +185,7 @@ def instance(ui, url, create):
     if url.startswith('http://') or url.startswith('https://'):
         try:
             # may yield a bogus 'real URL...' message
-            return httprepo.instance(ui, url, create)
+            return httppeer.instance(ui, url, create)
         except error.RepoError:
             ui.traceback()
             ui.note('(falling back to Subversion support)\n')
--- a/hgsubversion/wrappers.py
+++ b/hgsubversion/wrappers.py
@@ -65,13 +65,26 @@ def parents(orig, ui, repo, *args, **opt
     return 0
 
 
+def getpeer(ui, opts, source):
+    # Since 2.3 (1ac628cd7113)
+    peer = getattr(hg, 'peer', None)
+    if peer:
+        return peer(ui, opts, source)
+    return hg.repository(ui, source)
+
+
+def getcaps(other):
+    return (getattr(other, 'caps', None) or
+            getattr(other, 'capabilities', None) or set())
+
+
 def incoming(orig, ui, repo, origsource='default', **opts):
     """show incoming revisions from Subversion
     """
 
     source, revs, checkout = util.parseurl(ui.expandpath(origsource))
-    other = hg.repository(ui, source)
-    if 'subversion' not in other.capabilities:
+    other = getpeer(ui, opts, source)
+    if 'subversion' not in getcaps(other):
         return orig(ui, repo, origsource, **opts)
 
     svn = other.svn
@@ -235,7 +248,8 @@ def push(repo, dest, force, revs):
                    svnsourcerev=needs_transplant)
             # Reload the repo after the rebase. Do not reuse contexts across this.
             newtip = newtipctx.node()
-            repo = hg.repository(ui, meta.path)
+            repo = getpeer(ui, {}, meta.path)
+            repo = getattr(repo, 'local', lambda: repo)()
             newtipctx = repo[newtip]
             # Rewrite the node ids in outgoing to their rebased versions.
             rebasemap = dict()
@@ -490,7 +504,7 @@ def clone(orig, ui, source, dest=None, *
         if isinstance(origsource, str):
             source, branch, checkout = util.parseurl(ui.expandpath(origsource),
                                          opts.get('branch'))
-            srcrepo = hg.repository(ui, source)
+            srcrepo = getpeer(ui, opts, source)
         else:
             srcrepo = origsource
 
@@ -522,7 +536,8 @@ def clone(orig, ui, source, dest=None, *
     srcrepo = data.get('srcrepo')
 
     if dstrepo.local() and srcrepo.capable('subversion'):
-        fd = dstrepo.opener("hgrc", "a", text=True)
+        dst = dstrepo.local()
+        fd = dst.opener("hgrc", "a", text=True)
         for section in set(s for s, v in optionmap.itervalues()):
             config = dict(ui.configitems(section))
             for name in dontretain[section]:
--- a/tests/test_fetch_mappings.py
+++ b/tests/test_fetch_mappings.py
@@ -245,6 +245,8 @@ class MapTests(test_util.TestBase):
         ui = self.ui(stupid)
         src, dest = test_util.hgclone(ui, self.wc_path, self.wc_path + '_clone',
                                       update=False)
+        src = getattr(src, 'local', lambda: src)()
+        dest = getattr(dest, 'local', lambda: dest)()
         svncommands.rebuildmeta(ui, dest,
                                 args=[test_util.fileurl(repo_path)])
 
--- a/tests/test_rebuildmeta.py
+++ b/tests/test_rebuildmeta.py
@@ -34,6 +34,8 @@ def _do_case(self, name, stupid, single)
     wc2_path = self.wc_path + '_clone'
     u = ui.ui()
     src, dest = test_util.hgclone(u, self.wc_path, wc2_path, update=False)
+    src = getattr(src, 'local', lambda: src)()
+    dest = getattr(dest, 'local', lambda: dest)()
 
     # insert a wrapper that prevents calling changectx.children()
     def failfn(orig, ctx):
@@ -59,6 +61,8 @@ def _do_case(self, name, stupid, single)
                                   wc3_path,
                                   update=False,
                                   rev=[0])
+    srcrepo = getattr(src, 'local', lambda: src)()
+    dest = getattr(dest, 'local', lambda: dest)()
 
     # insert a wrapper that prevents calling changectx.children()
     extensions.wrapfunction(context.changectx, 'children', failfn)
@@ -83,7 +87,7 @@ def _do_case(self, name, stupid, single)
         # remove the wrapper
         context.changectx.children = origchildren
 
-    self._run_assertions(name, stupid, single, src, dest, u)
+    self._run_assertions(name, stupid, single, srcrepo, dest, u)
 
 
 def _run_assertions(self, name, stupid, single, src, dest, u):
--- a/tests/test_tags.py
+++ b/tests/test_tags.py
@@ -112,6 +112,7 @@ rename a tag
             "You should check that before assuming issues with this test.\n")
         wc2_path = self.wc_path + '2'
         src, dest = test_util.hgclone(repo.ui, self.wc_path, wc2_path, update=False)
+        dest = getattr(dest, 'local', lambda: dest)()
         svncommands.rebuildmeta(repo.ui,
                                dest,
                                args=[test_util.fileurl(repo_path), ])
--- a/tests/test_util.py
+++ b/tests/test_util.py
@@ -161,11 +161,8 @@ def testui(stupid=False, layout='auto', 
     return u
 
 def dispatch(cmd):
-    try:
-        req = dispatchmod.request(cmd)
-        dispatchmod.dispatch(req)
-    except AttributeError, e:
-        dispatchmod.dispatch(cmd)
+    cmd = getattr(dispatchmod, 'request', lambda x: x)(cmd)
+    dispatchmod.dispatch(cmd)
 
 def rmtree(path):
     # Read-only files cannot be removed under Windows