blob: 773d47cf3cb704d7976185738a2b9840c159a33c [file] [log] [blame]
Eric Wong36f5b1f2006-05-23 19:23:41 -07001. ./test-lib.sh
2
Nanako Shiraishi16805d32008-09-08 19:02:05 +09003remotes_git_svn=remotes/git""-svn
4git_svn_id=git""-svn-id
5
Eric Wong60d02cc2006-07-06 00:14:16 -07006if test -n "$NO_SVN_TESTS"
7then
Johannes Sixtfae74a02009-03-01 19:52:51 +01008 say 'skipping git svn tests, NO_SVN_TESTS defined'
Eric Wong60d02cc2006-07-06 00:14:16 -07009 test_done
Eric Wong60d02cc2006-07-06 00:14:16 -070010fi
Jeff King1b19ccd2009-04-03 15:33:59 -040011if ! test_have_prereq PERL; then
12 say 'skipping git svn tests, perl not available'
13 test_done
14fi
Eric Wong60d02cc2006-07-06 00:14:16 -070015
Eric Wong36f5b1f2006-05-23 19:23:41 -070016GIT_DIR=$PWD/.git
Eric Wong883d0a72006-05-24 01:22:07 -070017GIT_SVN_DIR=$GIT_DIR/svn/git-svn
Eric Wonga5e0ced2006-06-12 15:23:48 -070018SVN_TREE=$GIT_SVN_DIR/svn-tree
Eric Wong36f5b1f2006-05-23 19:23:41 -070019
Eric Wong36f5b1f2006-05-23 19:23:41 -070020svn >/dev/null 2>&1
Junio C Hamano4b832e82006-07-07 03:17:16 -070021if test $? -ne 1
Eric Wong36f5b1f2006-05-23 19:23:41 -070022then
Johannes Sixtfae74a02009-03-01 19:52:51 +010023 say 'skipping git svn tests, svn not found'
Eric Wong36f5b1f2006-05-23 19:23:41 -070024 test_done
Eric Wong36f5b1f2006-05-23 19:23:41 -070025fi
26
27svnrepo=$PWD/svnrepo
Bryan Donlancdf3ec02008-05-04 01:37:57 -040028export svnrepo
Eric Wong36f5b1f2006-05-23 19:23:41 -070029
Eric Wongc6d499a2006-12-31 21:49:45 -080030perl -w -e "
31use SVN::Core;
32use SVN::Repos;
33\$SVN::Core::VERSION gt '1.1.0' or exit(42);
Bryan Donlancdf3ec02008-05-04 01:37:57 -040034system(qw/svnadmin create --fs-type fsfs/, \$ENV{svnrepo}) == 0 or exit(41);
Shawn O. Pearce38434f22007-01-14 03:22:47 -050035" >&3 2>&4
Eric Wongc6d499a2006-12-31 21:49:45 -080036x=$?
37if test $x -ne 0
Eric Wongdc62e252006-06-28 03:07:14 -070038then
Eric Wongc6d499a2006-12-31 21:49:45 -080039 if test $x -eq 42; then
40 err='Perl SVN libraries must be >= 1.1.0'
Eric Wonge66191f2007-01-13 02:47:53 -080041 elif test $x -eq 41; then
42 err='svnadmin failed to create fsfs repository'
Eric Wongc6d499a2006-12-31 21:49:45 -080043 else
44 err='Perl SVN libraries not found or unusable, skipping test'
45 fi
Johannes Sixtfae74a02009-03-01 19:52:51 +010046 say "$err"
Eric Wongc6d499a2006-12-31 21:49:45 -080047 test_done
Eric Wongdc62e252006-06-28 03:07:14 -070048fi
49
sam@vilain.net2edb9c52006-12-05 16:17:38 +110050rawsvnrepo="$svnrepo"
Eric Wonge1516112006-11-27 21:46:50 -080051svnrepo="file://$svnrepo"
Eric Wong36f5b1f2006-05-23 19:23:41 -070052
Michael Spang7b3fab82007-02-12 19:33:37 -050053poke() {
Eric Wong56cf9802007-02-24 16:59:52 -080054 test-chmtime +1 "$1"
Michael Spang7b3fab82007-02-12 19:33:37 -050055}
Eric Wong29633bb2007-07-15 21:53:50 -070056
Kevin Ballard3644da72008-03-21 03:27:35 -040057for d in \
58 "$SVN_HTTPD_PATH" \
59 /usr/sbin/apache2 \
60 /usr/sbin/httpd \
61; do
62 if test -f "$d"
63 then
64 SVN_HTTPD_PATH="$d"
65 break
66 fi
67done
68for d in \
69 "$SVN_HTTPD_MODULE_PATH" \
70 /usr/lib/apache2/modules \
71 /usr/libexec/apache2 \
72; do
73 if test -d "$d"
74 then
75 SVN_HTTPD_MODULE_PATH="$d"
76 break
77 fi
78done
Eric Wong29633bb2007-07-15 21:53:50 -070079
80start_httpd () {
Eric Wongd1a8d0e2008-05-10 17:14:49 -070081 repo_base_path="$1"
Eric Wong29633bb2007-07-15 21:53:50 -070082 if test -z "$SVN_HTTPD_PORT"
83 then
84 echo >&2 'SVN_HTTPD_PORT is not defined!'
85 return
86 fi
Eric Wongd1a8d0e2008-05-10 17:14:49 -070087 if test -z "$repo_base_path"
88 then
89 repo_base_path=svn
90 fi
Eric Wong29633bb2007-07-15 21:53:50 -070091
92 mkdir "$GIT_DIR"/logs
93
94 cat > "$GIT_DIR/httpd.conf" <<EOF
Nanako Shiraishi1364ff22008-09-08 19:02:08 +090095ServerName "git svn test"
Eric Wong29633bb2007-07-15 21:53:50 -070096ServerRoot "$GIT_DIR"
97DocumentRoot "$GIT_DIR"
98PidFile "$GIT_DIR/httpd.pid"
Kevin Ballard3644da72008-03-21 03:27:35 -040099LockFile logs/accept.lock
Eric Wong29633bb2007-07-15 21:53:50 -0700100Listen 127.0.0.1:$SVN_HTTPD_PORT
101LoadModule dav_module $SVN_HTTPD_MODULE_PATH/mod_dav.so
102LoadModule dav_svn_module $SVN_HTTPD_MODULE_PATH/mod_dav_svn.so
Eric Wongd1a8d0e2008-05-10 17:14:49 -0700103<Location /$repo_base_path>
Eric Wong29633bb2007-07-15 21:53:50 -0700104 DAV svn
Eric Wong3901a8c2008-07-14 02:13:56 -0700105 SVNPath "$rawsvnrepo"
Eric Wong29633bb2007-07-15 21:53:50 -0700106</Location>
107EOF
108 "$SVN_HTTPD_PATH" -f "$GIT_DIR"/httpd.conf -k start
Eric Wongd1a8d0e2008-05-10 17:14:49 -0700109 svnrepo="http://127.0.0.1:$SVN_HTTPD_PORT/$repo_base_path"
Eric Wong29633bb2007-07-15 21:53:50 -0700110}
111
112stop_httpd () {
113 test -z "$SVN_HTTPD_PORT" && return
114 "$SVN_HTTPD_PATH" -f "$GIT_DIR"/httpd.conf -k stop
115}
Eric Wong060610c2007-12-08 23:27:41 -0800116
117convert_to_rev_db () {
118 perl -w -- - "$@" <<\EOF
119use strict;
120@ARGV == 2 or die "Usage: convert_to_rev_db <input> <output>";
121open my $wr, '+>', $ARGV[1] or die "$!: couldn't open: $ARGV[1]";
122open my $rd, '<', $ARGV[0] or die "$!: couldn't open: $ARGV[0]";
123my $size = (stat($rd))[7];
124($size % 24) == 0 or die "Inconsistent size: $size";
125while (sysread($rd, my $buf, 24) == 24) {
126 my ($r, $c) = unpack('NH40', $buf);
127 my $offset = $r * 41;
128 seek $wr, 0, 2 or die $!;
129 my $pos = tell $wr;
130 if ($pos < $offset) {
131 for (1 .. (($offset - $pos) / 41)) {
132 print $wr (('0' x 40),"\n") or die $!;
133 }
134 }
135 seek $wr, $offset, 0 or die $!;
136 print $wr $c,"\n" or die $!;
137}
138close $wr or die $!;
139close $rd or die $!;
140EOF
141}
Alec Berrymandd9da512008-09-14 17:14:15 -0400142
143require_svnserve () {
144 if test -z "$SVNSERVE_PORT"
145 then
146 say 'skipping svnserve test. (set $SVNSERVE_PORT to enable)'
147 test_done
Alec Berrymandd9da512008-09-14 17:14:15 -0400148 fi
149}
150
151start_svnserve () {
152 svnserve --listen-port $SVNSERVE_PORT \
153 --root "$rawsvnrepo" \
154 --listen-once \
155 --listen-host 127.0.0.1 &
156}
157