Skip to content

Instantly share code, notes, and snippets.

@isidentical
Last active July 23, 2019 06:59
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 isidentical/a2be1ff15f43127d2777ab5a8cfe5d42 to your computer and use it in GitHub Desktop.
Save isidentical/a2be1ff15f43127d2777ab5a8cfe5d42 to your computer and use it in GitHub Desktop.
import subprocess
import shelve
def _find_author(filename, lineno):
prop = subprocess.check_output(f"git blame -pL {lineno},{lineno} {filename}", shell = True)
lines = prop.decode().split("\n")
commit = lines[0].split()[0]
author = lines[1].split()[1]
return commit, author
def find_author(line):
prop = subprocess.check_output(f"fgrep -rni {line!r}", shell = True)
filename, lineno, line = prop.decode().split("\n")[0].split(":")
return line, _find_author(filename, lineno)
with open("../last.txt") as f:
lines = f.read().split("\n")
with shelve.open('result.db') as db, shelve.open('fails.db') as fdb:
for line in lines:
if line in db:
print("continue", line)
continue
elif line in fdb:
print("failed continue", line)
continue
try:
line, answer = find_author(line)
db[line] = answer
print(f"added {len(db)}/{5000 - len(fdb)}", line, *answer)
except Exception as exc:
fdb[line] = True
print("failed", line)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment