~ubuntu-branches/ubuntu/utopic/gitolite3/utopic-proposed

« back to all changes in this revision

Viewing changes to src/commands/info

  • Committer: Package Import Robot
  • Author(s): David Bremner
  • Date: 2013-05-18 17:59:21 UTC
  • Revision ID: package-import@ubuntu.com-20130518175921-ac4xe6vd0jtxvjot
Tags: upstream-3.5.1+4
ImportĀ upstreamĀ versionĀ 3.5.1+4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl
 
2
use strict;
 
3
use warnings;
 
4
 
 
5
use Getopt::Long;
 
6
 
 
7
use lib $ENV{GL_LIBDIR};
 
8
use Gitolite::Rc;
 
9
use Gitolite::Common;
 
10
use Gitolite::Conf::Load;
 
11
 
 
12
=for args
 
13
Usage:  gitolite info [-lc] [-ld] [<repo name pattern>]
 
14
 
 
15
List all existing repos you can access, as well as repo name patterns you can
 
16
create repos from (if any).
 
17
 
 
18
    '-lc'       lists creators as an additional field at the end.
 
19
    '-ld'       lists description as an additional field at the end.
 
20
 
 
21
The optional pattern is an unanchored regex that will limit the repos
 
22
searched, in both cases.  It might speed up things a little if you have more
 
23
than a few thousand repos.
 
24
=cut
 
25
 
 
26
# these two are globals
 
27
my ( $lc, $ld, $patt ) = args();
 
28
 
 
29
print_version();
 
30
 
 
31
print_patterns();     # repos he can create for himself
 
32
print_phy_repos();    # repos already created
 
33
print "\n$rc{SITE_INFO}\n" if $rc{SITE_INFO};
 
34
 
 
35
# ----------------------------------------------------------------------
 
36
 
 
37
sub args {
 
38
    my ( $lc, $ld, $patt ) = ( '', '', '' );
 
39
    my $help = '';
 
40
 
 
41
    GetOptions(
 
42
        'lc' => \$lc,
 
43
        'ld' => \$ld,
 
44
        'h'  => \$help,
 
45
    ) or usage();
 
46
 
 
47
    usage() if @ARGV > 1 or $help;
 
48
    $patt = shift @ARGV || '.';
 
49
 
 
50
    return ( $lc, $ld, $patt );
 
51
}
 
52
 
 
53
sub print_version {
 
54
    chomp( my $hn = `hostname -s 2>/dev/null || hostname` );
 
55
    my $gv = substr( `git --version`, 12 );
 
56
    $ENV{GL_USER} or _die "GL_USER not set";
 
57
    print "hello $ENV{GL_USER}, this is " . ($ENV{USER} || "httpd") . "\@$hn running gitolite3 " . version() . " on git $gv\n";
 
58
}
 
59
 
 
60
sub print_patterns {
 
61
    my ( $repos, @aa );
 
62
 
 
63
    my $lm = \&Gitolite::Conf::Load::list_members;
 
64
 
 
65
    # find repo patterns only, call them with ^C flag included
 
66
    @$repos = grep { !/$REPONAME_PATT/ } map { /^@/ ? @{ $lm->($_) } : $_ } @{ lister_dispatch('list-repos')->() };
 
67
    @aa = qw(R W ^C);
 
68
    listem( $repos, '', '', @aa );
 
69
    # but squelch the 'lc' and 'ld' flags for these
 
70
}
 
71
 
 
72
sub print_phy_repos {
 
73
    my ( $repos, @aa );
 
74
 
 
75
    # now get the actual repos and get R or W only
 
76
    _chdir( $rc{GL_REPO_BASE} );
 
77
    $repos = list_phy_repos(1);
 
78
    @aa    = qw(R W);
 
79
    listem( $repos, $lc, $ld, @aa );
 
80
}
 
81
 
 
82
sub listem {
 
83
    my ( $repos, $lc, $ld, @aa ) = @_;
 
84
    my $creator = '';
 
85
    for my $repo (@$repos) {
 
86
        next unless $repo =~ /$patt/;
 
87
        my $perm = '';
 
88
        $creator = creator($repo) if $lc;
 
89
 
 
90
        my $desc = '';
 
91
        for my $d ("$ENV{GL_REPO_BASE}/$repo.git/description") {
 
92
            next unless $ld and -r $d;
 
93
            $desc = slurp($d);
 
94
            chomp($desc);
 
95
        }
 
96
 
 
97
        for my $aa (@aa) {
 
98
            my $ret = access( $repo, $ENV{GL_USER}, $aa, 'any' );
 
99
            $perm .= ( $ret =~ /DENIED/ ? "  " : " $aa" );
 
100
        }
 
101
        $perm =~ s/\^//;
 
102
        next unless $perm =~ /\S/;
 
103
        print "$perm\t$repo";
 
104
        print "\t$creator" if $lc;
 
105
        print "\t$desc" if $ld;
 
106
        print "\n";
 
107
    }
 
108
}
 
109