Follow-up to r29036: Now that the "mergeinfo" transaction file is no
[svn.git] / contrib / hook-scripts / pre-lock-require-needs-lock.py
blob8377829988a8c0a7699449e3b9e03ebf2016b84d
1 #!/usr/bin/env python
2 # ====================================================================
3 # Copyright (c) 2005 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
17 import os
18 import os.path
19 from svn import repos, fs, core
21 def main(pool, repos_dir, path):
22 # Construct a ChangeCollector to fetch our changes.
23 fs_ptr = repos.svn_repos_fs(repos.svn_repos_open(repos_dir, pool))
24 youngest_rev = fs.svn_fs_youngest_rev(fs_ptr, pool)
25 root = fs.svn_fs_revision_root(fs_ptr, youngest_rev, pool)
26 if not fs.svn_fs_node_prop(root, path, core.SVN_PROP_NEEDS_LOCK, pool):
27 sys.stderr.write(
28 """Locking of path '%s' prohibited by repository policy (must have
29 %s property set)
30 """ % (path, core.SVN_PROP_NEEDS_LOCK))
31 return 1
32 return 0
35 def _usage_and_exit():
36 sys.stderr.write("""
37 Usage: %s REPOS-DIR PATH
39 This script, intended for use as a Subversion pre-lock hook, verifies that
40 the PATH that USER is attempting to lock has the %s property
41 set on it, returning success iff it does.
42 """ % (os.path.basename(sys.argv[0]), core.SVN_PROP_NEEDS_LOCK))
43 sys.exit(1)
46 if __name__ == '__main__':
47 if len(sys.argv) < 3:
48 _usage_and_exit()
49 sys.exit(core.run_app(main, sys.argv[1], sys.argv[2]))