allow perl modules as triggers also...

...and move "check_repo_write_enabled" to that mode ("writable")
This commit is contained in:
gitolite tester 2012-03-25 21:29:14 +05:30 committed by Sitaram Chamarty
parent 1cf062fad5
commit cc8b10483b
5 changed files with 64 additions and 16 deletions

View file

@ -11,7 +11,6 @@ package Gitolite::Conf::Load;
option option
repo_missing repo_missing
check_repo_write_enabled
creator creator
vrefs vrefs
@ -162,15 +161,6 @@ sub repo_missing {
return not -d "$rc{GL_REPO_BASE}/$repo.git"; return not -d "$rc{GL_REPO_BASE}/$repo.git";
} }
sub check_repo_write_enabled {
my ($repo) = shift;
for my $f ("$ENV{HOME}/.gitolite.down", "$rc{GL_REPO_BASE}/$repo.git/.gitolite.down") {
next unless -f $f;
_die slurp($f) if -s $f;
_die "sorry, writes are currently disabled (no more info available)";
}
}
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
sub load_common { sub load_common {

View file

@ -71,6 +71,9 @@ if ( defined($GL_ADMINDIR) ) {
# add internal triggers # add internal triggers
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
# is the server/repo in a writable state (i.e., not down for maintenance etc)
unshift @{ $rc{ACCESS_1} }, 'Writable::writable';
# (testing only) override the rc file silently # (testing only) override the rc file silently
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
# use an env var that is highly unlikely to appear in real life :) # use an env var that is highly unlikely to appear in real life :)
@ -174,13 +177,20 @@ sub trigger {
_die "$rc_section section in rc file is not a perl list"; _die "$rc_section section in rc file is not a perl list";
} else { } else {
for my $s ( @{ $rc{$rc_section} } ) { for my $s ( @{ $rc{$rc_section} } ) {
my ($pgm, @args) = split ' ', $s; my ($pgm, @args) = split ' ', $s;
$pgm = "$ENV{GL_BINDIR}/triggers/$pgm";
_warn("skipped command '$s'"), next if not -x $pgm; if ( my($module, $sub) = ($pgm =~ /^(.*)::(\w+)$/ ) ) {
trace( 2, "command: $s" );
_system( $pgm, @args, $rc_section, @_ ); # they better all return with 0 exit codes! require Gitolite::Triggers;
Gitolite::Triggers::run($module, $sub, @args, $rc_section, @_);
} else {
$pgm = "$ENV{GL_BINDIR}/triggers/$pgm";
_warn("skipped command '$s'"), next if not -x $pgm;
trace( 2, "command: $s" );
_system( $pgm, @args, $rc_section, @_ ); # they better all return with 0 exit codes!
}
} }
} }
return; return;

32
src/Gitolite/Triggers.pm Normal file
View file

@ -0,0 +1,32 @@
package Gitolite::Triggers;
# load and run triggered modules
# ----------------------------------------------------------------------
#<<<
@EXPORT = qw(
);
#>>>
use Exporter 'import';
use Gitolite::Rc;
use Gitolite::Common;
use strict;
use warnings;
# ----------------------------------------------------------------------
sub run {
my ($module, $sub, @args) = @_;
$module = "Gitolite::Triggers::$module" if $module !~ /^Gitolite::/;
eval "require $module";
my $subref;
eval "\$subref = \\\&$module" . "::" . "$sub";
_die "module '$module' does not exist or does not have sub '$sub'" unless ref($subref) eq 'CODE';
$subref->(@args);
}
1;

View file

@ -0,0 +1,17 @@
package Gitolite::Triggers::Writable;
use Gitolite::Rc;
use Gitolite::Common;
sub writable {
my ($repo, $aa, $result) = @_[1, 3, 5];
return if $aa eq 'R' or $result =~ /DENIED/;
for my $f ("$ENV{HOME}/.gitolite.down", "$rc{GL_REPO_BASE}/$repo.git/.gitolite.down") {
next unless -f $f;
_die slurp($f) if -s $f;
_die "sorry, writes are currently disabled (no more info available)\n";
}
}
1;

View file

@ -94,7 +94,6 @@ sub main {
trigger( 'ACCESS_1', $repo, $user, $aa, 'any', $ret ); trigger( 'ACCESS_1', $repo, $user, $aa, 'any', $ret );
_die $ret . "\n(or you mis-spelled the reponame)" if $ret =~ /DENIED/; _die $ret . "\n(or you mis-spelled the reponame)" if $ret =~ /DENIED/;
check_repo_write_enabled($repo) if $aa eq 'W';
trigger( 'PRE_GIT', $repo, $user, $aa, 'any', $verb ); trigger( 'PRE_GIT', $repo, $user, $aa, 'any', $verb );
my $repodir = "'$rc{GL_REPO_BASE}/$repo.git'"; my $repodir = "'$rc{GL_REPO_BASE}/$repo.git'";
_system( "git", "shell", "-c", "$verb $repodir" ); _system( "git", "shell", "-c", "$verb $repodir" );