Mercurial > hg-git
changeset 780:db10082cf043
exchange: wrap pull if localrepository.pull isn't available
Mercurial rev 73b5b8312ce6 removed localrepository.pull. We don't do it the
other way round (wrap pull if exchange.pull 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:53:42 -0700 |
parents | a951b04338e1 |
children | 8bfb1d72b49c |
files | hggit/__init__.py hggit/hgrepo.py |
diffstat | 2 files changed, 30 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/hggit/__init__.py Mon Oct 13 16:26:31 2014 -0700 +++ b/hggit/__init__.py Mon Oct 13 18:53:42 2014 -0700 @@ -27,6 +27,7 @@ from mercurial import demandimport from mercurial import dirstate from mercurial import discovery +from mercurial import exchange from mercurial import extensions from mercurial import help from mercurial import hg @@ -44,7 +45,7 @@ 'collections', ]) -import gitrepo, hgrepo +import gitrepo, hgrepo, util from git_handler import GitHandler import verify @@ -210,6 +211,25 @@ return newpeer extensions.wrapfunction(hg, 'peer', peer) +@util.transform_notgit +def exchangepull(orig, repo, remote, heads=None, force=False, bookmarks=()): + if isinstance(remote, gitrepo.gitrepo): + pullop = exchange.pulloperation(repo, remote, heads, force, + bookmarks=bookmarks) + lock = repo.lock() + try: + pullop.cgresult = repo.githandler.fetch(remote.path, heads) + pullop.closetransaction() + return pullop + finally: + pullop.releasetransaction() + lock.release() + else: + return orig(repo, remote, heads, force, bookmarks=bookmarks) +if not hgutil.safehasattr(localrepo.localrepository, 'pull'): + # Mercurial >= 3.2 + extensions.wrapfunction(exchange, 'pull', exchangepull) + def revset_fromgit(repo, subset, x): '''``fromgit()`` Select changesets that originate from Git.
--- a/hggit/hgrepo.py Mon Oct 13 16:26:31 2014 -0700 +++ b/hggit/hgrepo.py Mon Oct 13 18:53:42 2014 -0700 @@ -1,5 +1,6 @@ import os +from mercurial import localrepo from mercurial.node import bin from mercurial import util as hgutil @@ -9,12 +10,14 @@ def generate_repo_subclass(baseclass): class hgrepo(baseclass): - @util.transform_notgit - def pull(self, remote, heads=None, force=False): # Mercurial < 3.2 - if isinstance(remote, gitrepo): - return self.githandler.fetch(remote.path, heads) - else: #pragma: no cover - return super(hgrepo, self).pull(remote, heads, force) + if hgutil.safehasattr(localrepo.localrepository, 'pull'): + # Mercurial < 3.2 + @util.transform_notgit + def pull(self, remote, heads=None, force=False): + if isinstance(remote, gitrepo): + return self.githandler.fetch(remote.path, heads) + 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