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

« back to all changes in this revision

Viewing changes to src/commands/list-dangling-repos

  • 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 lib $ENV{GL_LIBDIR};
 
6
use Gitolite::Common;
 
7
use Gitolite::Conf::Load;
 
8
 
 
9
=for usage
 
10
Usage:  gitolite list-dangling-repos
 
11
 
 
12
List all existing repos that no one can access remotely any more.  They could
 
13
be normal repos that were taken out of "repo" statements in the conf file, or
 
14
wildcard repos whose matching "wild" pattern was taken out or changed so it no
 
15
longer matches.
 
16
 
 
17
I would advise caution if you use this as a basis for deleting repos from the
 
18
file system.  A bug in this program could cause you to lose important data!
 
19
=cut
 
20
 
 
21
usage() if @ARGV and $ARGV[0] eq '-h';
 
22
 
 
23
# get the two lists we need.  %repos is the list of repos in "repo" statements
 
24
# in the conf file.  %phy_repos is the list of actual repos on disk.  Our job
 
25
# is to cull %phy_repos of all keys that have a matching key in %repos, where
 
26
# "matching" means "string equal" or "regex match".
 
27
my %repos = map { chomp; $_ => 1 } `gitolite list-repos`;
 
28
for my $r ( grep /^@/, keys %repos ) {
 
29
    map { chomp; $repos{$_} = 1; } `gitolite list-members $r`;
 
30
}
 
31
my %phy_repos = map { chomp; $_ => 1 } `gitolite list-phy-repos`;
 
32
 
 
33
# Remove exact matches.  But for repo names like "gtk+", you could have
 
34
# collapsed this into the next step (the regex match).
 
35
for my $pr (keys %phy_repos) {
 
36
    next unless exists $repos{$pr};
 
37
    delete $repos{$pr};
 
38
    delete $phy_repos{$pr};
 
39
}
 
40
 
 
41
# Remove regex matches.
 
42
for my $pr (keys %phy_repos) {
 
43
    my $matched = 0;
 
44
    my $pr2 = Gitolite::Conf::Load::generic_name($pr);
 
45
    for my $r (keys %repos) {
 
46
        if ($pr =~ /^$r$/ or $pr2 =~ /^$r$/) {
 
47
            $matched = 1;
 
48
            next;
 
49
        }
 
50
    }
 
51
    delete $phy_repos{$pr} if $matched;
 
52
}
 
53
 
 
54
# what's left in %phy_repos are dangling repos.
 
55
print join("\n", sort keys %phy_repos), "\n";