Encapsulate change finding with backwards compatibility
authorPaul Crowley <paul@lshift.net>
Fri, 20 Feb 2009 15:08:50 +0000
changeset 52 f9eb98bb0791
parent 51 d87eeeae29a5
child 53 853444c5d393
Encapsulate change finding with backwards compatibility
install
src/access.py
src/changes.py
--- a/install	Fri Feb 20 14:29:48 2009 +0000
+++ b/install	Fri Feb 20 15:08:50 2009 +0000
@@ -7,6 +7,7 @@
     src/hg-ssh \
     src/do-refresh-auth
 install -o root -g root -t /usr/local/lib/mercurial-server -m 644 \
+    src/changes.py \
     src/access.py \
     src/ruleset.py
 install -o root -g root -d /usr/local/lib/mercurial-server/init
--- a/src/access.py	Fri Feb 20 14:29:48 2009 +0000
+++ b/src/access.py	Fri Feb 20 15:08:50 2009 +0000
@@ -13,6 +13,7 @@
 
 import os
 import ruleset
+import changes
 
 class Checker(object):
     '''acl checker.'''
@@ -40,14 +41,11 @@
             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 mercurial.util.Abort(_('config error - hook type "%s" cannot stop '
                            'incoming changesets') % hooktype)
     c = Checker(ui, repo)
-    start = repo.changectx(node).rev()
-    end = repo.changelog.count()
-    for rev in xrange(start, end):
-        c.check(repo.changectx(rev))
+    for ctx in changes.changes(repo, node):
+        c.check(ctx)
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/changes.py	Fri Feb 20 15:08:50 2009 +0000
@@ -0,0 +1,19 @@
+# Copyright 2008-2009 LShift Ltd
+# Copyright 2006 Vadim Gelfer <vadim.gelfer@gmail.com>
+#
+# Authors:
+# Paul Crowley <paul@lshift.net>
+# Vadim Gelfer <vadim.gelfer@gmail.com>
+#
+# This software may be used and distributed according to the terms
+# of the GNU General Public License, incorporated herein by reference.
+
+def changes(repo, node):
+    start = repo.changectx(node).rev()
+    try:
+        end = len(repo.changelog)
+    except:
+        end = repo.changelog.count()
+    for rev in xrange(start, end):
+        yield repo.changectx(rev)
+