Last active
January 21, 2016 01:53
-
-
Save stewartpark/fb34c712d04c2569058a to your computer and use it in GitHub Desktop.
Aggregate the console output of `ag` and git blame it.
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
from collections import Counter, defaultdict | |
from subprocess import check_output | |
import sys | |
import re | |
name_extractor=re.compile(r"\(.+?\)") | |
e=defaultdict(set) | |
try: | |
while True: | |
d = raw_input() | |
filename, lineno, _ = d.split(':')[:3] | |
e[filename].add(int(lineno)) | |
except EOFError: | |
pass | |
c = Counter() | |
for filename in e: | |
linenos = e[filename] | |
lines = check_output(["git", "blame", filename]).split("\n") | |
for no, o in enumerate(lines): | |
if not o: break | |
if no+1 in linenos: | |
print o | |
o = name_extractor.findall(o)[0].split() | |
for _ in range(4): o.pop() | |
c[" ".join(o)[1:]]+=1 | |
print c |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment