From 134bfe240bd6f632807096455a5356c3b4760813 Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Sat, 20 Aug 2016 16:02:51 -0700 Subject: [PATCH] show-pack-counts.pl: utility to view project pack counts Signed-off-by: Kyle J. McKay --- toolbox/show-pack-counts.pl | 65 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100755 toolbox/show-pack-counts.pl diff --git a/toolbox/show-pack-counts.pl b/toolbox/show-pack-counts.pl new file mode 100755 index 0000000..67f807f --- /dev/null +++ b/toolbox/show-pack-counts.pl @@ -0,0 +1,65 @@ +#!/usr/bin/perl + +# Show all projects' pack counts (how many .pack files) +# Use "show-pack-counts.pl --sorted" to see in pack count order +# Use the --objects option to show pack object counts instead of pack counts + +use strict; +use warnings; +use lib @basedir@; + +use Girocco::Config; +use Girocco::Project; + +my $sorted = 0; +my $objcounts = 0; +$sorted=1, shift if @ARGV && $ARGV[0] eq '--sorted'; +$objcounts = 1, shift if @ARGV && $ARGV[0] eq '--objects'; +$sorted=1, shift if @ARGV && $ARGV[0] eq '--sorted'; +my @projects = Girocco::Project::get_full_list; +my $lpbin = $Girocco::Config::basedir . "/bin/list_packs"; +my $prjroot = $Girocco::Config::reporoot; +my @lpcmd = ($lpbin, "--exclude-no-idx"); +push(@lpcmd, $objcounts ? "--count-objects" : "--count"); + +select((select(STDOUT),$|=1)[0]) unless $sorted; + +sub count_proj_packs { + my $projname = shift; + my $pd = $prjroot . "/" . $projname . ".git/objects/pack"; + -d $pd or warn("no such project (anymore) $projname\n"), return undef; + open LPCMD, '-|', @lpcmd, $pd or + warn("failed to run list_packs for project $projname\n"), return undef; + my $pcount = ; + chomp($pcount); + close LPCMD; + $pcount =~ /^\d+$/ or + warn("list_packs produced invalid output for project $projname\n"), return undef; + return 0 + $pcount; +} + +my %counts = (); + +foreach my $proj (@projects) { + my $c = count_proj_packs($proj); + next unless defined($c); + if ($sorted) { + $counts{$proj} = $c; + } else { + printf "%s\t%s\n", $proj, $c; + } +} + +if ($sorted) { + my $sortsub = sub { + my $order = $counts{$b} <=> $counts{$a}; + $order or $order = lc($a) cmp lc($b); + $order; + }; + + foreach my $proj (sort($sortsub keys(%counts))) { + printf "%s\t%s\n", $proj, $counts{$proj}; + } +} + +exit 0; -- 2.11.4.GIT