Sitaram Chamarty 2012-11-16 13:24:55 +05:30
parent b9bbb78278
commit b0298618a3
5 changed files with 70 additions and 1 deletions

View File

@ -51,6 +51,9 @@ if ( $cmd eq 'push' ) {
trace(1, `cat gl-perms 2>/dev/null | ssh $host CREATOR=$creator perms -c \\'$repo\\'`);
}
my ($ns, $rr) = repo_namespace($repo);
trace(1, "'$repo' is a namespace in '$rr', skipping push"), exit 0 if $rr;
my $errors = 0;
for (`git push --mirror $host:$repo 2>&1`) {
$errors = 1 if $?;

View File

@ -128,7 +128,7 @@ sub main {
if ($ENV{REQUEST_URI}) {
_system( "git", "http-backend" );
} else {
my $repodir = "'$rc{GL_REPO_BASE}/$repo.git'";
my $repodir = "'$rc{GL_REPO_BASE}/" . ( $rc{REALREPO} || $repo ) . ".git'";
_system( "git", "shell", "-c", "$verb $repodir" );
}
trigger( 'POST_GIT', $repo, $user, $aa, 'any', $verb );

View File

@ -11,6 +11,7 @@ package Gitolite::Conf::Load;
option
repo_missing
repo_namespace
creator
vrefs
@ -203,6 +204,37 @@ sub repo_missing {
return not -d "$rc{GL_REPO_BASE}/$repo.git";
}
sub repo_namespace {
my $repo = shift;
sanity($repo);
my $ref = git_config( $repo, "^gitolite-options\\.namespace\\.pattern.*" );
return () if not %$ref; # no namespace options provided
for my $k (sort keys %$ref) {
my $v = $ref->{$k} || '';
_die "bad namespace option value '$v'" if not $v =~ /^(\S+) is (\S+) in (\S+)$/;
my ($p, $ns, $rr) = ($1, $2, $3);
# interpret $p and match $repo against it
$p =~ s(\*)((.*))g;
$p =~ s(%)(([^/]*))g;
$p = "^$p\$";
my @matches;
next unless @matches = ($repo =~ qr($p));
$ns =~ s(@(\d+))($matches[$1-1] or _die "bad namespace option-value '$v'")ge;
$rr =~ s(@(\d+))($matches[$1-1] or _die "bad namespace option-value '$v'")ge;
# check if namespace processing was explicitly disabled
return () if $rr eq $repo;
return ($ns, $rr);
}
_die "no namespace options matched for '$repo'";
}
# ----------------------------------------------------------------------
sub load_common {

View File

@ -146,6 +146,7 @@ sub post_git {
# slave was eliminated earlier anyway, so that leaves 'master'
# find all slaves and push to each of them
push_to_slaves( $rc{REALREPO} ) if $rc{REALREPO};
push_to_slaves($repo);
return;
@ -165,6 +166,7 @@ sub post_git {
trace( 3, "case 2, slave redirect" );
# find all slaves and push to each of them
push_to_slaves( $rc{REALREPO} ) if $rc{REALREPO};
push_to_slaves($repo);
return;

View File

@ -0,0 +1,32 @@
package Gitolite::Triggers::Namespaces;
use Gitolite::Rc;
use Gitolite::Common;
use Gitolite::Conf::Load;
use strict;
use warnings;
# allow the server to use namespaces without the users needing to know
# ----------------------------------------------------------------------
# see http://sitaramc.github.com/gitolite/namespaces.html for instructions and
# important warnings
sub pre_git {
my $repo = $_[1];
my ($ns, $rr) = repo_namespace($repo);
return if not $ns;
$ENV{GIT_NAMESPACE} = $ns;
$rc{REALREPO} = $rr;
trace( 1, "GIT_NAMESPACE = $ns, REALREPO = $rr");
}
sub post_git {
delete $ENV{GIT_NAMESPACE};
}
1;