Skip to content

Commit c0cb4ed

Browse files
pksunkaragitster
authored andcommitted
git-instaweb: Configure it to work with new gitweb structure
git-instaweb in its current form (re)creates gitweb.cgi and (some of) required static files in $GIT_DIR/gitweb/ directory. Splitting gitweb would make it difficult for git-instaweb to continue with this method. Use the instaweb.gitwebdir config variable to point git-instaweb script to a global directory which contains gitweb files as server root and the httpd.conf along with server logs and pid go into '$(GIT_DIR)/gitweb' directory. Signed-off-by: Pavan Kumar Sunkara <[email protected]> Mentored-by: Christian Couder <[email protected]> Mentored-by: Petr Baudis <[email protected]> Acked-by: Jakub Narebski <[email protected]> Acked-by: Petr Baudis <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent be5347b commit c0cb4ed

File tree

2 files changed

+27
-52
lines changed

2 files changed

+27
-52
lines changed

Makefile

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1443,6 +1443,7 @@ gitexecdir_SQ = $(subst ','\'',$(gitexecdir))
14431443
template_dir_SQ = $(subst ','\'',$(template_dir))
14441444
htmldir_SQ = $(subst ','\'',$(htmldir))
14451445
prefix_SQ = $(subst ','\'',$(prefix))
1446+
gitwebdir_SQ = $(subst ','\'',$(gitwebdir))
14461447

14471448
SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))
14481449
PERL_PATH_SQ = $(subst ','\'',$(PERL_PATH))
@@ -1609,15 +1610,8 @@ git-instaweb: git-instaweb.sh gitweb/gitweb.cgi gitweb/static/gitweb.css gitweb/
16091610
sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
16101611
-e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \
16111612
-e 's/@@NO_CURL@@/$(NO_CURL)/g' \
1612-
-e '/@@GITWEB_CGI@@/r gitweb/gitweb.cgi' \
1613-
-e '/@@GITWEB_CGI@@/d' \
1614-
-e '/@@GITWEB_CSS@@/r $(GITWEB_CSS)' \
1615-
-e '/@@GITWEB_CSS@@/d' \
1616-
-e '/@@GITWEB_JS@@/r $(GITWEB_JS)' \
1617-
-e '/@@GITWEB_JS@@/d' \
1613+
-e 's|@@GITWEBDIR@@|$(gitwebdir_SQ)|g' \
16181614
-e 's|@@PERL@@|$(PERL_PATH_SQ)|g' \
1619-
-e 's|@@GITWEB_CSS_NAME@@|$(GITWEB_CSS)|' \
1620-
-e 's|@@GITWEB_JS_NAME@@|$(GITWEB_JS)|' \
16211615
$@.sh > $@+ && \
16221616
chmod +x $@+ && \
16231617
mv $@+ $@
@@ -1984,6 +1978,7 @@ install: all
19841978
$(MAKE) -C templates DESTDIR='$(DESTDIR_SQ)' install
19851979
ifndef NO_PERL
19861980
$(MAKE) -C perl prefix='$(prefix_SQ)' DESTDIR='$(DESTDIR_SQ)' install
1981+
$(MAKE) -C gitweb gitwebdir=$(gitwebdir_SQ) install
19871982
endif
19881983
ifndef NO_PYTHON
19891984
$(MAKE) -C git_remote_helpers prefix='$(prefix_SQ)' DESTDIR='$(DESTDIR_SQ)' install

git-instaweb.sh

Lines changed: 24 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ restart restart the web server
2424
fqgitdir="$GIT_DIR"
2525
local="$(git config --bool --get instaweb.local)"
2626
httpd="$(git config --get instaweb.httpd)"
27+
root="$(git config --get instaweb.gitwebdir)"
2728
port=$(git config --get instaweb.port)
2829
module_path="$(git config --get instaweb.modulepath)"
2930

@@ -34,6 +35,9 @@ conf="$GIT_DIR/gitweb/httpd.conf"
3435
# if installed, it doesn't need further configuration (module_path)
3536
test -z "$httpd" && httpd='lighttpd -f'
3637

38+
# Default is @@GITWEBDIR@@
39+
test -z "$root" && root='@@GITWEBDIR@@'
40+
3741
# any untaken local port will do...
3842
test -z "$port" && port=1234
3943

