forbid_external.py
author Michal Zlamal <mzlamal@netbeans.org>
Wed May 14 14:43:41 2008 +0200 (3 months ago)
changeset 9 e9b719609c5f
parent 7f949e016630b
permissions -rw-r--r--
Fix syntax error
        1 from mercurial import util, ui
        2 from mercurial.i18n import gettext as _
        3 from mercurial.node import *
        4 import fnmatch,re
        5 
        6 def forbid_external(ui, repo, hooktype, node, **kwargs):
        7     halt = False
        8     for rev in xrange(repo.changelog.rev(bin(node)), repo.changelog.count()):
        9         c = repo.changectx(rev)
       10         file_matcher = re.compile(r'^.+/external/.+\.(zip|jar|gz|bz2|gem|dll)$')
       11         content_matcher = re.compile(r'^<<<EXTERNAL (([0-9A-F]{40})-([a-zA-Z0-9._+-]+))>>>\n$')
       12         for f in c.files():
       13             if f not in c:
       14                 continue
       15             if not file_matcher.match(c[f].path()):
       16                 continue
       17             data = c[f].data()
       18             if not content_matcher.match(data):
       19                 if not halt:
       20                     ui.warn(_('Malformed content of binary: %s\n') % c[f].path())
       21                 ui.warn(_('in %s: %s\n') % (short(c.node()), f))
       22                 halt = True
       23     if halt and hooktype == 'pretxnchangegroup':
       24         ui.warn(_('\nTo prevent this mistake in your local repository,\n'
       25                   'add to your resitory .hg/hgrc:\n'
       26                   '\n'
       27                   '[hooks[extensions]\n'
       28                   'external = /path-to-external-hook/external.py\n'
       29                   '[encode]\n'
       30                   '# To preauthenticate, use: https://jhacker:secret@hg.netbeans.org/binaries/upload\n'
       31                   '*/external/*.{zip,jar,gz,bz2,gem,dll} = upload: https://hg.netbeans.org/binaries/upload\n'
       32                   '[decode]\n'
       33                   '*/external/*.{zip,jar,gz,bz2,gem,dll} = download: http://hg.netbeans.org/binaries/\n'))
       34     return halt