|
1 # filecheck.py - changeset filename check for mercurial |
|
2 # |
|
3 # should be configured as pretxnchangegroup to vet incoming changesets |
|
4 # and as pretxncommit to vet local commit |
|
5 # |
|
6 # will receive a group of changesets from provided node to tip |
|
7 |
|
8 from mercurial import util |
|
9 from mercurial.i18n import _ |
|
10 import re |
|
11 |
|
12 badpatterns = ('.*\.ttt\s*$','c.ttf','.*\.ttf\s*$','.*\.bbb\s*$', |
|
13 '.*\.bbb\s*$','.*\.ccc\s*$','.*\.ddd\s*$','.*\.eee\s*$','.*\.fff\s*$','.*\.ggg\s*$') |
|
14 |
|
15 badexpr=[] |
|
16 runonce=0 |
|
17 |
|
18 def init(): |
|
19 global badexpr |
|
20 for p in badpatterns: |
|
21 badexpr.append((re.compile((p),re.IGNORECASE))) |
|
22 |
|
23 def deny(f): |
|
24 global runonce |
|
25 if (not runonce): |
|
26 init() |
|
27 runonce =1 |
|
28 |
|
29 for pat in badexpr: |
|
30 if(pat.match(f)): |
|
31 return(1) |
|
32 |
|
33 return(0) |
|
34 |
|
35 def push_hook(ui, repo, hooktype, node=None, source=None, **kwargs): |
|
36 if hooktype != 'pretxnchangegroup': |
|
37 raise util.Abort(_('config error - hook type "%s" cannot stop ' |
|
38 'incoming changesets') % hooktype) |
|
39 |
|
40 # iterate over all the added changesets between node and tip |
|
41 for rev in xrange(repo[node], len(repo)): |
|
42 ctx = repo[rev] |
|
43 for f in ctx.files(): |
|
44 if deny(f): |
|
45 ui.debug(_('filecheck: file %s not allowed \n') % (f)) |
|
46 raise util.Abort(_('filecheck: access denied for changeset %s file %s blocked') % (ctx,f)) |
|
47 ui.debug(_('filecheck: allowing changeset %s\n') % ctx) |
|
48 |
|
49 def commit_hook(ui, repo, hooktype, node=None, source=None, **kwargs): |
|
50 # iterate over all the files in added changeset |
|
51 ctx = repo[node] |
|
52 for f in ctx.files(): |
|
53 if deny(f): |
|
54 ui.debug(_('filecheck: file %s not allowed \n') % (f)) |
|
55 raise util.Abort(_('filecheck: access denied for changeset %s file %s blocked') % (ctx,f)) |
|
56 ui.debug(_('filecheck: allowing changeset %s\n') % ctx) |