2012-03-12 16:24:30 +01:00
|
|
|
#!/usr/bin/perl
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
2012-03-19 16:31:08 +01:00
|
|
|
use Getopt::Long;
|
|
|
|
|
2012-04-06 16:59:05 +02:00
|
|
|
use lib $ENV{GL_LIBDIR};
|
2012-03-12 16:24:30 +01:00
|
|
|
use Gitolite::Rc;
|
|
|
|
use Gitolite::Common;
|
|
|
|
use Gitolite::Conf::Load;
|
|
|
|
|
2012-03-29 03:34:46 +02:00
|
|
|
=for args
|
|
|
|
Usage: gitolite info [-lc] [<repo name pattern>]
|
2012-03-19 16:31:08 +01:00
|
|
|
|
2012-04-22 18:14:06 +02:00
|
|
|
List all existing repos you can access, as well as repo name patterns you can
|
|
|
|
create repos from (if any).
|
2012-03-12 16:24:30 +01:00
|
|
|
|
2012-03-29 03:34:46 +02:00
|
|
|
'-lc' lists creators as an additional field at the end.
|
2012-03-19 16:31:08 +01:00
|
|
|
|
|
|
|
The optional pattern is an unanchored regex that will limit the repos
|
|
|
|
searched, in both cases. It might speed up things a little if you have more
|
|
|
|
than a few thousand repos.
|
2012-03-12 16:24:30 +01:00
|
|
|
=cut
|
|
|
|
|
2012-03-29 03:34:46 +02:00
|
|
|
# these two are globals
|
|
|
|
my ( $lc, $patt ) = args();
|
2012-03-19 16:31:08 +01:00
|
|
|
|
2012-03-29 03:34:46 +02:00
|
|
|
print_version();
|
2012-03-12 16:24:30 +01:00
|
|
|
|
2012-03-30 02:41:06 +02:00
|
|
|
print_patterns(); # repos he can create for himself
|
|
|
|
print_phy_repos(); # repos already created
|
2012-03-29 03:34:46 +02:00
|
|
|
print "\n$rc{SITE_INFO}\n" if $rc{SITE_INFO};
|
2012-03-12 16:24:30 +01:00
|
|
|
|
2012-03-29 03:34:46 +02:00
|
|
|
# ----------------------------------------------------------------------
|
2012-03-15 14:44:40 +01:00
|
|
|
|
2012-03-29 03:34:46 +02:00
|
|
|
sub args {
|
|
|
|
my ( $lc, $patt ) = ( '', '' );
|
|
|
|
my $help = '';
|
2012-03-12 16:24:30 +01:00
|
|
|
|
2012-03-29 03:34:46 +02:00
|
|
|
GetOptions(
|
|
|
|
'lc' => \$lc,
|
|
|
|
'h' => \$help,
|
|
|
|
) or usage();
|
2012-03-19 16:31:08 +01:00
|
|
|
|
2012-03-29 03:34:46 +02:00
|
|
|
usage() if @ARGV > 1 or $help;
|
|
|
|
$patt = shift @ARGV || '.';
|
|
|
|
|
|
|
|
return ( $lc, $patt );
|
|
|
|
}
|
|
|
|
|
|
|
|
sub print_version {
|
2012-04-28 08:32:15 +02:00
|
|
|
chomp( my $hn = `hostname -s 2>/dev/null || hostname` );
|
2012-03-29 03:34:46 +02:00
|
|
|
my $gv = substr( `git --version`, 12 );
|
|
|
|
$ENV{GL_USER} or _die "GL_USER not set";
|
2012-05-01 09:42:10 +02:00
|
|
|
print "hello $ENV{GL_USER}, this is " . ($ENV{USER} || "httpd") . "\@$hn running gitolite3 " . version() . " on git $gv\n";
|
2012-03-29 03:34:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sub print_patterns {
|
|
|
|
my ( $repos, @aa );
|
|
|
|
|
|
|
|
# find repo patterns only, call them with ^C flag included
|
|
|
|
@$repos = grep { !/$REPONAME_PATT/ } @{ lister_dispatch('list-repos')->() };
|
2012-03-20 03:13:20 +01:00
|
|
|
@aa = qw(R W ^C);
|
2012-03-29 03:34:46 +02:00
|
|
|
listem( $repos, '', @aa );
|
|
|
|
# but squelch the 'lc' flag for these
|
2012-03-19 16:31:08 +01:00
|
|
|
}
|
|
|
|
|
2012-03-29 03:34:46 +02:00
|
|
|
sub print_phy_repos {
|
|
|
|
my ( $repos, @aa );
|
|
|
|
|
|
|
|
# now get the actual repos and get R or W only
|
|
|
|
_chdir( $rc{GL_REPO_BASE} );
|
|
|
|
$repos = list_phy_repos(1);
|
|
|
|
@aa = qw(R W);
|
|
|
|
listem( $repos, $lc, @aa );
|
|
|
|
}
|
2012-03-20 03:13:20 +01:00
|
|
|
|
2012-03-29 03:34:46 +02:00
|
|
|
sub listem {
|
|
|
|
my ( $repos, $lc, @aa ) = @_;
|
|
|
|
my $creator = '';
|
|
|
|
for my $repo (@$repos) {
|
|
|
|
next unless $repo =~ /$patt/;
|
|
|
|
my $perm = '';
|
|
|
|
$creator = creator($repo) if $lc;
|
|
|
|
|
|
|
|
for my $aa (@aa) {
|
|
|
|
my $ret = access( $repo, $ENV{GL_USER}, $aa, 'any' );
|
|
|
|
$perm .= ( $ret =~ /DENIED/ ? " " : " $aa" );
|
|
|
|
}
|
|
|
|
$perm =~ s/\^//;
|
|
|
|
next unless $perm =~ /\S/;
|
|
|
|
print "$perm\t$repo";
|
|
|
|
print "\t$creator" if $lc;
|
|
|
|
print "\n";
|
2012-03-12 16:24:30 +01:00
|
|
|
}
|
|
|
|
}
|
2012-03-22 10:15:30 +01:00
|
|
|
|