Skip to content

Instantly share code, notes, and snippets.

@camsaul
Created December 15, 2015 18:00
Show Gist options
  • Save camsaul/64af2e323eae7c821968 to your computer and use it in GitHub Desktop.
Save camsaul/64af2e323eae7c821968 to your computer and use it in GitHub Desktop.
Perl script to deduce the primary authors of a git project
#! /usr/bin/perl # -*- coding: utf-8 -*-
use strict;
use warnings;
use List::Util qw(reduce);
my %author_aliases = ('Cameron T Saul' => 'Cam',
'Cam Saul' => 'Cam Saül',
'Cam Saül' => 'Cam Saül'); # different umlauts, apparently
my %counts = ();
sub process_blames {
for (`git blame --line-porcelain $_[0]`) {
next unless m/^author\s+/;
s/author\s+(.*[^\s])\s+$/$1/s;
$_ = $author_aliases{$_} if exists $author_aliases{$_};
$counts{$_} = 0 unless exists $counts{$_};
$counts{$_}++;
}
}
for (@ARGV) {
s/\s*$//s;
print "Processing $_...\n";
process_blames($_);
}
my $total_line_count = reduce {$a + $b} values %counts;
printf("\nTotal: %d files, %d lines\n\n", scalar(@ARGV), $total_line_count);
for (sort { $counts{$b} <=> $counts{$a} } keys %counts) {
my $count = $counts{$_};
my $percent = ($count / $total_line_count) * 100;
printf("%s -> %d (%.01f %%)\n", $_, $count, $percent);
}
Processing src/toucan_finder/models/bird.clj...
Processing src/toucan_finder/models/blueberry.clj...
Processing src/toucan_finder/util.clj...
[...]
Total: 94 files, 12804 lines
Cam Saül -> 8955 (69.9 %)
Rasta Toucan -> 3115 (24.3 %)
Lucky Bird -> 584 (4.6 %)
Trash Bird -> 136 (1.2 %)
cd my-repo && ./project-authors.pl `find src -name "*.clj"`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment