# HG changeset patch # User Siddharth Agarwal # Date 1413269727 25200 # Node ID 2179747e7feaa6fa310ef2d7204b5ad6ac8c0267 # Parent 260212f056b738d32dcda92bda4554d0b7efb484 push: wrap exchange.push when 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. diff --git a/hgsubversion/__init__.py b/hgsubversion/__init__.py --- a/hgsubversion/__init__.py +++ b/hgsubversion/__init__.py @@ -20,9 +20,16 @@ import sys import traceback from mercurial import commands +try: + from mercurial import exchange + exchange.push # existed in first iteration of this file +except ImportError: + # We only *use* the exchange module in hg 3.2+, so this is safe + pass from mercurial import extensions from mercurial import help from mercurial import hg +from mercurial import localrepo from mercurial import util as hgutil from mercurial import demandimport demandimport.ignore.extend([ @@ -136,6 +143,10 @@ def extsetup(ui): except: pass + if not hgutil.safehasattr(localrepo.localrepository, 'push'): + # Mercurial >= 3.2 + extensions.wrapfunction(exchange, 'push', wrappers.exchangepush) + helpdir = os.path.join(os.path.dirname(__file__), 'help') entries = ( diff --git a/hgsubversion/svnrepo.py b/hgsubversion/svnrepo.py --- a/hgsubversion/svnrepo.py +++ b/hgsubversion/svnrepo.py @@ -17,6 +17,7 @@ subclass: pull() is called on the instan import errno from mercurial import error +from mercurial import localrepo from mercurial import util as hgutil try: @@ -95,10 +96,12 @@ def generate_repo_class(ui, repo): self.pushkey('phases', self[hash].hex(), str(phases.draft), str(phases.public)) return hash - # TODO use newbranch to allow branch creation in Subversion? - @remotesvn - def push(self, remote, force=False, revs=None, newbranch=None): - return wrappers.push(self, remote, force, revs) + if hgutil.safehasattr(localrepo.localrepository, 'push'): + # Mercurial < 3.2 + # TODO use newbranch to allow branch creation in Subversion? + @remotesvn + def push(self, remote, force=False, revs=None, newbranch=None): + return wrappers.push(self, remote, force, revs) @remotesvn def pull(self, remote, heads=[], force=False): diff --git a/hgsubversion/wrappers.py b/hgsubversion/wrappers.py --- a/hgsubversion/wrappers.py +++ b/hgsubversion/wrappers.py @@ -2,6 +2,12 @@ from hgext import rebase as hgrebase from mercurial import cmdutil from mercurial import discovery +try: + from mercurial import exchange + exchange.push # existed in first iteration of this file +except ImportError: + # We only *use* the exchange module in hg 3.2+, so this is safe + pass from mercurial import patch from mercurial import hg from mercurial import util as hgutil @@ -362,6 +368,16 @@ def push(repo, dest, force, revs): util.swap_out_encoding(old_encoding) return 1 # so we get a sane exit status, see hg's commands.push +def exchangepush(orig, repo, remote, force=False, revs=None, newbranch=False, + bookmarks=()): + capable = getattr(remote, 'capable', lambda x: False) + if capable('subversion'): + pushop = exchange.pushoperation(repo, remote, force, revs, newbranch, + bookmarks=bookmarks) + pushop.cgresult = push(repo, remote, force, revs) + return pushop + else: + return orig(repo, remote, force, revs, newbranch, bookmarks=bookmarks) def pull(repo, source, heads=[], force=False): """pull new revisions from Subversion"""