#! /usr/bin/perl # Copyright (C) 2006, Randy Dunlap. # read stdin, drop non-author: lines, count/sum/tally author: lines by # each author after sanitizing author-name somewhat. # # optionally print out in author-name (-a) alpha order # or in numeric/count (-n) order (low-to-high) # or in numeric/count (-m) order (high-to-low) ("max" first) # hash for author names: my %authors; my $auth; my $sortby; sub usage() { print "usage: authorcount [-a | -n | -m] < git.log.lines\n"; exit(1); } $sortby = $ARGV[0]; if (($sortby ne "") && ($sortby ne "-a") && ($sortby ne "-n") && ($sortby ne "-m")) { print "Invalid sort option: $sortby\n"; usage(); } READIN: while ($line = ) { chomp $line; next READIN if $line !~ /Author:/; $auth = $line; $auth =~ s/Author: //; $auth =~ s/<.*>//; $authors{$auth}++; } # end READIN sub byvalue { $authors{$a} <=> $authors{$b}; } # optionally sort by author name or author counts # print out the tally array if ($sortby eq "-a") { foreach $auth (sort keys %authors) { print "$auth: $authors{$auth}\n"; } } elsif ($sortby eq "-n") { foreach $auth (sort byvalue keys %authors) { print "$auth: $authors{$auth}\n"; } } elsif ($sortby eq "-m") { foreach $auth (reverse sort byvalue keys %authors) { print "$auth: $authors{$auth}\n"; } } else # no sort, just hash order { while (($auth, $count) = each(%authors)) { print "$auth: $count\n"; } }