Fix compiler warning due to missing function prototype.
[svn.git] / tools / dev / verify-history.py
blobb0cb21cae41f8cbfc160d79d0c7a66ddce4efafd
1 #!/usr/bin/env python
3 # This program is used to verify the FS history code.
5 # The basic gist is this: given a repository, a path in that
6 # repository, and a revision at which to begin plowing through history
7 # (towards revision 1), verify that each history object returned by
8 # the svn_fs_history_prev() interface -- indirectly via
9 # svn_repos_history() -- represents a revision in which the node being
10 # tracked actually changed, or where a parent directory of the node
11 # was copied, according to the list of paths changed as reported by
12 # svn_fs_paths_changed().
14 # A fun way to run this:
16 # #!/bin/sh
18 # export VERIFY=/path/to/verify-history.py
19 # export MYREPOS=/path/to/repos
21 # # List the paths in HEAD of the repos (filtering out the directories)
22 # for VCFILE in `svn ls -R file://${MYREPOS} | grep -v '/$'`; do
23 # echo "Checking ${VCFILE}"
24 # ${VERIFY} ${MYREPOS} ${VCFILE}
25 # done
27 import sys
28 import string
29 from svn import core, repos, fs
31 class HistoryChecker:
32 def __init__(self, fs_ptr):
33 self.fs_ptr = fs_ptr
35 def _check_history(self, path, revision):
36 root = fs.revision_root(self.fs_ptr, revision)
37 changes = fs.paths_changed(root)
38 while 1:
39 if changes.has_key(path):
40 return 1
41 if path == '/':
42 return 0
43 idx = string.rfind(path, '/')
44 if idx != -1:
45 path = path[:idx]
46 else:
47 return 0
49 def add_history(self, path, revision, pool=None):
50 if not self._check_history(path, revision):
51 print "**WRONG** %8d %s" % (revision, path)
52 else:
53 print " %8d %s" % (revision, path)
56 def check_history(fs_ptr, path, revision):
57 history = HistoryChecker(fs_ptr)
58 repos.history(fs_ptr, path, history.add_history,
59 1, revision, 1)
62 def main():
63 argc = len(sys.argv)
64 if argc < 3 or argc > 4:
65 print "Usage: %s PATH-TO-REPOS PATH-IN-REPOS [REVISION]" % sys.argv[0]
66 sys.exit(1)
68 fs_ptr = repos.fs(repos.open(sys.argv[1]))
69 if argc == 3:
70 revision = fs.youngest_rev(fs_ptr)
71 else:
72 revision = int(sys.argv[3])
73 check_history(fs_ptr, sys.argv[2], revision)
74 sys.exit(0)
77 if __name__ == '__main__':
78 main()