@@ -57,7 +61,7 @@ resolve_full_httpd () {
5761
# these days and those are not in most users $PATHs
5862
# in addition, we may have generated a server script
5963
# in $fqgitdir/gitweb.
60-
for i in /usr/local/sbin /usr/sbin "$fqgitdir/gitweb"
64+
for i in /usr/local/sbin /usr/sbin "$root" "$fqgitdir/gitweb"
6165
do
6266
if test -x "$i/$httpd_only"
6367
then
@@ -159,8 +163,8 @@ done
159163
mkdir -p "$GIT_DIR/gitweb/tmp"
160164
GIT_EXEC_PATH="$(git --exec-path)"
161165
GIT_DIR="$fqgitdir"
162-
export GIT_EXEC_PATH GIT_DIR
163-
166+
GITWEB_CONFIG="$fqgitdir/gitweb/gitweb_config.perl"
167+
export GIT_EXEC_PATH GIT_DIR GITWEB_CONFIG
164168

165169
webrick_conf () {
166170
# generate a standalone server script in $fqgitdir/gitweb.
@@ -192,7 +196,7 @@ EOF
192196

193197
cat >"$conf" <<EOF
194198
:Port: $port
195-
:DocumentRoot: "$fqgitdir/gitweb"
199+
:DocumentRoot: "$root"
196200
:DirectoryIndex: ["gitweb.cgi"]
197201
:PidFile: "$fqgitdir/pid"
198202
EOF
@@ -201,7 +205,7 @@ EOF
201205

202206
lighttpd_conf () {
203207
cat > "$conf" <<EOF
204-
server.document-root = "$fqgitdir/gitweb"
208+
server.document-root = "$root"
205209
server.port = $port
206210
server.modules = ( "mod_setenv", "mod_cgi" )
207211
server.indexfiles = ( "gitweb.cgi" )
@@ -212,7 +216,7 @@ server.errorlog = "$fqgitdir/gitweb/$httpd_only/error.log"
212216
# variable above and uncomment this
213217
#accesslog.filename = "$fqgitdir/gitweb/$httpd_only/access.log"
214218
215-
setenv.add-environment = ( "PATH" => env.PATH )
219+
setenv.add-environment = ( "PATH" => env.PATH, "GITWEB_CONFIG" => env.GITWEB_CONFIG )
216220
217221
cgi.assign = ( ".cgi" => "" )
218222
@@ -282,8 +286,8 @@ apache2_conf () {
282286
echo 'text/css css' > "$fqgitdir/mime.types"
283287
cat > "$conf" <<EOF
284288
ServerName "git-instaweb"
285-
ServerRoot "$fqgitdir/gitweb"
286-
DocumentRoot "$fqgitdir/gitweb"
289+
ServerRoot "$root"
290+
DocumentRoot "$root"
287291
ErrorLog "$fqgitdir/gitweb/$httpd_only/error.log"
288292
CustomLog "$fqgitdir/gitweb/$httpd_only/access.log" combined
289293
PidFile "$fqgitdir/pid"
@@ -304,13 +308,14 @@ EOF
304308
# check to see if Dennis Stosberg's mod_perl compatibility patch
305309
# (<[email protected]>) has been applied
306310
if test -f "$module_path/mod_perl.so" &&
307-
sane_grep 'MOD_PERL' "$GIT_DIR/gitweb/gitweb.cgi" >/dev/null
311+
sane_grep 'MOD_PERL' "$root/gitweb.cgi" >/dev/null
308312
then
309313
# favor mod_perl if available
310314
cat >> "$conf" <<EOF
311315
LoadModule perl_module $module_path/mod_perl.so
312316
PerlPassEnv GIT_DIR
313317
PerlPassEnv GIT_EXEC_DIR
318+
PerlPassEnv GITWEB_CONFIG
314319
<Location /gitweb.cgi>
315320
SetHandler perl-script
316321
PerlResponseHandler ModPerl::Registry
@@ -354,15 +359,15 @@ mongoose_conf() {
354359
# For detailed description of every option, visit
355360
# http://code.google.com/p/mongoose/wiki/MongooseManual
356361
357-
root $fqgitdir/gitweb
362+
root $root
358363
ports $port
359364
index_files gitweb.cgi
360365
#ssl_cert $fqgitdir/gitweb/ssl_cert.pem
361366
error_log $fqgitdir/gitweb/$httpd_only/error.log
362367
access_log $fqgitdir/gitweb/$httpd_only/access.log
363368
364369
#cgi setup
365-
cgi_env PATH=$PATH,GIT_DIR=$GIT_DIR,GIT_EXEC_PATH=$GIT_EXEC_PATH
370+
cgi_env PATH=$PATH,GIT_DIR=$GIT_DIR,GIT_EXEC_PATH=$GIT_EXEC_PATH,GITWEB_CONFIG=$GITWEB_CONFIG
366371
cgi_interp $PERL
367372
cgi_ext cgi,pl
368373
@@ -371,41 +376,16 @@ mime_types .gz=application/x-gzip,.tar.gz=application/x-tgz,.tgz=application/x-t
371376
EOF
372377
}
373378

374-
375-
script='
376-
s#^(my|our) \$projectroot =.*#$1 \$projectroot = "'$(dirname "$fqgitdir")'";#;
377-
s#(my|our) \$gitbin =.*#$1 \$gitbin = "'$GIT_EXEC_PATH'";#;
378-
s#(my|our) \$projects_list =.*#$1 \$projects_list = \$projectroot;#;
379-
s#(my|our) \$git_temp =.*#$1 \$git_temp = "'$fqgitdir/gitweb/tmp'";#;'
380-
381-
gitweb_cgi () {
382-
cat > "$1.tmp" <<\EOFGITWEB
383-
@@GITWEB_CGI@@
384-
EOFGITWEB
385-
# Use the configured full path to perl to match the generated
386-
# scripts' 'hashpling' line
387-
"$PERL" -p -e "$script" "$1.tmp" > "$1"
388-
chmod +x "$1"
389-
rm -f "$1.tmp"
390-
}
391-
392-
gitweb_css () {
393-
cat > "$1" <<\EOFGITWEB
394-
@@GITWEB_CSS@@
395-
396-
EOFGITWEB
397-
}
398-
399-
gitweb_js () {
400-
cat > "$1" <<\EOFGITWEB
401-
@@GITWEB_JS@@
402-
403-
EOFGITWEB
379+
gitweb_conf() {
380+
cat > "$fqgitdir/gitweb/gitweb_config.perl" <<EOF
381+
#!/usr/bin/perl
382+
our \$projectroot = "$(dirname "$fqgitdir")";
383+
our \$git_temp = "$fqgitdir/gitweb/tmp";
384+
our \$projects_list = \$projectroot;
385+
EOF
404386
}
405387

406-
gitweb_cgi "$GIT_DIR/gitweb/gitweb.cgi"
407-
gitweb_css "$GIT_DIR/@@GITWEB_CSS_NAME@@"
408-
gitweb_js "$GIT_DIR/@@GITWEB_JS_NAME@@"
388+
gitweb_conf
409389

410390
resolve_full_httpd
411391
mkdir -p "$fqgitdir/gitweb/$httpd_only"

0 commit comments

Comments
 (0)