Follow-up to r29036: Now that the "mergeinfo" transaction file is no
[svn.git] / contrib / hook-scripts / commit-block-joke.py
blobe4a2b35514e459a11d8b93f9ead0e07131e03d89
1 #!/usr/bin/env python
2 # ====================================================================
3 # Copyright (c) 2004 CollabNet. All rights reserved.
5 # This software is licensed as described in the file COPYING, which
6 # you should have received as part of this distribution. The terms
7 # are also available at http://subversion.tigris.org/license.html.
8 # If newer versions of this license are posted there, you may use a
9 # newer version instead, at your option.
11 # This software consists of voluntary contributions made by many
12 # individuals. For exact contribution history, see the revision
13 # history and logs, available at http://subversion.tigris.org/.
14 # ====================================================================
16 import sys, os, string
18 SVNLOOK='/usr/local/bin/svnlook'
19 MESSAGE="""
20 Dear {AUTHOR}:
22 We're sorry, but we just couldn't allow you to have the
23 revision {REVISION} commit.
25 -- Love, Your Administrator(s).
26 """
28 if len(sys.argv) < 5:
29 sys.stderr.write(
30 "Usage: %s REPOS AUTHOR BLOCKED_REV BLOCKED_AUTHOR [...]\n"
31 "\n"
32 "Disallow a set BLOCKED_AUTHORS from committing the revision\n"
33 "expected to bring REPOS to a youngest revision of BLOCKED_REV.\n"
34 "Written as a prank for use as a start-commit hook (which provides\n"
35 "REPOS and AUTHOR for you).\n"
36 "\n"
37 "NOTE: There is a small chance that while HEAD is BLOCKED_REV - 2,\n"
38 "a commit could slip in between the time we query the youngest\n"
39 "revision and the time this commit-in-progress actually occurs.\n"
40 "\n"
41 % sys.argv[0])
42 sys.exit(1)
44 repos = sys.argv[1]
45 author = sys.argv[2]
46 blocked_rev = sys.argv[3]
47 blocked_authors = sys.argv[4:]
49 if author in blocked_authors:
50 youngest_cmd = '%s youngest %s' % (SVNLOOK, repos)
51 youngest = os.popen(youngest_cmd, 'r').readline().rstrip('\n')
53 # See if this is the blocked revision
54 if int(youngest) == int(blocked_rev) - 1:
55 MESSAGE = MESSAGE.replace('{AUTHOR}', author)
56 MESSAGE = MESSAGE.replace('{REVISION}', blocked_rev)
57 sys.stderr.write(MESSAGE)
58 sys.exit(1)
60 sys.exit(0)