Skip to content

Instantly share code, notes, and snippets.

@stewartpark
Last active January 21, 2016 01:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stewartpark/fb34c712d04c2569058a to your computer and use it in GitHub Desktop.
Save stewartpark/fb34c712d04c2569058a to your computer and use it in GitHub Desktop.
Aggregate the console output of `ag` and git blame it.
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