changeset 930:5bacb9c63e3e

Fix more peer breakage with old hg versions
author Patrick Mezard <patrick@mezard.eu>
date Mon, 10 Sep 2012 22:42:49 +0200
parents 8417be758047
children e1dbd9646d6a
files hgsubversion/wrappers.py tests/test_fetch_mappings.py tests/test_rebuildmeta.py tests/test_tags.py tests/test_updatemeta.py tests/test_util.py
diffstat 6 files changed, 26 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/hgsubversion/wrappers.py
+++ b/hgsubversion/wrappers.py
@@ -72,6 +72,12 @@ def getpeer(ui, opts, source):
         return peer(ui, opts, source)
     return hg.repository(ui, source)
 
+def getlocalpeer(ui, opts, source):
+    peer = getpeer(ui, opts, source)
+    repo = getattr(peer, 'local', lambda: peer)()
+    if isinstance(repo, bool):
+        repo = peer
+    return repo
 
 def getcaps(other):
     return (getattr(other, 'caps', None) or
@@ -262,8 +268,7 @@ def push(repo, dest, force, revs):
                 # Reload the repo after the rebase. Do not reuse
                 # contexts across this.
                 newtip = newtipctx.node()
-                repo = getpeer(ui, {}, meta.path)
-                repo = getattr(repo, 'local', lambda: repo)()
+                repo = getlocalpeer(ui, {}, meta.path)
                 newtipctx = repo[newtip]
                 # Rewrite the node ids in outgoing to their rebased versions.
                 rebasemap = dict()
@@ -554,7 +559,11 @@ def clone(orig, ui, source, dest=None, *
 
     if dstrepo.local() and srcrepo.capable('subversion'):
         dst = dstrepo.local()
-        fd = dst.opener("hgrc", "a", text=True)
+        if isinstance(dst, bool):
+            # Apparently <= hg@1.9
+            fd = dstrepo.opener("hgrc", "a", text=True)
+        else:
+            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,8 +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)()
+        src = test_util.getlocalpeer(src)
+        dest = test_util.getlocalpeer(dest)
         svncommands.rebuildmeta(ui, dest,
                                 args=[test_util.fileurl(repo_path)])
 
--- a/tests/test_rebuildmeta.py
+++ b/tests/test_rebuildmeta.py
@@ -34,8 +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)()
+    src = test_util.getlocalpeer(src)
+    dest = test_util.getlocalpeer(dest)
 
     # insert a wrapper that prevents calling changectx.children()
     def failfn(orig, ctx):
@@ -61,8 +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)()
+    srcrepo = test_util.getlocalpeer(src)
+    dest = test_util.getlocalpeer(dest)
 
     # insert a wrapper that prevents calling changectx.children()
     extensions.wrapfunction(context.changectx, 'children', failfn)
--- a/tests/test_tags.py
+++ b/tests/test_tags.py
@@ -112,7 +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)()
+        dest = test_util.getlocalpeer(dest)
         svncommands.rebuildmeta(repo.ui,
                                dest,
                                args=[test_util.fileurl(repo_path), ])
--- a/tests/test_updatemeta.py
+++ b/tests/test_updatemeta.py
@@ -26,8 +26,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)()
+    src = test_util.getlocalpeer(src)
+    dest = test_util.getlocalpeer(dest)
 
     # insert a wrapper that prevents calling changectx.children()
     def failfn(orig, ctx):
--- a/tests/test_util.py
+++ b/tests/test_util.py
@@ -104,6 +104,11 @@ subdir = {'truncatedhistory.svndump': '/
 FIXTURES = os.path.join(os.path.abspath(os.path.dirname(__file__)),
                         'fixtures')
 
+def getlocalpeer(repo):
+    localrepo = getattr(repo, 'local', lambda: repo)()
+    if isinstance(localrepo, bool):
+        localrepo = repo
+    return localrepo
 
 def _makeskip(name, message):
     if SkipTest: