indextext.html: add notice about upcoming ssh host key change
[girocco.git] / toolbox / clean-tags.pl
blob185c5636aed9f8591250fb9e2b436c47ed615d0b
1 #!/usr/bin/perl
3 # Remove all projects' ctags that are not a valid_tag (--dry-run shows invalid tags)
5 use strict;
6 use warnings;
7 use lib "__BASEDIR__";
9 use Storable;
10 use Girocco::Config;
11 use Girocco::Util qw(valid_tag);
13 my $rr = $Girocco::Config::reporoot;
14 -d $rr or die "No such directory $rr\n";
15 my $gwic = $Girocco::Config::projlist_cache_dir . "/gitweb.index.cache";
16 my $cache;
17 eval { $cache = retrieve($gwic); 1; } or die "Could not load cache file $gwic\n";
19 # Format of cache is:
20 # [ "format string", [[project hash refs in project name order], {project name => hashref}]]
22 # Each project hash ref has:
23 # owner => project owner name
24 # descr_long => project one liner description (from description file)
25 # age_epoch => time of last change (seconds since epoch)
26 # ctags => hash ref of tag => count (not present if ctags not enabled)
27 # path => $Girocco::Config::reporoot relative path to repository
28 # descr => truncated version of descr_long (typically 29-34 characters)
30 @ARGV == 0 || @ARGV == 1 && $ARGV[0] eq "--dry-run"
31 or die "Usage: clean-tags.pl [--dry-run]\n";
33 my $dryrun = @ARGV;
35 my $killcount = 0;
37 sub kill_tag {
38 if (-f "$rr/$_[1]/ctags/$_[0]") {
39 ++$killcount;
40 if ($dryrun) {
41 my $p = $_[1];
42 $p =~ s/\.git$//;
43 printf "%s:\t%s\n", $p, $_[0];
44 } else {
45 unlink("$rr/$_[1]/ctags/$_[0]")
46 or warn "failed to remove '$rr/$_[1]/ctags/$_[0]': $!\n";
51 foreach my $proj (@{$cache->[1][0]}) {
52 ref($proj) eq 'HASH' && ref($proj->{ctags}) eq 'HASH' or next;
53 while (my ($k,$v) = each(%{$proj->{ctags}})) {
54 valid_tag($k) or kill_tag($k, $proj->{path});
58 printf "%s %d tag file(s)\n", ($dryrun?"Would remove":"Removed"), $killcount;
59 exit 0;