changeset 782:8bfb1d72b49c

exchange: wrap push if localrepository.push isn't available Mercurial rev 4d52e6eb98ea removed localrepository.push. We don't do it the other way round (wrap push if exchange.push is available) because that's been available with a different signature since Mercurial 3.0.
author Siddharth Agarwal <sid0@fb.com>
date Mon, 13 Oct 2014 18:55:18 -0700
parents db10082cf043
children e5450a81676e
files hggit/__init__.py hggit/hgrepo.py
diffstat 2 files changed, 25 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/hggit/__init__.py
+++ b/hggit/__init__.py
@@ -230,6 +230,21 @@
     # Mercurial >= 3.2
     extensions.wrapfunction(exchange, 'pull', exchangepull)
 
+# TODO figure out something useful to do with the newbranch param
+@util.transform_notgit
+def exchangepush(orig, repo, remote, force=False, revs=None, newbranch=False,
+                 bookmarks=()):
+    if isinstance(remote, gitrepo.gitrepo):
+        pushop = exchange.pushoperation(repo, remote, force, revs, newbranch,
+                                        bookmarks)
+        pushop.cgresult = repo.githandler.push(remote.path, revs, force)
+        return pushop
+    else:
+        return orig(repo, remote, force, revs, newbranch, bookmarks=bookmarks)
+if not hgutil.safehasattr(localrepo.localrepository, 'push'):
+    # Mercurial >= 3.2
+    extensions.wrapfunction(exchange, 'push', exchangepush)
+
 def revset_fromgit(repo, subset, x):
     '''``fromgit()``
     Select changesets that originate from Git.
--- a/hggit/hgrepo.py
+++ b/hggit/hgrepo.py
@@ -19,13 +19,16 @@
                 else: #pragma: no cover
                     return super(hgrepo, self).pull(remote, heads, force)
 
-        # TODO figure out something useful to do with the newbranch param
-        @util.transform_notgit
-        def push(self, remote, force=False, revs=None, newbranch=False):
-            if isinstance(remote, gitrepo):
-                return self.githandler.push(remote.path, revs, force)
-            else: #pragma: no cover
-                return super(hgrepo, self).push(remote, force, revs, newbranch)
+        if hgutil.safehasattr(localrepo.localrepository, 'push'):
+            # Mercurial < 3.2
+            # TODO figure out something useful to do with the newbranch param
+            @util.transform_notgit
+            def push(self, remote, force=False, revs=None, newbranch=False):
+                if isinstance(remote, gitrepo):
+                    return self.githandler.push(remote.path, revs, force)
+                else: #pragma: no cover
+                    return super(hgrepo, self).push(remote, force, revs,
+                                                    newbranch)
 
         @util.transform_notgit
         def findoutgoing(self, remote, base=None, heads=None, force=False):