-
-
Save hoppfrosch/901b9046a55b004a828b to your computer and use it in GitHub Desktop.
git-log2json #git #script
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 bash | |
# Use this one-liner to produce a JSON literal from the Git log: | |
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/},]/}]/' |
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 bash | |
# OPTIONAL: use this stand-alone shell script to produce a JSON object | |
# with information similar to git --stat. | |
# | |
# You can then easily cross-reference or merge this with the JSON git | |
# log, since both are keyed on the commit hash, which is unique. | |
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*?}$#}#' |
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
/* | |
* OPTIONAL: use this Node.js expression to merge the data structures | |
* created by the two shell scripts above | |
*/ | |
var gitLog, lstat; | |
gitLog = require('git-log.json'); | |
lstat = require('git-stat.json'); | |
gitLog.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