Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- """
- Analyze Segwit2x contributors via git history.
- To use:
- git clone git@github.com:bitcoin/bitcoin.git
- cd bitcoin
- git remote add 2x git@github.com:btc1/bitcoin.git
- git fetch 2x
- [wget $THIS_URL, chmod +x, whatever]
- git log origin/master..2x/segwit2x-dev --shortstat --pretty="%cE" | ./analyze2x.py
- """
- import fileinput
- import re
- from collections import namedtuple, defaultdict
- Stat = namedtuple('Stat', 'adds rms files')
- changeline_regexp = (
- r'(?P<files>\d+) file.? changed, '
- r'((?P<adds>\d+) insertion.*)?'
- r'((?P<rms>\d+) delet.*)?')
- definitely_not_a_2x_dev = {
- 'pieter.wuille@gmail.com',
- 'practicalswift@users.noreply.github.com',
- 'laanwj@gmail.com',
- 'noreply@github.com',
- 'sdaftuar@gmail.com',
- 'dev@jonasschnelli.ch',
- 'practicalswift@users.noreply.github.com',
- 'russ@yanofsky.org',
- 'morcos@chaincode.com',
- 'luke-jr+git@utopios.org',
- 'sdaftuar@chaincode.com',
- 'git@bluematt.me',
- 'cory-nospam-@coryfields.com',
- 'falke.marco@gmail.com',
- 'greg@xiph.org',
- 'dev@jonasschnelli.ch',
- 'sdaftuar@gmail.com',
- }
- def main():
- authors_to_stats = defaultdict(list)
- authors_per_line = set()
- lines = fileinput.input()
- for line in lines:
- line = line.strip()
- m = re.search(changeline_regexp, line)
- if m:
- stat = Stat(**m.groupdict())
- for author in authors_per_line:
- authors_to_stats[author].append(stat)
- authors_per_line = set()
- elif line:
- if line not in definitely_not_a_2x_dev:
- authors_per_line.add(line)
- total_stat = aggregate_stat(
- stat for stats in authors_to_stats.values() for stat in stats)
- prettyprint(aggregate(authors_to_stats), total_stat)
- def aggregate(authors_to_stats):
- out = {}
- for author, stats in authors_to_stats.items():
- out[author] = aggregate_stat(stats)
- return list(reversed(sorted(
- out.items(), key=lambda i: i[1].adds + i[1].rms)))
- def aggregate_stat(stats):
- def to_int(a):
- return int(a) if a else 0
- return Stat(
- adds=sum(to_int(s.adds) for s in stats),
- rms=sum(to_int(s.rms) for s in stats),
- files=sum(to_int(s.files) for s in stats),
- )
- def prettyprint(author_stats, total_stat):
- total_changes = total_stat.rms + total_stat.adds
- for author, stat in author_stats:
- perc = (stat.adds + stat.rms) / total_changes
- print("{:>6} {:<40} {:>8} {:>8} {:>20}".format(
- f'{int(perc * 100)}%',
- author,
- f'+{stat.adds}',
- f'-{stat.rms}',
- f'(over {stat.files} files)',
- ))
- if __name__ == '__main__':
- main()
Add Comment
Please, Sign In to add comment