Fix compiler warning due to missing function prototype.
[svn.git] / contrib / server-side / load_repo_with_mergesensitive_copy.sh
blob20777db385f5427ef28e775a2d25cd4e363b5a7e
1 #!/bin/bash
3 #This script installs the 'pre-commit' hook on a
4 #repository and loads the dump in a merge sensitive way.
5 #Removes the pre-commit script after load is over.
9 create_sample_script_to_check_python_bindings ()
11 cat <<EOF >/tmp/check_python_bindings.py
12 #!/usr/bin/env python
13 from svn import fs, repos, core, client
14 EOF
16 create_pre_commit_script ()
18 cat <<EOF >/tmp/pre-commit
19 #!/usr/bin/env python
20 import os
21 import sys
22 from svn import fs, repos, core, client
24 node_created_at = -1
25 def get_node_creation_rev(repos_path, node_canon_path):
26 def revnum_receiver(changed_paths, revision, author, date, message, pool):
27 """ Function to receive log messages retrieved by client.log3(). """
28 globals()['node_created_at'] = revision
30 # Open up the repository and transaction.
31 client_ctx = client.svn_client_create_context()
32 start = core.svn_opt_revision_t()
33 end = core.svn_opt_revision_t()
34 core.svn_opt_parse_revision(start, end, "1:HEAD")
35 dir = "file://" + repos_path + node_canon_path
36 client.log3((dir,), end, start, end, 1, False, True,
37 revnum_receiver, client_ctx)
38 return globals()['node_created_at']
40 def traverse_tree(tree, path, txn_root, repos_path, pool):
41 if tree.copyfrom_path:
42 existing_mergeinfo = fs.svn_fs_node_prop(txn_root, path,
43 'svn:mergeinfo', pool)
44 if existing_mergeinfo:
45 if existing_mergeinfo.find(tree.copyfrom_path + ':') != -1:
46 print sys.stderr.write(("Node %s has similar mergeinfo %s") %
47 (path, existing_mergeinfo))
48 sys.exit(1)
49 src_created_at = get_node_creation_rev(repos_path, tree.copyfrom_path)
50 new_mergeinfo = tree.copyfrom_path + ":" + str(src_created_at) + "-" \\
51 + str(tree.copyfrom_rev) + '\n'
52 mergeinfo = ''
53 if existing_mergeinfo:
54 mergeinfo = existing_mergeinfo + new_mergeinfo
55 else:
56 mergeinfo = new_mergeinfo
57 repos.svn_repos_fs_change_node_prop(txn_root, path, 'svn:mergeinfo',
58 mergeinfo, pool)
59 node = tree.child
60 if not node:
61 return
62 full_path = path + '/' + node.name
63 traverse_tree(node, full_path, txn_root, repos_path, pool)
64 while node.sibling:
65 node = node.sibling
66 full_path = path + '/' + node.name
67 traverse_tree(node, full_path, txn_root, repos_path, pool)
69 def main(pool, repos_path, txn_name):
70 repo = repos.svn_repos_open(repos_path, pool)
71 repo_fs = repos.svn_repos_fs(repo)
72 txn_t = fs.open_txn(repo_fs, txn_name, pool)
74 txn_root = fs.txn_root(txn_t, pool)
75 editor_and_baton = repos.svn_repos_node_editor(repo, repo_fs, txn_root,
76 pool, pool)
77 editor = editor_and_baton[0]
78 edit_baton = editor_and_baton[1]
79 repos.svn_repos_replay2(txn_root, "", core.SWIG_SVN_INVALID_REVNUM, False,
80 editor, edit_baton, None, pool)
81 tree = repos.svn_repos_node_from_baton(edit_baton)
82 traverse_tree(tree, "", txn_root, repos_path, pool)
85 if __name__ == "__main__":
86 if len(sys.argv) < 3:
87 sys.stderr.write("usage: %s <repository> <txn>\n" %
88 os.path.basename(sys.argv[0]))
89 sys.exit(1)
90 sys.exit(core.run_app(main, sys.argv[1], sys.argv[2]))
91 EOF
94 if test $# -lt 1
95 then
96 echo "Usage: " $0 " PATH_TO_REPOS [PATH_TO_DUMP_FILE]"
97 exit 1
99 which svnadmin 2>&1>/dev/null
100 if test $? -ne 0
101 then
102 echo "Please install svnadmin"
103 exit 1
106 create_sample_script_to_check_python_bindings
107 chmod 755 /tmp/check_python_bindings.py
108 /tmp/check_python_bindings.py 2>/dev/null
109 if test $? -ne 0
110 then
111 echo "Please install python bindings"
112 exit 1
114 rm /tmp/check_python_bindings.py
116 rm -rf /tmp/pre-commit*
117 create_pre_commit_script
118 cd $1 2>/dev/null
119 if test $? -ne 0
120 then
121 echo "$1 does not seem to be a repository."
122 exit 1
124 REPO_ABS_PATH=`pwd`
125 cd -
126 if test -f $REPO_ABS_PATH/hooks/pre-commit
127 then
128 cp $REPO_ABS_PATH/hooks/pre-commit /tmp/pre_commit.orig
130 cp /tmp/pre-commit $REPO_ABS_PATH/hooks/pre-commit
131 chmod 755 $REPO_ABS_PATH/hooks/pre-commit
133 if test -n "$2"
134 then
135 cat "$2"|svnadmin load $REPO_ABS_PATH --use-pre-commit-hook
136 else
137 svnadmin load $REPO_ABS_PATH --use-pre-commit-hook
140 if test -f /tmp/pre_commit.orig
141 then
142 cp /tmp/pre_commit.orig $REPO_ABS_PATH/hooks/pre-commit