Code

lib-git-svn.sh: Avoid setting web server variables unnecessarily
[git.git] / t / lib-git-svn.sh
1 . ./test-lib.sh
3 remotes_git_svn=remotes/git""-svn
4 git_svn_id=git""-svn-id
6 if test -n "$NO_SVN_TESTS"
7 then
8         skip_all='skipping git svn tests, NO_SVN_TESTS defined'
9         test_done
10 fi
11 if ! test_have_prereq PERL; then
12         skip_all='skipping git svn tests, perl not available'
13         test_done
14 fi
16 GIT_DIR=$PWD/.git
17 GIT_SVN_DIR=$GIT_DIR/svn/refs/remotes/git-svn
18 SVN_TREE=$GIT_SVN_DIR/svn-tree
20 svn >/dev/null 2>&1
21 if test $? -ne 1
22 then
23     skip_all='skipping git svn tests, svn not found'
24     test_done
25 fi
27 svnrepo=$PWD/svnrepo
28 export svnrepo
29 svnconf=$PWD/svnconf
30 export svnconf
32 "$PERL_PATH" -w -e "
33 use SVN::Core;
34 use SVN::Repos;
35 \$SVN::Core::VERSION gt '1.1.0' or exit(42);
36 system(qw/svnadmin create --fs-type fsfs/, \$ENV{svnrepo}) == 0 or exit(41);
37 " >&3 2>&4
38 x=$?
39 if test $x -ne 0
40 then
41         if test $x -eq 42; then
42                 skip_all='Perl SVN libraries must be >= 1.1.0'
43         elif test $x -eq 41; then
44                 skip_all='svnadmin failed to create fsfs repository'
45         else
46                 skip_all='Perl SVN libraries not found or unusable'
47         fi
48         test_done
49 fi
51 rawsvnrepo="$svnrepo"
52 svnrepo="file://$svnrepo"
54 poke() {
55         test-chmtime +1 "$1"
56 }
58 # We need this, because we should pass empty configuration directory to
59 # the 'svn commit' to avoid automated property changes and other stuff
60 # that could be set from user's configuration files in ~/.subversion.
61 svn_cmd () {
62         [ -d "$svnconf" ] || mkdir "$svnconf"
63         orig_svncmd="$1"; shift
64         if [ -z "$orig_svncmd" ]; then
65                 svn
66                 return
67         fi
68         svn "$orig_svncmd" --config-dir "$svnconf" "$@"
69 }
71 if test -n "$SVN_HTTPD_PORT"
72 then
73         for d in \
74                 "$SVN_HTTPD_PATH" \
75                 /usr/sbin/apache2 \
76                 /usr/sbin/httpd \
77         ; do
78                 if test -f "$d"
79                 then
80                         SVN_HTTPD_PATH="$d"
81                         break
82                 fi
83         done
84         for d in \
85                 "$SVN_HTTPD_MODULE_PATH" \
86                 /usr/lib/apache2/modules \
87                 /usr/libexec/apache2 \
88         ; do
89                 if test -d "$d"
90                 then
91                         SVN_HTTPD_MODULE_PATH="$d"
92                         break
93                 fi
94         done
95 fi
97 start_httpd () {
98         repo_base_path="$1"
99         if test -z "$SVN_HTTPD_PORT"
100         then
101                 echo >&2 'SVN_HTTPD_PORT is not defined!'
102                 return
103         fi
104         if test -z "$repo_base_path"
105         then
106                 repo_base_path=svn
107         fi
109         mkdir "$GIT_DIR"/logs
111         cat > "$GIT_DIR/httpd.conf" <<EOF
112 ServerName "git svn test"
113 ServerRoot "$GIT_DIR"
114 DocumentRoot "$GIT_DIR"
115 PidFile "$GIT_DIR/httpd.pid"
116 LockFile logs/accept.lock
117 Listen 127.0.0.1:$SVN_HTTPD_PORT
118 LoadModule dav_module $SVN_HTTPD_MODULE_PATH/mod_dav.so
119 LoadModule dav_svn_module $SVN_HTTPD_MODULE_PATH/mod_dav_svn.so
120 <Location /$repo_base_path>
121         DAV svn
122         SVNPath "$rawsvnrepo"
123 </Location>
124 EOF
125         "$SVN_HTTPD_PATH" -f "$GIT_DIR"/httpd.conf -k start
126         svnrepo="http://127.0.0.1:$SVN_HTTPD_PORT/$repo_base_path"
129 stop_httpd () {
130         test -z "$SVN_HTTPD_PORT" && return
131         "$SVN_HTTPD_PATH" -f "$GIT_DIR"/httpd.conf -k stop
134 convert_to_rev_db () {
135         "$PERL_PATH" -w -- - "$@" <<\EOF
136 use strict;
137 @ARGV == 2 or die "Usage: convert_to_rev_db <input> <output>";
138 open my $wr, '+>', $ARGV[1] or die "$!: couldn't open: $ARGV[1]";
139 open my $rd, '<', $ARGV[0] or die "$!: couldn't open: $ARGV[0]";
140 my $size = (stat($rd))[7];
141 ($size % 24) == 0 or die "Inconsistent size: $size";
142 while (sysread($rd, my $buf, 24) == 24) {
143         my ($r, $c) = unpack('NH40', $buf);
144         my $offset = $r * 41;
145         seek $wr, 0, 2 or die $!;
146         my $pos = tell $wr;
147         if ($pos < $offset) {
148                 for (1 .. (($offset - $pos) / 41)) {
149                         print $wr (('0' x 40),"\n") or die $!;
150                 }
151         }
152         seek $wr, $offset, 0 or die $!;
153         print $wr $c,"\n" or die $!;
155 close $wr or die $!;
156 close $rd or die $!;
157 EOF
160 require_svnserve () {
161     if test -z "$SVNSERVE_PORT"
162     then
163         skip_all='skipping svnserve test. (set $SVNSERVE_PORT to enable)'
164         test_done
165     fi
168 start_svnserve () {
169     svnserve --listen-port $SVNSERVE_PORT \
170              --root "$rawsvnrepo" \
171              --listen-once \
172              --listen-host 127.0.0.1 &