Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

executable file 69 lines (55 sloc) 1.991 kb
#!/usr/bin/env python
Get a git project's authors (ordered by most contributions).
import re
import subprocess
from operator import itemgetter
re_line = re.compile(r'(\d+)\s+(\d+)\s+[^<]+$')
re_author = re.compile(r'.+<(.+)>$')
def get_authors(exclude_primary_author=True):
git_log = subprocess.Popen(["git", "log", "--format=%aN <%aE>",
"--numstat"], stdout=subprocess.PIPE)
output = git_log.communicate()[0]
authors = {}
author = None
for line in output.splitlines():
match = re_line.match(line)
if not match:
if line:
author = line
authors[author] = authors.get(author, 0) + max([int(num)
for num in match.groups()])
# Combine duplicate authors (by email).
emails = {}
for author, changes in authors.items():
match = re_author.match(author)
if not match:
author_emails =
for email in author_emails.split(','):
if '@' not in email:
if email in emails:
remove_author = emails[email]
if remove_author not in authors:
if changes < authors[remove_author]:
author, remove_author = remove_author, author
authors[author] = authors[author] + authors[remove_author]
del authors[remove_author]
emails[email] = author
# Sort authors list.
list_authors = authors.items()
list_authors.sort(key=itemgetter(1), reverse=True)
total = float(sum(authors.values()))
if exclude_primary_author:
top_author = list_authors.pop(0)
total -= top_author[1]
return [(author, changes, changes / total * 100)
for author, changes in list_authors]
if __name__ == '__main__':
for author, changes, percent in get_authors():
print author
Jump to Line
Something went wrong with that request. Please try again.