changeset 780:a951b04338e1

hgrepo: move _transform_notgit into util This decorator will be used in other contexts in upcoming patches.
author Siddharth Agarwal <sid0@fb.com>
date Mon, 13 Oct 2014 16:26:31 -0700
parents 503d0b871a7c
children db10082cf043
files hggit/hgrepo.py hggit/util.py
diffstat 2 files changed, 17 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/hggit/hgrepo.py
+++ b/hggit/hgrepo.py
@@ -5,36 +5,26 @@
 
 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)
--- 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