auto-create repo on 'C' perm done

This commit is contained in:
Sitaram Chamarty 2012-03-17 07:00:17 +05:30
parent a014d2ffd5
commit 89a1857d56
3 changed files with 47 additions and 19 deletions

View file

@ -7,6 +7,7 @@ package Gitolite::Conf::Load;
load
access
git_config
repo_missing
vrefs
lister_dispatch
);
@ -105,13 +106,13 @@ sub git_config {
# sort this list of listrefs by the first element in each list ref'd to
sort { $a->[0] <=> $b->[0] }
# dereference it (into a list of listrefs)
map { @$_ }
map { @$_ }
# take the value of that entry
map { $configs{$_} }
# if it has an entry in %configs
grep { $configs{$_} }
# for each "repo" that represents us
memberships('repo', $repo);
memberships( 'repo', $repo );
# %configs looks like this (for each 'foo' that is in memberships())
# 'foo' => [ [ 6, 'foo.bar', 'repo' ], [ 7, 'foodbar', 'repoD' ], [ 8, 'foo.czar', 'jule' ] ],
@ -128,6 +129,11 @@ sub git_config {
return \%ret;
}
sub repo_missing {
my $repo = shift;
return not -d "$rc{GL_REPO_BASE}/$repo.git";
}
# ----------------------------------------------------------------------
sub load_common {
@ -158,6 +164,10 @@ sub load_1 {
return if $repo =~ /^\@/;
trace( 3, $repo );
if ( repo_missing($repo) ) {
trace( 3, "repo '$repo' missing" );
return;
}
_chdir("$rc{GL_REPO_BASE}/$repo.git");
if ( $repo eq $last_repo ) {
@ -193,8 +203,8 @@ sub load_1 {
my @rules = ();
my @repos = memberships('repo', $repo);
my @users = memberships('user', $user);
my @repos = memberships( 'repo', $repo );
my @users = memberships( 'user', $user );
trace( 3, "memberships: " . scalar(@repos) . " repos and " . scalar(@users) . " users found" );
for my $r (@repos) {
@ -224,36 +234,35 @@ sub load_1 {
}
sub memberships {
my $type = shift;
my $item = shift;
my $type = shift;
my $item = shift;
my $item2 = '';
my @ret = ( $item, '@all' );
if ($type eq 'repo') {
if ( $type eq 'repo' ) {
my $f = "$rc{GL_REPO_BASE}/$item.git/gl-creator";
if (-f $f) {
if ( -f $f ) {
my $creator;
chomp($creator = slurp($f));
($item2 = $item) =~ s(/$creator/)(/CREATOR/);
$item2 = '' if $item2 eq $item; # no change
chomp( $creator = slurp($f) );
( $item2 = $item ) =~ s(/$creator/)(/CREATOR/);
$item2 = '' if $item2 eq $item; # no change
}
for my $i (keys %repos) {
if ($item eq $i or $item =~ /^$i$/ or $item2 and ( $item2 eq $i or $item2 =~ /^$i$/ )) {
for my $i ( keys %repos ) {
if ( $item eq $i or $item =~ /^$i$/ or $item2 and ( $item2 eq $i or $item2 =~ /^$i$/ ) ) {
push @ret, $i;
}
}
}
for my $i (keys %groups) {
if ($item eq $i or $item =~ /^$i$/ or $item2 and ( $item2 eq $i or $item2 =~ /^$i$/ )) {
for my $i ( keys %groups ) {
if ( $item eq $i or $item =~ /^$i$/ or $item2 and ( $item2 eq $i or $item2 =~ /^$i$/ ) ) {
push @ret, @{ $groups{$i} };
}
}
@ret = @{ sort_u(\@ret) };
dbg(\@ret);
@ret = @{ sort_u( \@ret ) };
return @ret;
}
@ -349,7 +358,7 @@ sub list_memberships {
my $name = shift;
load_common();
my @m = memberships('', $name);
my @m = memberships( '', $name );
return ( sort_u( \@m ) );
}

View file

@ -15,6 +15,7 @@ package Gitolite::Conf::Store;
expand_list
new_repos
new_repo
new_wild_repo
hook_repos
store
parse_done
@ -126,7 +127,7 @@ sub add_rule {
}
sub add_config {
my($n, $key, $value) = @_;
my ( $n, $key, $value ) = @_;
$nextseq++;
for my $repo (@repolist) {
@ -194,6 +195,17 @@ sub new_repo {
# XXX ignoring gl-post-init for now
}
sub new_wild_repo {
my ( $repo, $user ) = @_;
_chdir( $rc{GL_REPO_BASE} );
new_repo($repo);
_print( "$repo.git/gl-creator", $user );
# XXX _print("$repo.git/gl-perms", "$rc{WILDREPOS_DEFAULT_PERMS}\n") if $rc{WILDREPOS_DEFAULT_PERMS};
# XXX git config, daemon, web...
# XXX pre-create, post-create
_chdir( $rc{GL_ADMIN_BASE} );
}
sub hook_repos {
trace(3);
# all repos, all hooks

View file

@ -61,6 +61,13 @@ sub main {
$ENV{GL_REPO} = $repo;
my $aa = ( $verb =~ 'upload' ? 'R' : 'W' );
# auto-create?
if ( repo_missing($repo) and access( $repo, $user, '^C', 'any' ) !~ /DENIED/ ) {
require Gitolite::Conf::Store;
Gitolite::Conf::Store->import;
new_wild_repo( $repo, $user );
}
# a ref of 'any' signifies that this is a pre-git check, where we don't
# yet know the ref that will be eventually pushed (and even that won't
# apply if it's a read operation). See the matching code in access() for