5 use lib
$ENV{GL_LIBDIR
};
7 use Gitolite
::Conf
::Load
;
10 Usage: gitolite list-dangling-repos
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
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!
21 usage
() if @ARGV and $ARGV[0] eq '-h';
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`;
31 my %phy_repos = map { chomp; $_ => 1 } `gitolite list-phy-repos`;
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};
38 delete $phy_repos{$pr};
41 # Remove regex matches.
42 for my $pr ( keys %phy_repos ) {
44 my $pr2 = Gitolite
::Conf
::Load
::generic_name
($pr);
45 for my $r ( keys %repos ) {
46 if ( $pr =~ /^$r$/ or $pr2 =~ /^$r$/ ) {
51 delete $phy_repos{$pr} if $matched;
54 # what's left in %phy_repos are dangling repos.
55 print join( "\n", sort keys %phy_repos ), "\n";