Created
November 26, 2012 13:18
-
-
Save jubianchi/4148152 to your computer and use it in GitHub Desktop.
Get your git usage stats
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env php | |
<?php | |
$output = $commands = $status = null; | |
exec('ls /usr/lib/git-core', $commands, $status); | |
$commands = array_map(function($v) { return str_replace('git-', '', $v); }, $commands); | |
$output = $reflog = $status = null; | |
exec('git reflog', $reflog, $status); | |
printf(" \033[0;34m%s\033[0;32m" . PHP_EOL, 'Git Command Stats v0.1 - Stats computation based on git\'s reflog'); | |
if(0 === $status) { | |
$stats = $others = array(); | |
$output = null; | |
$log = explode(' ', $reflog[count($reflog) - 1]); | |
$sha1begin = trim($log[0]); | |
exec('git log -1 --format=%cr ' . $sha1begin, $output); | |
$begin = $output[0]; | |
$output = null; | |
$log = explode(' ', $reflog[0]); | |
$sha1end = trim($log[0]); | |
exec('git log -1 --format=%cr ' . $sha1end, $output); | |
$end = $output[0]; | |
printf(" \033[0;33m%s\033[0m (%s) => \033[0;33m%s\033[0m (%s)" . PHP_EOL, $sha1begin, $begin, $sha1end, $end); | |
print PHP_EOL; | |
foreach($reflog as $line) { | |
$line = explode(' ', $line); | |
$sha1 = array_shift($line); | |
array_shift($line); | |
if(false === empty($line)) { | |
$line[0] = trim($line[0], ':'); | |
if(false === empty($commands) && false === in_array($line[0], $commands)) { | |
if( | |
false === in_array($line[0], $others) && | |
false == preg_match('/[0-9a-f]+/', $line[0]) | |
) { | |
$others[] = $line[0]; | |
} | |
$line[0] = 'others*'; | |
} | |
if(false == preg_match('/(\*|:|\w)$/', $line[0])) { | |
$line[0] = $line[0] . ' ' . trim($line[1], ':'); | |
} else { | |
$line[0] = $line[0]; | |
} | |
if(false === isset($stats[$line[0]])) { | |
$stats[$line[0]] = 1; | |
} else { | |
$stats[$line[0]]++; | |
} | |
} | |
} | |
arsort($stats); | |
foreach($stats as $command => $usage) { | |
printf(" \033[0;34m%-20s: \033[0;32m%d\033[0m" . PHP_EOL, $command, $usage); | |
} | |
print str_repeat('-', 30) . PHP_EOL; | |
printf(" \033[0;34m%-20s: \033[0;32m%d\033[0m" . PHP_EOL, 'Total', array_sum($stats)); | |
if(false === empty($others)) { | |
print str_repeat('-', 30) . PHP_EOL; | |
printf(" \033[0;34m%-20s: \033[0;32m%s\033[0m" . PHP_EOL, 'others*', implode(', ', $others)); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Install script | |
$ curl -o git-cstats https://raw.github.com/gist/4148152/4ef0f1b08238ccafe6fa8184cc5d6b429c66210b/git-cstats | |
$ chmod +x ./git-cstats | |
# Put git-cstats somewhere in you PATH | |
# In a git repository, run | |
$ git cstats |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Had an issue or want to make feedback ?
use this: https://github.com/jubianchi/gist
ping me on twitter: @jubianchi