@matheusbsbs / matheus-bagliano / commits / 3aa3047106
Fork 0

lib-git-svn.sh: Move web-server handling code into separate function

This library file is currently sourced by 57 test files, of which only four may (optionally) start a web-server in order to access the svn repo via an http url, rather than a file url. In addition to isolating the current web-server handling code from the majority of tests, in a new prepare_httpd function, we also add some more error checking and reporting code to validate the apache installation. Only those tests which attempt to start the web-server, by calling start_httpd, will execute this code. Note that it is important for start_httpd to return an error indication, if prepare_httpd fails, so that the failure to use the web-server, as requested by the user, should not go unnoticed. (Unless the svnrepo variable is set to an http url at the end of start_httpd, the remaining tests will use file urls, without comment.) Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ramsay Jones committed Dec 30, 2010 at 19:44 UTC 3aa30471065b212ee6563f3bfcb2de92a2bf2fa9
1 file changed +21 -17
t/lib-git-svn.sh
+21 -17
@@ -68,8 +68,7 @@ svn_cmd () {
68 svn "$orig_svncmd" --config-dir "$svnconf" "$@"
69 }
70
71 -if test -n "$SVN_HTTPD_PORT"
72 -then
71 +prepare_httpd () {
72 for d in \
73 "$SVN_HTTPD_PATH" \
74 /usr/sbin/apache2 \
@@ -83,8 +82,8 @@ then
82 done
83 if test -z "$SVN_HTTPD_PATH"
84 then
86 - skip_all='skipping git svn tests, Apache not found'
87 - test_done
85 + echo >&2 '*** error: Apache not found'
86 + return 1
87 fi
88 for d in \
89 "$SVN_HTTPD_MODULE_PATH" \
@@ -99,23 +98,16 @@ then
98 done
99 if test -z "$SVN_HTTPD_MODULE_PATH"
100 then
102 - skip_all='skipping git svn tests, Apache module dir not found'
103 - test_done
104 - fi
105 -fi
106 -
107 -start_httpd () {
108 - repo_base_path="$1"
109 - if test -z "$SVN_HTTPD_PORT"
110 - then
111 - echo >&2 'SVN_HTTPD_PORT is not defined!'
112 - return
101 + echo >&2 '*** error: Apache module dir not found'
102 + return 1
103 fi
114 - if test -z "$repo_base_path"
104 + if test ! -f "$SVN_HTTPD_MODULE_PATH/mod_dav_svn.so"
105 then
116 - repo_base_path=svn
106 + echo >&2 '*** error: Apache module "mod_dav_svn" not found'
107 + return 1
108 fi
109
110 + repo_base_path="${1-svn}"
111 mkdir "$GIT_DIR"/logs
112
113 cat > "$GIT_DIR/httpd.conf" <<EOF
@@ -132,12 +124,24 @@ LoadModule dav_svn_module $SVN_HTTPD_MODULE_PATH/mod_dav_svn.so
124 SVNPath "$rawsvnrepo"
125 </Location>
126 EOF
127 +}
128 +
129 +start_httpd () {
130 + if test -z "$SVN_HTTPD_PORT"
131 + then
132 + echo >&2 'SVN_HTTPD_PORT is not defined!'
133 + return
134 + fi
135 +
136 + prepare_httpd "$1" || return 1
137 +
138 "$SVN_HTTPD_PATH" -f "$GIT_DIR"/httpd.conf -k start
139 svnrepo="http://127.0.0.1:$SVN_HTTPD_PORT/$repo_base_path"
140 }
141
142 stop_httpd () {
143 test -z "$SVN_HTTPD_PORT" && return
144 + test ! -f "$GIT_DIR/httpd.conf" && return
145 "$SVN_HTTPD_PATH" -f "$GIT_DIR"/httpd.conf -k stop
146 }
147