Use the context API
authorPaul Crowley <paul@lshift.net>
Fri, 20 Feb 2009 14:29:48 +0000
changeset 51 d87eeeae29a5
parent 50 77d97aa18f29
child 52 f9eb98bb0791
Use the context API
src/access.py
--- a/src/access.py	Fri Feb 20 12:47:49 2009 +0000
+++ b/src/access.py	Fri Feb 20 14:29:48 2009 +0000
@@ -9,8 +9,7 @@
 # of the GNU General Public License, incorporated herein by reference.
 
 from mercurial.i18n import _
-from mercurial.node import *
-from mercurial import util
+import mercurial.util
 
 import os
 import ruleset
@@ -26,31 +25,29 @@
         self.rules.set(user = os.environ['REMOTE_USER'])
         self.rules.set(repo = os.environ['HG_REPO_PATH'])
 
-    def allow(self, node):
-        '''return if access allowed, raise exception if not.'''
-        ctx = self.repo.changectx(node)
+    def allow(self, ctx):
         branch = ctx.branch()
         if not self.rules.allow("write", branch=branch, file=None):
             return False
         for f in ctx.files():
             if not self.rules.allow("write", branch=branch, file=f):
                 return False
-        self.ui.debug(_('%s: allowing changeset %s\n') % (__name__, short(node)))
         return True
 
-    def check(self, node):
-        if not self.allow(node):
-            raise util.Abort(_('%s: access denied for changeset %s') %
-                (__name__, short(node)))
+    def check(self, ctx):
+        '''return if access allowed, raise exception if not.'''
+        if not self.allow(ctx):
+            raise mercurial.util.Abort(_('%s: access denied for changeset %s') %
+                (__name__, ctx.short()))
 
         
 def hook(ui, repo, hooktype, node=None, source=None, **kwargs):
     if hooktype != 'pretxnchangegroup':
-        raise util.Abort(_('config error - hook type "%s" cannot stop '
+        raise mercurial.util.Abort(_('config error - hook type "%s" cannot stop '
                            'incoming changesets') % hooktype)
     c = Checker(ui, repo)
-    start = repo.changelog.rev(bin(node))
-    end = len(repo.changelog)
+    start = repo.changectx(node).rev()
+    end = repo.changelog.count()
     for rev in xrange(start, end):
-        c.check(repo.changelog.node(rev))
+        c.check(repo.changectx(rev))