2 # ====================================================================
3 # Copyright (c) 2004-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 # ====================================================================
19 from svn
import repos
, fs
, delta
, core
22 ### DEAR USER: Please populate the test_props() and test_path_change()
23 ### to do your bidding.
26 def test_props(props
):
27 """Validate the PROPS (a dictionary mapping property names to
28 values) set on the transaction. Return 0 if all is well, non-zero
31 ### Test the transaction (revision-to-be) properties. If there is
32 ### bogosity, write to sys.stderr and return non-zero.
37 def test_path_change(path
, change
):
38 """Validate the CHANGE made to PATH in the transaction. Return 0
39 if all is well, non-zero otherwise."""
41 # The svn_node_kind of the path.
42 item_kind
= change
.item_kind
44 # Non-zero iff properties of this path were changed.
45 prop_changes
= change
.prop_changes
47 # Non-zero iff path is a file, and its text was changed.
48 text_changed
= change
.text_changed
50 # The location of the previous revision of this resource, if any.
51 base_path
= change
.base_path
52 base_rev
= change
.base_rev
54 # Non-zero iff this change represents an addition (see
55 # base_path/base_rev for whether it was an addition with history).
58 ### Test the path change as you see fit. If there is bogosity,
59 ### write to sys.stderr and return non-zero.
64 def main(pool
, repos_dir
, txn
):
65 # Construct a ChangeCollector to fetch our changes.
66 fs_ptr
= repos
.svn_repos_fs(repos
.svn_repos_open(repos_dir
, pool
))
67 root
= fs
.txn_root(fs
.open_txn(fs_ptr
, txn
, pool
), pool
)
68 cc
= repos
.ChangeCollector(fs_ptr
, root
, pool
)
70 # Call the transaction property validator. Might as well get the
71 # cheap checks outta the way first.
72 retval
= test_props(cc
.get_root_props())
76 # Generate the path-based changes list.
77 e_ptr
, e_baton
= delta
.make_editor(cc
, pool
)
78 repos
.svn_repos_replay(root
, e_ptr
, e_baton
, pool
)
80 # Call the path change validator.
81 changes
= cc
.get_changes()
82 paths
= changes
.keys()
83 paths
.sort(lambda a
, b
: core
.svn_path_compare_paths(a
, b
))
85 change
= changes
[path
]
86 retval
= test_path_change(path
, change
)
93 def _usage_and_exit():
94 sys
.stderr
.write("USAGE: %s REPOS-DIR TXN-NAME\n" % (sys
.argv
[0]))
98 if __name__
== '__main__':
101 sys
.exit(core
.run_app(main
, sys
.argv
[1], sys
.argv
[2]))