t / lib-git-svn.shon commit Merge branch 'mv/parseopt-ls-files' (de2e3b0)
   1. ./test-lib.sh
   2
   3remotes_git_svn=remotes/git""-svn
   4git_svn_id=git""-svn-id
   5
   6if test -n "$NO_SVN_TESTS"
   7then
   8        say 'skipping git svn tests, NO_SVN_TESTS defined'
   9        test_done
  10        exit
  11fi
  12
  13GIT_DIR=$PWD/.git
  14GIT_SVN_DIR=$GIT_DIR/svn/git-svn
  15SVN_TREE=$GIT_SVN_DIR/svn-tree
  16
  17svn >/dev/null 2>&1
  18if test $? -ne 1
  19then
  20    say 'skipping git svn tests, svn not found'
  21    test_done
  22    exit
  23fi
  24
  25svnrepo=$PWD/svnrepo
  26export svnrepo
  27
  28perl -w -e "
  29use SVN::Core;
  30use SVN::Repos;
  31\$SVN::Core::VERSION gt '1.1.0' or exit(42);
  32system(qw/svnadmin create --fs-type fsfs/, \$ENV{svnrepo}) == 0 or exit(41);
  33" >&3 2>&4
  34x=$?
  35if test $x -ne 0
  36then
  37        if test $x -eq 42; then
  38                err='Perl SVN libraries must be >= 1.1.0'
  39        elif test $x -eq 41; then
  40                err='svnadmin failed to create fsfs repository'
  41        else
  42                err='Perl SVN libraries not found or unusable, skipping test'
  43        fi
  44        say "$err"
  45        test_done
  46        exit
  47fi
  48
  49rawsvnrepo="$svnrepo"
  50svnrepo="file://$svnrepo"
  51
  52poke() {
  53        test-chmtime +1 "$1"
  54}
  55
  56for d in \
  57        "$SVN_HTTPD_PATH" \
  58        /usr/sbin/apache2 \
  59        /usr/sbin/httpd \
  60; do
  61        if test -f "$d"
  62        then
  63                SVN_HTTPD_PATH="$d"
  64                break
  65        fi
  66done
  67for d in \
  68        "$SVN_HTTPD_MODULE_PATH" \
  69        /usr/lib/apache2/modules \
  70        /usr/libexec/apache2 \
  71; do
  72        if test -d "$d"
  73        then
  74                SVN_HTTPD_MODULE_PATH="$d"
  75                break
  76        fi
  77done
  78
  79start_httpd () {
  80        repo_base_path="$1"
  81        if test -z "$SVN_HTTPD_PORT"
  82        then
  83                echo >&2 'SVN_HTTPD_PORT is not defined!'
  84                return
  85        fi
  86        if test -z "$repo_base_path"
  87        then
  88                repo_base_path=svn
  89        fi
  90
  91        mkdir "$GIT_DIR"/logs
  92
  93        cat > "$GIT_DIR/httpd.conf" <<EOF
  94ServerName "git svn test"
  95ServerRoot "$GIT_DIR"
  96DocumentRoot "$GIT_DIR"
  97PidFile "$GIT_DIR/httpd.pid"
  98LockFile logs/accept.lock
  99Listen 127.0.0.1:$SVN_HTTPD_PORT
 100LoadModule dav_module $SVN_HTTPD_MODULE_PATH/mod_dav.so
 101LoadModule dav_svn_module $SVN_HTTPD_MODULE_PATH/mod_dav_svn.so
 102<Location /$repo_base_path>
 103        DAV svn
 104        SVNPath "$rawsvnrepo"
 105</Location>
 106EOF
 107        "$SVN_HTTPD_PATH" -f "$GIT_DIR"/httpd.conf -k start
 108        svnrepo="http://127.0.0.1:$SVN_HTTPD_PORT/$repo_base_path"
 109}
 110
 111stop_httpd () {
 112        test -z "$SVN_HTTPD_PORT" && return
 113        "$SVN_HTTPD_PATH" -f "$GIT_DIR"/httpd.conf -k stop
 114}
 115
 116convert_to_rev_db () {
 117        perl -w -- - "$@" <<\EOF
 118use strict;
 119@ARGV == 2 or die "Usage: convert_to_rev_db <input> <output>";
 120open my $wr, '+>', $ARGV[1] or die "$!: couldn't open: $ARGV[1]";
 121open my $rd, '<', $ARGV[0] or die "$!: couldn't open: $ARGV[0]";
 122my $size = (stat($rd))[7];
 123($size % 24) == 0 or die "Inconsistent size: $size";
 124while (sysread($rd, my $buf, 24) == 24) {
 125        my ($r, $c) = unpack('NH40', $buf);
 126        my $offset = $r * 41;
 127        seek $wr, 0, 2 or die $!;
 128        my $pos = tell $wr;
 129        if ($pos < $offset) {
 130                for (1 .. (($offset - $pos) / 41)) {
 131                        print $wr (('0' x 40),"\n") or die $!;
 132                }
 133        }
 134        seek $wr, $offset, 0 or die $!;
 135        print $wr $c,"\n" or die $!;
 136}
 137close $wr or die $!;
 138close $rd or die $!;
 139EOF
 140}
 141
 142require_svnserve () {
 143    if test -z "$SVNSERVE_PORT"
 144    then
 145        say 'skipping svnserve test. (set $SVNSERVE_PORT to enable)'
 146        test_done
 147        exit
 148    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