Skip to content

Instantly share code, notes, and snippets.

@snark
Created April 24, 2018 19:46
Show Gist options
  • Save snark/b8967765045a6e0059caf54884983232 to your computer and use it in GitHub Desktop.
Save snark/b8967765045a6e0059caf54884983232 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import argparse
import operator
import subprocess
parser = argparse.ArgumentParser(description='Count deleted lines only in the current repo')
parser.add_argument('--since', help='Since a date or e.g. "2 weeks ago"')
args = parser.parse_args()
base_command = 'git log --pretty=format:"%an" --numstat'
if args.since:
since = args.since
if (since.endswith('ago')):
since = since.replace(' ', '.')
base_command += ' --since "{}"'.format(since)
else:
# TODO: Validate
base_command += ' --since "{}"'.format(since)
sp = subprocess.run(base_command, stdout=subprocess.PIPE, shell=True)
name = False
scores = {}
for line in sp.stdout.splitlines():
line = line.decode('utf-8')
if line.strip() == '':
pass
elif line[0].isnumeric():
vals = line.split('\t')
old_score = scores.get(name, 0)
scores[name] = old_score + int(vals[1])
else:
if line[0] == '-':
continue
name = line.strip()
sorted_scores = sorted(scores.items(), key=operator.itemgetter(1), reverse=True)
for each in sorted_scores:
print("{}: {}".format(each[0], each[1]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment