Skip to content

Instantly share code, notes, and snippets.

@tlovett1
Created November 2, 2017 20:40
Show Gist options
  • Save tlovett1/d55b8e3f7b630f3fc96b74287457bfab to your computer and use it in GitHub Desktop.
Save tlovett1/d55b8e3f7b630f3fc96b74287457bfab to your computer and use it in GitHub Desktop.
Print out code that an author has contributed to a Git repo filtering out whitespace and compiled files.
#!/usr/bin/env php
<?php
if ( empty( $argv[1] ) ) {
exit( "Need to supply an author.\n" );
}
$author = $argv[1];
exec( 'git ls-files', $files );
echo "Author Report: " . $author;
$added = 0;
$subtracted = 0;
foreach ( $files as $file ) {
if ( false !== strpos( $file, '.min') ) {
continue;
}
$log = '';
exec( 'git log -p -M --author=' . $author . ' --ignore-space-change --ignore-blank-lines --follow --stat -- ' . $file, $log );
if ( empty( $log ) ) {
continue;
}
$log = implode( $log, "\n" );
if ( false === strpos( $log, 'sourceMappingUrl') ) {
echo "\n\n" . $file . "\n----------------------------------------------------------------------------------------------\n\n";
echo $log;
exec( 'git log --author=' . $author . ' --ignore-space-change --ignore-blank-lines --numstat --pretty="%H" -- ' . $file . ' | awk \'NF==3 {plus+=$1; minus+=$2} END {printf("+%d, -%d\n", plus, minus)}\'', $stats );
$added += (int) preg_replace( '#\+([0-9]+), \-([0-9]+)#i', '$1', $stats[0] );
$subtracted += (int) preg_replace( '#\+([0-9]+), \-([0-9]+)#i', '$2', $stats[0] );
}
}
echo "\n\n-----------------------------------\n\n";
echo 'Total Added: ' . $added . "\n";
echo 'Total Subtracted: ' . $subtracted . "\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment