Skip to content

Instantly share code, notes, and snippets.

@aug2uag
Forked from textarcana/git-log2json.sh
Last active August 29, 2015 14:05
Show Gist options
  • Save aug2uag/f0aa19742d3b71c906cc to your computer and use it in GitHub Desktop.
Save aug2uag/f0aa19742d3b71c906cc to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# generate git log array in JSON:
git log \
--pretty=format:'{%n "commit": "%H",%n "author": "%an <%ae>",%n "date": "%ad",%n "message": "%f"%n},' \
$@ | \
perl -pe 'BEGIN{print "["}; END{print "]\n"}' | \
perl -pe 's/},]/}]/' > logAcc.json
#!/usr/bin/env bash
# generate git log --stats array in JSON
git log \
--numstat \
--format='%H' \
$@ | \
perl -lawne '
if (defined $F[1]) {
print qq#{"insertions": "$F[0]", "deletions": "$F[1]", "path": "$F[2]"},#
} elsif (defined $F[0]) {
print qq#],\n"$F[0]": [#
};
END{print qq#],#}' | \
tail -n +2 | \
perl -wpe 'BEGIN{print "{"}; END{print "}"}' | \
tr '\n' ' ' | \
perl -wpe 's#(]|}),\s*(]|})#$1$2#g' | \
perl -wpe 's#,\s*?}$#}#' > logStats.json
/*
* OPTIONAL: use this Node.js expression to merge the data structures
* created by the two shell scripts above
*/
var logAcc, lstat;
logAcc = require('logAcc.json');
lstat = require('logStats.json');
logAcc.map(function(o){
o.stat = lstat[o.commit];
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment