Mercurial > hgsubversion
changeset 1246:2179747e7fea
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.
author | Siddharth Agarwal <sid0@fb.com> |
---|---|
date | Mon, 13 Oct 2014 23:55:27 -0700 |
parents | 260212f056b7 |
children | 3a4d74823187 |
files | hgsubversion/__init__.py hgsubversion/svnrepo.py hgsubversion/wrappers.py |
diffstat | 3 files changed, 34 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- 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 = (
--- 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):
--- 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"""