Browse files

(untested) namespace support...

-   see http://sitaramc.github.com/gitolite/namespaces.html for details
-   last time this was tested, "taxpayer funded" and "cyber criminals" were
    mutually exclusive phrases ;-)
  • Loading branch information...
1 parent 0d12bd6 commit 1e7236e3a87600d74172bdf264fba8ee9da93b11 @sitaramc committed Nov 16, 2012
View
3 src/commands/mirror
@@ -66,6 +66,9 @@ if ( $cmd eq 'push' ) {
trace( 1, `cat gl-perms 2>/dev/null | ssh $host CREATOR=$creator perms -c \\'$repo\\' 2>/dev/null` );
}
+ my ($ns, $rr) = repo_namespace($repo);
+ trace(1, "'$repo' is a namespace in '$rr', skipping push"), exit 0 if $rr;
+
my $errors = 0;
my $glss = '';
for (`git push --mirror $host:$repo 2>&1`) {
View
2 src/gitolite-shell
@@ -140,7 +140,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
32 src/lib/Gitolite/Conf/Load.pm
@@ -12,6 +12,7 @@ package Gitolite::Conf::Load;
option
repo_missing
+ repo_namespace
creator
vrefs
@@ -262,6 +263,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
2 src/lib/Gitolite/Rc.pm
@@ -438,6 +438,8 @@ BEGIN {
Mirroring INPUT ::
Mirroring PRE_GIT ::
+ Namespaces PRE_GIT ::
+ Namespaces POST_GIT ::
Mirroring POST_GIT ::
refex-expr ACCESS_2 RefexExpr::access_2
View
2 src/lib/Gitolite/Triggers/Mirroring.pm
@@ -150,6 +150,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;
@@ -169,6 +170,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
32 src/lib/Gitolite/Triggers/Namespaces.pm
@@ -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;

0 comments on commit 1e7236e

Please sign in to comment.