From b1a75b78892461686d1e44c43567e13be7c4f165 Mon Sep 17 00:00:00 2001 From: Sitaram Chamarty Date: Mon, 19 Mar 2012 14:04:17 +0530 Subject: [PATCH] gitweb/daemon post-create scripts done --- src/Gitolite/Rc.pm | 10 +++ .../update-git-daemon-access-list | 40 +++++++++ .../post-compile/update-gitweb-access-list | 11 +++ t/all-yall.t | 89 +++++++++++++++++++ 4 files changed, 150 insertions(+) create mode 100755 src/commands/post-compile/update-git-daemon-access-list create mode 100755 src/commands/post-compile/update-gitweb-access-list create mode 100755 t/all-yall.t diff --git a/src/Gitolite/Rc.pm b/src/Gitolite/Rc.pm index ff87e1d..5050852 100644 --- a/src/Gitolite/Rc.pm +++ b/src/Gitolite/Rc.pm @@ -246,6 +246,16 @@ __DATA__ POST_COMPILE => [ 'post-compile/ssh-authkeys', + 'post-compile/update-gitweb-access-list', + 'post-compile/update-git-daemon-access-list', + ], + + # comment out or uncomment as needed + # these will run in sequence after a new wild repo is created + POST_CREATE => + [ + # 'post-compile/update-gitweb-access-list', + # 'post-compile/update-git-daemon-access-list', ], # comment out or uncomment as needed diff --git a/src/commands/post-compile/update-git-daemon-access-list b/src/commands/post-compile/update-git-daemon-access-list new file mode 100755 index 0000000..feb4a37 --- /dev/null +++ b/src/commands/post-compile/update-git-daemon-access-list @@ -0,0 +1,40 @@ +#!/bin/sh + +# this is probably the *fastest* git-daemon update possible. + +export EO=git-daemon-export-ok +export RB=$(gitolite query-rc GL_REPO_BASE) + +gitolite list-phy-repos | gitolite access % daemon R any | + perl -lane ' + unlink "$ENV{RB}/$F[0].git/$ENV{EO}" if /DENIED/; + print $F[0] unless /DENIED/ + ' | + while read r + do + > $RB/$r.git/$EO + done + +# A bit of explanation may be in order. The gitolite output looks somewhat +# like this: + +# bar^Idaemon^IR any bar daemon DENIED by fallthru$ +# foo^Idaemon^Irefs/.*$ +# fubar^Idaemon^Irefs/.*$ +# gitolite-admin^Idaemon^IR any gitolite-admin daemon DENIED by fallthru$ +# testing^Idaemon^Irefs/.*$ + +# where I've type "^I" to denote a tab. + +# Shell has to fork 'rm' to delete a file but perl doesn't. So removing the +# export-ok file from repos where needed is done in perl. + +# On the other hand, perls requires a bit more *code* to even create an empty +# file. Shell can do it with just "> file", and it doesn't fork for this. So +# that part is handled in shell. + +# You'll also see that the perl part is taking what it needs from the input +# and passing the rest on, so the shell part doesn't have to do any grepping, +# which would be a horrible slowdown. + +# $F and the rest is the magic of perl's flags (man perlrun). diff --git a/src/commands/post-compile/update-gitweb-access-list b/src/commands/post-compile/update-gitweb-access-list new file mode 100755 index 0000000..971100e --- /dev/null +++ b/src/commands/post-compile/update-gitweb-access-list @@ -0,0 +1,11 @@ +#!/bin/sh + +# this is literally the simplest gitweb update possible. You are free to add +# whatever you want and contribute it back, as long as it is upward +# compatible. + +plf=$(gitolite query-rc GITWEB_PROJECTS_LIST) +[ -z "$plf" ] && plf=$HOME/projects.list + +gitolite list-phy-repos | gitolite access % gitweb R any | grep -v DENIED | cut -f1 | sed -e 's/$/.git/' > $plf + diff --git a/t/all-yall.t b/t/all-yall.t new file mode 100755 index 0000000..7174e4b --- /dev/null +++ b/t/all-yall.t @@ -0,0 +1,89 @@ +#!/usr/bin/perl +use strict; +use warnings; + +# this is hardcoded; change it if needed +use lib "src"; +use Gitolite::Test; + +# basic tests +# ---------------------------------------------------------------------- + +try "plan 26"; + +confreset;confadd ' + repo @all + R = @all + repo foo + RW+ = u1 + repo bar + RW+ = u2 + repo dev/..* + C = u3 u4 + RW+ = CREATOR +'; + +try " + rm $ENV{HOME}/projects.list +"; +try "ADMIN_PUSH set1; !/FATAL/" or die text(); + +try " + glt ls-remote u1 file:///dev/wild1 + /FATAL: R any dev/wild1 u1 DENIED by fallthru/ + + glt clone u3 file:///dev/wild1 + /Cloning into 'wild1'.../ + /Initialized empty Git repository in .*/dev/wild1.git// + /warning: You appear to have cloned an empty repository./ + + cd wild1 + tc n-855 n-856 + glt push u3 origin master:wild1 + /To file:///dev/wild1/ + /\\* \\[new branch\\] master -> wild1/ + glt push u1 file:///foo master:br-foo + /To file:///foo/ + /\\* \\[new branch\\] master -> br-foo/ + glt push u2 file:///bar master:br-bar + /To file:///bar/ + /\\* \\[new branch\\] master -> br-bar/ + + glt ls-remote u6 file:///foo + /refs/heads/br-foo/ + + glt ls-remote u6 file:///bar + /refs/heads/br-bar/ + + glt ls-remote u6 file:///dev/wild1 + /refs/heads/wild1/ +"; + +try " + gitolite post-compile/update-git-daemon-access-list; ok + gitolite post-compile/update-gitweb-access-list; ok + cat $ENV{HOME}/projects.list; ok +"; +cmp 'bar.git +dev/wild1.git +foo.git +gitolite-admin.git +testing.git +'; + +my $rb = `gitolite query-rc -n GL_REPO_BASE`; + +try " + cd .. + cd .. + echo $rb + find $rb -name git-daemon-export-ok | sort + perl s,$rb/,,g +"; + +cmp 'bar.git/git-daemon-export-ok +dev/wild1.git/git-daemon-export-ok +foo.git/git-daemon-export-ok +gitolite-admin.git/git-daemon-export-ok +testing.git/git-daemon-export-ok +';