allow perl modules as triggers also...
...and move "check_repo_write_enabled" to that mode ("writable")
This commit is contained in:
parent
1cf062fad5
commit
cc8b10483b
|
@ -11,7 +11,6 @@ package Gitolite::Conf::Load;
|
|||
|
||||
option
|
||||
repo_missing
|
||||
check_repo_write_enabled
|
||||
creator
|
||||
|
||||
vrefs
|
||||
|
@ -162,15 +161,6 @@ sub repo_missing {
|
|||
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 {
|
||||
|
|
|
@ -71,6 +71,9 @@ if ( defined($GL_ADMINDIR) ) {
|
|||
# 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
|
||||
# ----------------------------------------------------------------------
|
||||
# use an env var that is highly unlikely to appear in real life :)
|
||||
|
@ -174,8 +177,14 @@ sub trigger {
|
|||
_die "$rc_section section in rc file is not a perl list";
|
||||
} else {
|
||||
for my $s ( @{ $rc{$rc_section} } ) {
|
||||
|
||||
my ($pgm, @args) = split ' ', $s;
|
||||
|
||||
if ( my($module, $sub) = ($pgm =~ /^(.*)::(\w+)$/ ) ) {
|
||||
|
||||
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;
|
||||
|
@ -183,6 +192,7 @@ sub trigger {
|
|||
_system( $pgm, @args, $rc_section, @_ ); # they better all return with 0 exit codes!
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
trace( 2, "'$rc_section' not found in rc" );
|
||||
|
|
32
src/Gitolite/Triggers.pm
Normal file
32
src/Gitolite/Triggers.pm
Normal 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;
|
17
src/Gitolite/Triggers/Writable.pm
Normal file
17
src/Gitolite/Triggers/Writable.pm
Normal 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;
|
|
@ -94,7 +94,6 @@ sub main {
|
|||
trigger( 'ACCESS_1', $repo, $user, $aa, 'any', $ret );
|
||||
_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 );
|
||||
my $repodir = "'$rc{GL_REPO_BASE}/$repo.git'";
|
||||
_system( "git", "shell", "-c", "$verb $repodir" );
|
||||
|
|
Loading…
Reference in a new issue