Last active
February 29, 2016 13:08
-
-
Save dmerejkowsky/ccb91c7bf4b2c495dcde to your computer and use it in GitHub Desktop.
Get git history statistics
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
import sys | |
import subprocess | |
import packaging.version | |
import tabulate | |
out = subprocess.check_output(["git", "tag"]).decode("UTF-8") | |
current_branch = subprocess.check_output(["git", "rev-parse", "--abbrev-ref", "HEAD"]) | |
if not current_branch: | |
sys.exit("Not on a branch") | |
current_branch = current_branch.decode("UTF-8").strip() | |
tags = out.splitlines() | |
tags.sort(key=packaging.version.Version) | |
tags.append(current_branch) | |
lines = list() | |
for before, after in zip(tags, tags[1:]): | |
stat = subprocess.check_output(["git", "diff", "--shortstat", "%s..%s" % (before, after)]) | |
stat = stat.decode("UTF-8") | |
files, _, _, insertions, _, deletions, _ = stat.split() | |
lines.append([after, files, insertions, deletions]) | |
out = tabulate.tabulate(lines, headers=["version", "files", "insertions", "deletions"]) | |
print(out) | |
# Example of output: | |
""" | |
version files insertions deletions | |
---------- ------- ------------ ----------- | |
v1.12.1 610 22399 7840 | |
v1.14 177 3889 1865 | |
v1.14.1 4 14 5 | |
... | |
devel 1019 4923 2291 | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Requires packaging and tabulate