Last active
December 13, 2015 20:08
-
-
Save zielmicha/4967657 to your computer and use it in GitHub Desktop.
Make LOC history of a git repo and display pretty graph.
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
# Make LOC history of a git repo and display pretty graph. | |
# | |
# Usage: | |
# cd ~/myrepo | |
# python linum.py ~/mylinecountingscript.sh | |
# | |
# Counting script should count LOC in current directory. Example: | |
# wc --lines $(find -name '*.py') | |
# | |
# Requires Python Matplotlib. | |
import subprocess | |
import time | |
import tempfile | |
import os | |
import sys | |
import bisect | |
dir = tempfile.mkdtemp() | |
subprocess.check_call(['git', 'clone', '.', | |
dir + '/gitrepo']) | |
os.chdir(dir + '/gitrepo') | |
subprocess.check_call(['git', 'checkout', 'master'], | |
stderr=open('/dev/null', 'w')) | |
it = subprocess.check_output(['git', 'log']).splitlines() | |
lines = [ line.split(None, 1)[1] | |
for line in it if line.startswith(('commit ', 'Date:')) ] | |
commits = zip(lines[::2], lines[1::2]) | |
linum = [] | |
for id, date in reversed(commits): | |
subprocess.check_call(['git', 'checkout', id], | |
stderr=open('/dev/null', 'w')) | |
count = int(subprocess.check_output(sys.argv[1], shell=True) | |
.splitlines()[-1].split()[0]) | |
t = time.mktime(time.strptime(' '.join(date.split()[:-1]))) | |
linum.append((t, count)) | |
linum.sort() | |
start = linum[0][0] | |
end = linum[-1][0] | |
samples = 50 | |
result = [] | |
for t in xrange(int(start), int(end), int((end - start) / samples)): | |
i = bisect.bisect_left(linum, (t, None)) | |
loc = linum[i][1] | |
lt = time.localtime(t) | |
stime = lt.tm_mon | |
#'%s.%s.%s' % (loc.tm_year, loc.tm_mon, loc.tm_mday) | |
result.append((stime, loc)) | |
from matplotlib import pyplot | |
axis, data = zip(*result) | |
print data | |
pyplot.plot(data) | |
#pyplot.axis(axis) | |
pyplot.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment