mirror of
https://github.com/facebook/sapling.git
synced 2024-10-10 16:57:49 +03:00
hgrepo: move _transform_notgit into util
This decorator will be used in other contexts in upcoming patches.
This commit is contained in:
parent
58d56b6660
commit
16e7862fe1
@ -5,36 +5,26 @@ from mercurial import util as hgutil
|
||||
|
||||
from git_handler import GitHandler
|
||||
from gitrepo import gitrepo
|
||||
|
||||
from dulwich import errors
|
||||
|
||||
def _transform_notgit(f):
|
||||
def inner(*args, **kwargs):
|
||||
try:
|
||||
return f(*args, **kwargs)
|
||||
except errors.NotGitRepository:
|
||||
raise util.Abort('not a git repository')
|
||||
return inner
|
||||
|
||||
import util
|
||||
|
||||
def generate_repo_subclass(baseclass):
|
||||
class hgrepo(baseclass):
|
||||
@_transform_notgit
|
||||
def pull(self, remote, heads=None, force=False):
|
||||
@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)
|
||||
|
||||
# TODO figure out something useful to do with the newbranch param
|
||||
@_transform_notgit
|
||||
@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)
|
||||
|
||||
@_transform_notgit
|
||||
@util.transform_notgit
|
||||
def findoutgoing(self, remote, base=None, heads=None, force=False):
|
||||
if isinstance(remote, gitrepo):
|
||||
base, heads = self.githandler.get_refs(remote.path)
|
||||
|
@ -1,4 +1,6 @@
|
||||
"""Compatability functions for old Mercurial versions."""
|
||||
"""Compatibility functions for old Mercurial versions and other utility
|
||||
functions."""
|
||||
from dulwich import errors
|
||||
try:
|
||||
from collections import OrderedDict
|
||||
except ImportError:
|
||||
@ -31,3 +33,12 @@ def parse_hgsubstate(lines):
|
||||
def serialize_hgsubstate(data):
|
||||
"""Produces a string from OrderedDict hgsubstate content"""
|
||||
return ''.join(['%s %s\n' % (data[n], n) for n in sorted(data)])
|
||||
|
||||
def transform_notgit(f):
|
||||
'''use as a decorator around functions and methods that call into dulwich'''
|
||||
def inner(*args, **kwargs):
|
||||
try:
|
||||
return f(*args, **kwargs)
|
||||
except errors.NotGitRepository:
|
||||
raise util.Abort('not a git repository')
|
||||
return inner
|
||||
|
Loading…
Reference in New Issue
Block a user