Add a validation script
[svnrdump.git] / validate.sh
blob6bdb42751685ed43b7898034adb09b37c8cfd9ef
1 #!/bin/sh
2 usage(){
3 sed 's/..//' <<USAGE
4 Usage: validate.sh [--svnadmin-dump=<file>] [--svnrdump-dump=<file>]
5 [--repos=<url-or-path>] [-r<revision>]
6 [--ignore-existing-dump] [--make]
7 [generate] [validate]
8 USAGE
11 svnadmin_dump=
12 svnrdump_dump=
13 repos_url=
14 repos_path=
15 end_rev=
16 do_make=
17 do_both=1
18 do_generate=1
19 do_validate=1
20 do_ignore_existing_svnadmin_dump=
21 while test "$#" -gt 0; do
22 case "$1" in
23 --svnadmin-dump=*)
24 svnadmin_dump="${1#*=}"
26 --svnrdump-dump=*)
27 svnrdump_dump="${1#*=}"
29 --ignore-existing|--ignore-existing-dump)
30 do_ignore_existing_svnadmin_dump=1
32 --repos=*)
33 repos_url="${1#*=}"
34 repos_protocol="${repos_url%://*}"
35 repos_path="${repos_url#file://}"
36 if test "$repos_protocol" = "$repos_path"; then
37 repos_protocol=
38 repos_url=
39 elif test ! "$repos_protocol" = 'file'; then
40 repos_path=
43 -r*)
44 end_rev="${1#-r}"
46 --make)
47 do_make=1
49 generate)
50 do_generate=1
51 test -n "$do_both" && do_validate=
52 do_both=
54 validate)
55 do_validate=1
56 test -n "$do_both" && do_generate=
57 do_both=
59 -h|--help)
60 usage
61 exit
64 echo "unknown option $1" >&2
65 usage >&2
66 exit 1
67 esac
68 shift
69 done
71 if test -z "$svnrdump_dump"; then
72 if test -z "$repos_url"; then
73 if test -n "$repos_path"; then
74 repos_url="file://$(readlink -f "$repos_path")"
75 if test $? -ne 0; then
76 echo "error: unable to derive repos url from path" >&2
77 echo "--svnrdump_dump=<file> or a local (file://) --repos=<url> is required" >&2
78 exit 1
80 else
81 echo "--svnrdump_dump=<file> or a local (file://) --repos=<url> is required" >&2
82 exit 1
87 svnadmin_dump_cut="t/svnadmin-$end_rev.dump"
88 svnrdump_dump_cut="t/svnrdump-$end_rev.dump"
89 mkdir t 2>/dev/null
91 if test -z "$svnadmin_dump"; then
92 if test -z "$repos_path"; then
93 echo "--svnadmin_dump=<file> or a local (file://) --repos=<url> is required" >&2
94 usage >&2
95 exit 1
98 svnadmin_dump="$svnadmin_dump_cut"
99 if test -z "$do_ignore_existing_svnadmin_dump" && test -r "$svnadmin_dump"; then
100 echo "Using existing $svnadmin_dump"
101 else
102 echo "Generating $svnadmin_dump ..."
105 if test -n "$end_rev"; then
106 r="-r0:$end_rev"
107 else
108 r="-r0:HEAD"
111 svnadmin dump --deltas $r "$repos_path" > "$svnadmin_dump"
112 if test $? -ne 0; then
113 echo "error: failed to create canonical dump for comparison" >&2
114 exit 1
117 else
118 echo "Using specified $svnadmin_dump"
121 if test -z "$svnrdump_dump"; then
122 svnrdump_dump="$svnrdump_dump_cut"
124 if test -n "$do_make"; then
125 make svnrdump > /dev/null;
126 if test $? -ne 0; then
127 echo "error: Make failed. Check the program." >&2
128 exit 1;
132 echo "Generating $svnrdump_dump ..."
135 test -n "$end_rev" && r="-r0:$end_rev"
137 ./svnrdump -v $r "$repos_url" > "$svnrdump_dump"
138 if test $? -ne 0; then
139 echo "error: failed to create dump for validation" >&2
140 exit 1
142 else
143 echo "Using specified $svnrdump_dump"
146 cut_dump(){
147 r="$1"
148 test -z "$r" && r=-1
150 gawk '
151 BEGIN {
152 max='"$r"'
153 hit_max=0
155 /^Revision-number: [0-9][0-9]*$/ {
156 rev=$2
157 if (rev == max) {
158 hit_max=1
159 } else if ( hit_max ) {
160 exit
163 { print $0 }
164 END {
165 if (max == -1 || hit_max) {
166 exit 0
168 exit 1
172 if test ! "$svnadmin_dump" = "$svnadmin_dump_cut"; then
173 cut_dump "$end_rev" <"$svnadmin_dump" >"$svnadmin_dump_cut"
174 if test $? -ne 0; then
175 echo "error: failed to cut canonical dump $svnadmin_dump for comparison" >&2
176 exit 1
178 echo "Successfully generated cut canonical dump $svnadmin_dump_cut for comparison" >&2
181 echo "Comparing canonical and svnrdump-based dumps..."
182 diff -au "$svnadmin_dump_cut" "$svnrdump_dump" > t/dump-diff.error
183 gawk \
184 '$0 !~ "Prop-delta: true|Text-delta-base-|sha1|Text-copy-source-|^-$" && $0 ~ "^+|^-" { print; }' \
185 t/dump-diff.error >t/dump-diff-filtered.error;
187 if test -n "$do_generate"; then
188 echo "Generating canonical import logs..."
190 rm -rf t/repo;
191 mkdir t/repo;
192 svnadmin create t/repo;
194 svnadmin load t/repo < "$svnadmin_dump_cut" \
195 1>"$svnadmin_dump_cut.import.log" 2>"$svnadmin_dump_cut.import.error";
196 if test $? -ne 0; then
197 echo "error: Load $end_rev failed. See $svnadmin_dump_cut.import.* for details" >&2
198 exit 1
200 echo "Successfully generated canonical repository for comparison."
203 if test -n "$do_validate"; then
204 echo "Generating svnrdump-based import logs..."
206 log_prefix=t/svnrdump-$end_rev
208 rm -rf t/repo;
209 mkdir t/repo;
210 svnadmin create t/repo;
212 svnadmin load t/repo < "$svnrdump_dump" 1>"$log_prefix.import.log" 2>"$log_prefix.import.error";
213 if test $? -ne 0; then
214 echo "error: Load $end_rev failed. See $log_prefix.import.* for details" >&2
215 exit 1
217 echo "Successfully loaded svnrdump-based repository for validation"
219 echo "Comparing canonical and svnrdump-based import logs..."
220 diff -au "$svnadmin_dump_cut.import.log" "$log_prefix.import.log" > t/import-diff.error;
221 if test $? -ne 0; then
222 echo "Validation failed. See t/import-diff.error for details." >&2
223 exit 1
225 echo "Validation successful"