(perltidy)
This commit is contained in:
parent
2cb7d8313e
commit
1c15b4cc2d
|
@ -3,6 +3,7 @@ use strict;
|
|||
use warnings;
|
||||
|
||||
my $tid;
|
||||
|
||||
BEGIN {
|
||||
$tid = $ENV{GL_TID} || 0;
|
||||
delete $ENV{GL_TID};
|
||||
|
@ -33,15 +34,15 @@ usage() if not @ARGV or $ARGV[0] eq '-h';
|
|||
|
||||
_die "HOSTNAME not set" if not $rc{HOSTNAME};
|
||||
|
||||
my ($cmd, $host, $repo) = @ARGV;
|
||||
my ( $cmd, $host, $repo ) = @ARGV;
|
||||
usage() if not $repo;
|
||||
|
||||
if ($cmd eq 'push') {
|
||||
valid_slave($host, $repo) if exists $ENV{GL_USER};
|
||||
if ( $cmd eq 'push' ) {
|
||||
valid_slave( $host, $repo ) if exists $ENV{GL_USER};
|
||||
# will die if host not in slaves for repo
|
||||
|
||||
trace(1, "TID=$tid host=$host repo=$repo", "gitolite mirror push started");
|
||||
_chdir($rc{GL_REPO_BASE});
|
||||
trace( 1, "TID=$tid host=$host repo=$repo", "gitolite mirror push started" );
|
||||
_chdir( $rc{GL_REPO_BASE} );
|
||||
_chdir("$repo.git");
|
||||
|
||||
my $errors = 0;
|
||||
|
@ -50,19 +51,19 @@ if ($cmd eq 'push') {
|
|||
chomp;
|
||||
if (/FATAL/) {
|
||||
$errors++;
|
||||
gl_log('mirror', $_);
|
||||
gl_log( 'mirror', $_ );
|
||||
} else {
|
||||
trace(1, "mirror: $_");
|
||||
trace( 1, "mirror: $_" );
|
||||
}
|
||||
}
|
||||
exit $errors;
|
||||
}
|
||||
|
||||
sub valid_slave {
|
||||
my ($host, $repo) = @_;
|
||||
my ( $host, $repo ) = @_;
|
||||
_die "invalid repo '$repo'" unless $repo =~ $REPONAME_PATT;
|
||||
|
||||
my $ref = git_config($repo, "^gitolite-options\\.mirror\\.slaves.*");
|
||||
my $ref = git_config( $repo, "^gitolite-options\\.mirror\\.slaves.*" );
|
||||
my %list = map { $_ => 1 } map { split } values %$ref;
|
||||
|
||||
_die "'$host' not a valid slave for '$repo'" unless $list{$host};
|
||||
|
|
|
@ -72,7 +72,7 @@ sub in_ssh {
|
|||
my $ip;
|
||||
( $ip = $ENV{SSH_CONNECTION} || '(no-IP)' ) =~ s/ .*//;
|
||||
|
||||
gl_log( 'ssh', "ARGV=" . join( ",", @ARGV ), "SOC=" . ( $ENV{SSH_ORIGINAL_COMMAND} || ''), "FROM=$ip" );
|
||||
gl_log( 'ssh', "ARGV=" . join( ",", @ARGV ), "SOC=" . ( $ENV{SSH_ORIGINAL_COMMAND} || '' ), "FROM=$ip" );
|
||||
|
||||
$ENV{SSH_ORIGINAL_COMMAND} ||= '';
|
||||
my $soc = $ENV{SSH_ORIGINAL_COMMAND};
|
||||
|
@ -172,24 +172,24 @@ sub sanity {
|
|||
sub http_setup_die_handler {
|
||||
|
||||
$SIG{__DIE__} = sub {
|
||||
my $service = ($ENV{SSH_ORIGINAL_COMMAND} =~ /git-receive-pack/ ? 'git-receive-pack' : 'git-upload-pack');
|
||||
my $service = ( $ENV{SSH_ORIGINAL_COMMAND} =~ /git-receive-pack/ ? 'git-receive-pack' : 'git-upload-pack' );
|
||||
my $message = shift; chomp($message);
|
||||
print STDERR "$message\n";
|
||||
|
||||
# format the service response, then the message. With initial
|
||||
# help from Ilari and then a more detailed email from Shawn...
|
||||
$service = "# service=$service\n"; $message = "ERR $message\n";
|
||||
$service = sprintf("%04X", length($service)+4) . "$service"; # no CRLF on this one
|
||||
$message = sprintf("%04X", length($message)+4) . "$message";
|
||||
$service = sprintf( "%04X", length($service) + 4 ) . "$service"; # no CRLF on this one
|
||||
$message = sprintf( "%04X", length($message) + 4 ) . "$message";
|
||||
|
||||
http_print_headers();
|
||||
print $service;
|
||||
print "0000"; # flush-pkt, apparently
|
||||
print "0000"; # flush-pkt, apparently
|
||||
print $message;
|
||||
print STDERR $service;
|
||||
print STDERR $message;
|
||||
exit 0; # if it's ok for die_webcgi in git.git/http-backend.c, it's ok for me ;-)
|
||||
}
|
||||
exit 0; # if it's ok for die_webcgi in git.git/http-backend.c, it's ok for me ;-)
|
||||
}
|
||||
}
|
||||
|
||||
sub http_simulate_ssh_connection {
|
||||
|
@ -197,26 +197,27 @@ sub http_simulate_ssh_connection {
|
|||
# http-backend.c for how I got that. Also note that "info" is overloaded;
|
||||
# git uses "info/refs...", while gitolite uses "info" or "info?...". So
|
||||
# there's a "/" after info in the list below
|
||||
if ($ENV{PATH_INFO} =~ m(^/(.*)/(HEAD$|info/refs$|objects/|git-(?:upload|receive)-pack$))) {
|
||||
if ( $ENV{PATH_INFO} =~ m(^/(.*)/(HEAD$|info/refs$|objects/|git-(?:upload|receive)-pack$)) ) {
|
||||
my $repo = $1;
|
||||
my $verb = ($ENV{REQUEST_URI} =~ /git-receive-pack/) ? 'git-receive-pack' : 'git-upload-pack';
|
||||
my $verb = ( $ENV{REQUEST_URI} =~ /git-receive-pack/ ) ? 'git-receive-pack' : 'git-upload-pack';
|
||||
$ENV{SSH_ORIGINAL_COMMAND} = "$verb '$repo'";
|
||||
} else {
|
||||
# this is one of our custom commands; could be anything really,
|
||||
# because of the adc feature
|
||||
my ($verb) = ($ENV{PATH_INFO} =~ m(^/(\S+)));
|
||||
my ($verb) = ( $ENV{PATH_INFO} =~ m(^/(\S+)) );
|
||||
my $args = $ENV{QUERY_STRING};
|
||||
$args =~ s/\+/ /g;
|
||||
$ENV{SSH_ORIGINAL_COMMAND} = $verb;
|
||||
$ENV{SSH_ORIGINAL_COMMAND} .= " $args" if $args;
|
||||
http_print_headers(); # in preparation for the eventual output!
|
||||
http_print_headers(); # in preparation for the eventual output!
|
||||
}
|
||||
$ENV{SSH_CONNECTION} = "$ENV{REMOTE_ADDR} $ENV{REMOTE_PORT} $ENV{SERVER_ADDR} $ENV{SERVER_PORT}";
|
||||
}
|
||||
|
||||
my $http_headers_printed = 0;
|
||||
|
||||
sub http_print_headers {
|
||||
my($code, $text) = @_;
|
||||
my ( $code, $text ) = @_;
|
||||
|
||||
return if $http_headers_printed++;
|
||||
$code ||= 200;
|
||||
|
|
|
@ -392,12 +392,12 @@ sub creator {
|
|||
|
||||
sub ext_grouplist {
|
||||
my $user = shift;
|
||||
my $pgm = $rc{GROUPLIST_PGM};
|
||||
my $pgm = $rc{GROUPLIST_PGM};
|
||||
return [] if not $pgm;
|
||||
|
||||
return $cache{$user} if $cache{$user};
|
||||
my @extgroups = map { s/^@?/@/; $_; } split ' ', `$rc{GROUPLIST_PGM} $user`;
|
||||
return ($cache{$user} = \@extgroups);
|
||||
return ( $cache{$user} = \@extgroups );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ sub update {
|
|||
sub bypass {
|
||||
require Cwd;
|
||||
Cwd->import;
|
||||
gl_log( 'update', getcwd(), '(' . ($ENV{USER} || '?') . ')', 'bypass', @ARGV );
|
||||
gl_log( 'update', getcwd(), '(' . ( $ENV{USER} || '?' ) . ')', 'bypass', @ARGV );
|
||||
exit 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -32,11 +32,11 @@ our %rc;
|
|||
# pre-populate some important rc keys
|
||||
# ----------------------------------------------------------------------
|
||||
|
||||
$rc{GL_BINDIR} = $ENV{GL_BINDIR};
|
||||
$rc{GL_LIBDIR} = $ENV{GL_LIBDIR};
|
||||
$rc{GL_BINDIR} = $ENV{GL_BINDIR};
|
||||
$rc{GL_LIBDIR} = $ENV{GL_LIBDIR};
|
||||
|
||||
# these keys could be overridden by the rc file later
|
||||
$rc{GL_REPO_BASE} = "$ENV{HOME}/repositories";
|
||||
$rc{GL_REPO_BASE} = "$ENV{HOME}/repositories";
|
||||
$rc{GL_ADMIN_BASE} = "$ENV{HOME}/.gitolite";
|
||||
$rc{LOG_TEMPLATE} = "$ENV{HOME}/.gitolite/logs/gitolite-%y-%m.log";
|
||||
|
||||
|
@ -183,7 +183,7 @@ sub trigger {
|
|||
if ( my ( $module, $sub ) = ( $pgm =~ /^(.*)::(\w+)$/ ) ) {
|
||||
|
||||
require Gitolite::Triggers;
|
||||
trace(1, 'trigger', $module, $sub, @args, $rc_section, @_ );
|
||||
trace( 1, 'trigger', $module, $sub, @args, $rc_section, @_ );
|
||||
Gitolite::Triggers::run( $module, $sub, @args, $rc_section, @_ );
|
||||
|
||||
} else {
|
||||
|
|
|
@ -8,7 +8,7 @@ use strict;
|
|||
use warnings;
|
||||
|
||||
my $git_commands = "git-upload-pack|git-receive-pack|git-upload-archive";
|
||||
my $hn = $rc{HOSTNAME};
|
||||
my $hn = $rc{HOSTNAME};
|
||||
|
||||
# ----------------------------------------------------------------------
|
||||
|
||||
|
@ -17,14 +17,14 @@ sub input {
|
|||
|
||||
# note: we treat %rc as our own internal "poor man's %ENV"
|
||||
$rc{FROM_SERVER} = $1;
|
||||
trace(3, "from_server: $1");
|
||||
trace( 3, "from_server: $1" );
|
||||
|
||||
if ( $ENV{SSH_ORIGINAL_COMMAND} =~ /^USER=(\S+) SOC=(git-receive-pack '(\S+)')$/ ) {
|
||||
# my ($user, $newsoc, $repo) = ($1, $2, $3);
|
||||
$ENV{SSH_ORIGINAL_COMMAND} = $2;
|
||||
@ARGV = ($1);
|
||||
$rc{REDIRECTED_PUSH} = 1;
|
||||
trace(3, "redirected_push for user $1");
|
||||
@ARGV = ($1);
|
||||
$rc{REDIRECTED_PUSH} = 1;
|
||||
trace( 3, "redirected_push for user $1" );
|
||||
} else {
|
||||
# master -> slave push, no access checks needed
|
||||
$ENV{GL_BYPASS_ACCESS_CHECKS} = 1;
|
||||
|
@ -33,14 +33,14 @@ sub input {
|
|||
|
||||
# ----------------------------------------------------------------------
|
||||
|
||||
my ($mode, $master, %slaves, %trusted_slaves);
|
||||
my ( $mode, $master, %slaves, %trusted_slaves );
|
||||
|
||||
sub pre_git {
|
||||
return unless $hn;
|
||||
# nothing, and I mean NOTHING, happens if HOSTNAME is not set
|
||||
trace(1, "pre_git() on $hn");
|
||||
trace( 1, "pre_git() on $hn" );
|
||||
|
||||
my ($repo, $user, $aa) = @_[1, 2, 3];
|
||||
my ( $repo, $user, $aa ) = @_[ 1, 2, 3 ];
|
||||
|
||||
my $sender = $rc{FROM_SERVER} || '';
|
||||
$user = '' if $sender and not exists $rc{REDIRECTED_PUSH};
|
||||
|
@ -55,18 +55,17 @@ sub pre_git {
|
|||
# exclude this host from both the master and slave lists)
|
||||
return if $aa eq 'R';
|
||||
|
||||
trace(1, "mirror", "pre_git", $repo, "user=$user", "sender=$sender", "mode=$mode",
|
||||
($rc{REDIRECTED_PUSH} ? ("redirected") : ()));
|
||||
trace( 1, "mirror", "pre_git", $repo, "user=$user", "sender=$sender", "mode=$mode", ( $rc{REDIRECTED_PUSH} ? ("redirected") : () ) );
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# case 1: we're master or slave, normal user pushing to us
|
||||
if ($user and not $rc{REDIRECTED_PUSH}) {
|
||||
trace(3, "case 1, user push");
|
||||
if ( $user and not $rc{REDIRECTED_PUSH} ) {
|
||||
trace( 3, "case 1, user push" );
|
||||
return if $mode eq 'local' or $mode eq 'master';
|
||||
if ($trusted_slaves{$hn}) {
|
||||
trace(3, "redirecting to $master");
|
||||
trace(1, "redirect to $master");
|
||||
exec("ssh", $master, "USER=$user", "SOC=$ENV{SSH_ORIGINAL_COMMAND}");
|
||||
if ( $trusted_slaves{$hn} ) {
|
||||
trace( 3, "redirecting to $master" );
|
||||
trace( 1, "redirect to $master" );
|
||||
exec( "ssh", $master, "USER=$user", "SOC=$ENV{SSH_ORIGINAL_COMMAND}" );
|
||||
} else {
|
||||
_die "$hn: pushing '$repo' to slave '$hn' not allowed";
|
||||
}
|
||||
|
@ -74,9 +73,9 @@ sub pre_git {
|
|||
|
||||
# ------------------------------------------------------------------
|
||||
# case 2: we're slave, master pushing to us
|
||||
if ($sender and not $rc{REDIRECTED_PUSH}) {
|
||||
trace(3, "case 2, master push");
|
||||
_die "$hn: '$repo' is local" if $mode eq 'local';
|
||||
if ( $sender and not $rc{REDIRECTED_PUSH} ) {
|
||||
trace( 3, "case 2, master push" );
|
||||
_die "$hn: '$repo' is local" if $mode eq 'local';
|
||||
_die "$hn: '$repo' is native" if $mode eq 'master';
|
||||
_die "$hn: '$sender' is not the master for '$repo'" if $master ne $sender;
|
||||
return;
|
||||
|
@ -84,12 +83,12 @@ sub pre_git {
|
|||
|
||||
# ------------------------------------------------------------------
|
||||
# case 3: we're master, slave sending a redirected push to us
|
||||
if ($sender and $rc{REDIRECTED_PUSH}) {
|
||||
trace(3, "case 2, slave redirect");
|
||||
_die "$hn: '$repo' is local" if $mode eq 'local';
|
||||
if ( $sender and $rc{REDIRECTED_PUSH} ) {
|
||||
trace( 3, "case 2, slave redirect" );
|
||||
_die "$hn: '$repo' is local" if $mode eq 'local';
|
||||
_die "$hn: '$repo' is not native" if $mode eq 'slave';
|
||||
_die "$hn: '$sender' is not a valid slave for '$repo'" if not $slaves{$sender};
|
||||
_die "$hn: redirection not allowed from '$sender'" if not $trusted_slaves{$sender};
|
||||
_die "$hn: redirection not allowed from '$sender'" if not $trusted_slaves{$sender};
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -102,9 +101,9 @@ sub pre_git {
|
|||
sub post_git {
|
||||
return unless $hn;
|
||||
# nothing, and I mean NOTHING, happens if HOSTNAME is not set
|
||||
trace(1, "post_git() on $hn");
|
||||
trace( 1, "post_git() on $hn" );
|
||||
|
||||
my ($repo, $user, $aa) = @_[1, 2, 3];
|
||||
my ( $repo, $user, $aa ) = @_[ 1, 2, 3 ];
|
||||
# we don't deal with any reads
|
||||
return if $aa eq 'R';
|
||||
|
||||
|
@ -115,13 +114,12 @@ sub post_git {
|
|||
# now you know the repo, get its mirroring details
|
||||
details($repo);
|
||||
|
||||
trace(1, "mirror", "post_git", $repo, "user=$user", "sender=$sender", "mode=$mode",
|
||||
($rc{REDIRECTED_PUSH} ? ("redirected") : ()));
|
||||
trace( 1, "mirror", "post_git", $repo, "user=$user", "sender=$sender", "mode=$mode", ( $rc{REDIRECTED_PUSH} ? ("redirected") : () ) );
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# case 1: we're master or slave, normal user pushing to us
|
||||
if ($user and not $rc{REDIRECTED_PUSH}) {
|
||||
trace(3, "case 1, user push");
|
||||
if ( $user and not $rc{REDIRECTED_PUSH} ) {
|
||||
trace( 3, "case 1, user push" );
|
||||
return if $mode eq 'local';
|
||||
# slave was eliminated earlier anyway, so that leaves 'master'
|
||||
|
||||
|
@ -133,16 +131,16 @@ sub post_git {
|
|||
|
||||
# ------------------------------------------------------------------
|
||||
# case 2: we're slave, master pushing to us
|
||||
if ($sender and not $rc{REDIRECTED_PUSH}) {
|
||||
trace(3, "case 2, master push");
|
||||
if ( $sender and not $rc{REDIRECTED_PUSH} ) {
|
||||
trace( 3, "case 2, master push" );
|
||||
# nothing to do
|
||||
return;
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# case 3: we're master, slave sending a redirected push to us
|
||||
if ($sender and $rc{REDIRECTED_PUSH}) {
|
||||
trace(3, "case 2, slave redirect");
|
||||
if ( $sender and $rc{REDIRECTED_PUSH} ) {
|
||||
trace( 3, "case 2, slave redirect" );
|
||||
|
||||
# find all slaves and push to each of them
|
||||
push_to_slaves($repo);
|
||||
|
@ -158,40 +156,40 @@ sub post_git {
|
|||
my $repo = shift;
|
||||
return if $lastrepo eq $repo;
|
||||
|
||||
$master = master($repo);
|
||||
%slaves = slaves($repo);
|
||||
$mode = mode($repo);
|
||||
$master = master($repo);
|
||||
%slaves = slaves($repo);
|
||||
$mode = mode($repo);
|
||||
%trusted_slaves = trusted_slaves($repo);
|
||||
trace(3, $master, $mode, join(",", sort keys %slaves), join(",", sort keys %trusted_slaves) );
|
||||
trace( 3, $master, $mode, join( ",", sort keys %slaves ), join( ",", sort keys %trusted_slaves ) );
|
||||
}
|
||||
|
||||
sub master {
|
||||
return option(+shift, 'mirror.master');
|
||||
return option( +shift, 'mirror.master' );
|
||||
}
|
||||
|
||||
sub slaves {
|
||||
my $ref = git_config(+shift, "^gitolite-options\\.mirror\\.slaves.*");
|
||||
my $ref = git_config( +shift, "^gitolite-options\\.mirror\\.slaves.*" );
|
||||
my %out = map { $_ => 1 } map { split } values %$ref;
|
||||
return %out;
|
||||
}
|
||||
|
||||
sub trusted_slaves {
|
||||
my $ref = git_config(+shift, "^gitolite-options\\.mirror\\.redirectOK.*");
|
||||
my $ref = git_config( +shift, "^gitolite-options\\.mirror\\.redirectOK.*" );
|
||||
# the list of trusted slaves (where we accept redirected pushes from)
|
||||
# is either explicitly given...
|
||||
my @out = map { split } values %$ref;
|
||||
my %out = map { $_ => 1 } @out;
|
||||
# ...or it's all the slaves mentioned if the list is just a "all"
|
||||
%out = %slaves if (@out == 1 and $out[0] eq 'all');
|
||||
%out = %slaves if ( @out == 1 and $out[0] eq 'all' );
|
||||
return %out;
|
||||
}
|
||||
|
||||
sub mode {
|
||||
my $repo = shift;
|
||||
return 'local' if not $hn;
|
||||
return 'local' if not $hn;
|
||||
return 'master' if $master eq $hn;
|
||||
return 'slave' if $slaves{$hn};
|
||||
return 'local' if not $master and not %slaves;
|
||||
return 'slave' if $slaves{$hn};
|
||||
return 'local' if not $master and not %slaves;
|
||||
_die "$hn: '$repo' is mirrored but not here";
|
||||
}
|
||||
}
|
||||
|
@ -200,9 +198,9 @@ sub push_to_slaves {
|
|||
my $repo = shift;
|
||||
|
||||
my $u = $ENV{GL_USER};
|
||||
delete $ENV{GL_USER}; # why? see src/commands/mirror
|
||||
delete $ENV{GL_USER}; # why? see src/commands/mirror
|
||||
|
||||
for my $s (sort keys %slaves) {
|
||||
for my $s ( sort keys %slaves ) {
|
||||
system("gitolite mirror push $s $repo &");
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue