diff --git a/hggit/hgrepo.py b/hggit/hgrepo.py index 503d0b871a7c0ecae739f97c461900816778bb0b_aGdnaXQvaGdyZXBvLnB5..a951b04338e161560b824a5fdf45cd6458f07ae5_aGdnaXQvaGdyZXBvLnB5 100644 --- a/hggit/hgrepo.py +++ b/hggit/hgrepo.py @@ -5,17 +5,7 @@ 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): @@ -19,11 +9,11 @@ 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 @@ -24,13 +14,13 @@ 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) @@ -31,10 +21,10 @@ 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) diff --git a/hggit/util.py b/hggit/util.py index 503d0b871a7c0ecae739f97c461900816778bb0b_aGdnaXQvdXRpbC5weQ==..a951b04338e161560b824a5fdf45cd6458f07ae5_aGdnaXQvdXRpbC5weQ== 100644 --- a/hggit/util.py +++ b/hggit/util.py @@ -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 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