Skip to content

Instantly share code, notes, and snippets.

@ganadist
Last active December 14, 2015 08:28
Show Gist options
  • Save ganadist/5057717 to your computer and use it in GitHub Desktop.
Save ganadist/5057717 to your computer and use it in GitHub Desktop.
get commit count from AOSP
#!/usr/bin/env python
# -*- coding : utf-8 -*-
import sys, os
import subprocess
import xml.dom.minidom
BOTS = ('[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
)
NOBODY = ('', '[email protected]')
def isBot(email):
if email in BOTS: return True
return email.startswith('android-build')
def isGoogler(email):
if email.endswith('google.com'):
return True
if email.endswith('android.com'):
return True
return email == ''
def getManifest(path):
return os.path.join(path, '.repo', 'manifest.xml')
def getTop():
def isTopDir(path):
return os.access(getManifest(path), os.F_OK)
def getParents():
for env in ('TOP', 'ANDROID_BUILD_TOP'):
wd = os.getenv(env)
if wd: yield wd
wd = os.path.abspath(os.getcwd())
while wd != os.path.sep:
yield wd
wd = os.path.dirname(wd)
for path in getParents():
if isTopDir(path):
return path
assert False, "can not find android source directory."
def getPaths(path):
manifest = getManifest(path)
root = xml.dom.minidom.parse(manifest)
for node in root.childNodes[0].childNodes:
if node.nodeName != 'project':
continue
yield node.getAttribute('path')
def getAuthors(path):
gitdir = os.path.join(path, '.git')
cmd = ('git', 'log', '--no-merges', '--pretty=%ae %an')
p = subprocess.Popen(cmd, stdout = subprocess.PIPE,
env = {'GIT_DIR': gitdir})
for line in p.stdout:
line = line.strip()
if '@' in line:
if ' ' in line:
email, name = line.split(' ', 1)
else:
email, name = line, ''
else:
email, name = '', line
yield email, name
class AuthorCount(object):
def __init__(self, email):
object.__init__(self)
self.email = email
self.names = []
self.count = 0
def getName(self):
return self.names and self.names[0] or ''
def getCount(self):
return self.count
def getEmail(self):
return self.email
def incCount(self, name):
if not name in self.names:
def nameSort(a, b):
if a.islower(): return 1
if b.islower(): return -1
return cmp(b, a)
self.names.append(name)
self.names.sort(nameSort)
self.count += 1
def __str__(self):
if self.email:
mail = self.email.replace('@', ' at ').replace('.', ' dot ')
else:
mail = 'UNKNOWN_AT_GOOGLE_DOT_COM'
return '%s <%s>\t %d'%(self.getName(), mail, self.count)
if __name__ == '__main__':
d = {}
top = getTop()
platformPrefix = ('frameworks',
'bionic',
'system',
'hardware',
'build',
'dalvik',
'libcore',
)
platformOnly = '-p' in sys.argv
commitCountLimit = platformOnly and 500 or 1000
def isPlatform(path):
for prefix in platformPrefix:
if path.startswith(prefix):
return True
for path in getPaths(top):
if platformOnly and not isPlatform(path):
continue
for author in getAuthors(path):
email, name = author
if isBot(email):
continue
if not isGoogler(email):
continue
if email in NOBODY:
key = 'NOBODY', name
email = ''
else:
if email.endswith('corp.google.com'):
email = email.split('@', 1)[0] + '@google.com'
key = email, ''
d.setdefault(key, AuthorCount(email)).incCount(name)
names = {}
for item in d.iteritems():
k, v = item
name = v.getName()
names.setdefault(name, set()).add(item)
# get delegate account in duplicated
def getDelegates(items):
google_account = set()
android_account = set()
for key, value in items:
email = value.getEmail()
if email.endswith('google.com'):
google_account.add((key, value))
elif email.endswith('android.com'):
android_account.add((key, value))
return google_account and google_account or android_account
# merge duplicated account
for items in names.itervalues():
if len(items) == 1: continue
delegates = getDelegates(items)
if len(delegates) != 1: continue
delegate = tuple(delegates)[0][1]
for k, v in items - delegates:
del d[k]
delegate.count += v.count
countKey = lambda x:x.getCount()
nameKey = lambda x:x.getName()
emailKey = lambda x:x.getEmail()
count = 0
for item in sorted(d.itervalues(), key = countKey):
#if d[item].count < commitCountLimit: continue
sys.stdout.write('%s\n'%(str(item)))
count += item.getCount()
print 'total commit count:', count
@ganadist
Copy link
Author

Platform commits:

Dima Zavin <dima at android dot com>     200
Fred Quintana <fredq at google dot com>  202
Chia-chi Yeh <chiachi at android dot com>    208
Nick Kralevich <nnk at google dot com>   214
Craig Mautner <cmautner at google dot com>   219
Wu-cheng Li <wuchengli at google dot com>    223
Leon Scroggins III <scroggo at google dot com>   228
Vasu Nori <vnori at google dot com>  236
Grace Kloba <klobag at google dot com>   237
Brad Fitzpatrick <bradfitz at google dot com>    240
Nick Pelly <npelly at google dot com>    244
Daniel Sandler <dsandler at google dot com>  256
Daisuke Miyakawa <dmiyakawa at google dot com>   259
Mindy Pereira <mindyp at google dot com>     273
Bill Buzbee <buzbee at google dot com>   275
Satoshi Kataoka <satok at google dot com>    276
Eino-Ville Talvala <etalvala at google dot com>  295
Marco Nelissen <marcone at google dot com>   299
David Turner <digit at google dot com>   301
Ben Cheng <bccheng at google dot com>    308
Doug Zongker <dougz at google dot com>   314
Justin Ho <justinho at google dot com>   316
Jaikumar Ganesh <jaikumar at google dot com>     317
Chet Haase <chet at google dot com>  320
San Mehat <san at google dot com>    328
Fabrice Di Meglio <fdimeglio at google dot com>  352
Dirk Dougherty <ddougherty at google dot com>    359
Dan Bornstein <danfuzz at android dot com>   381
Alex Sakhartchouk <alexst at google dot com>     386
Xavier Ducrohet <xav at google dot com>  390
Amith Yamasani <yamasani at google dot com>  392
Steve Block <steveblock at google dot com>   395
Wink Saville <wink at google dot com>    399
Jack Palevich <jackpal at google dot com>    399
Irfan Sheriff <isheriff at google dot com>   406
Jean-Baptiste Queru <jbq at google dot com>  444
Christopher Tate <ctate at google dot com>   459
Robert Greenwalt <rgreenwalt at google dot com>  473
Carl Shapiro <cshapiro at google dot com>    488
Jamie Gennis <jgennis at google dot com>     490
Jeff Sharkey <jsharkey at android dot com>   500
David Agnew <dsandler at android dot com>    504
Jim Miller <jaggies at google dot com>   515
Stephen Hines <srhines at google dot com>    525
Brian Carlstrom <bdc at google dot com>  528
Svetoslav Ganov <svetoslavganov at google dot com>   535
Shih-wei Liao <sliao at google dot com>  540
Kenny Root <kroot at google dot com>     565
Gilles Debunne <debunne at google dot com>   576
Ying Wang <wangying at google dot com>   582
Eric Fischer <enf at google dot com>     621
Joe Onorato <joeo at google dot com>     665
Jean-Michel Trivi <jmtrivi at google dot com>    753
Eric Laurent <elaurent at google dot com>    846
Andy McFadden <fadden at android dot com>    858
James Dong <jdong at google dot com>     963
Jason Sams <jsams at google dot com>     1001
Scott Main <smain at google dot com>     1070
Adam Powell <adamp at google dot com>    1097
Jesse Wilson <jessewilson at google dot com>     1102
Jeff Brown <jeffbrown at google dot com>     1180
Mike Lockwood <lockwood at google dot com>   1322
Romain Guy <romainguy at google dot com>     1380
Glenn Kasten <gkasten at google dot com>     1449
Dianne Hackborn <hackbod at google dot com>  1769
Elliott Hughes <enh at google dot com>   1822
Andreas Huber <andih at google dot com>  1833
Mathias Agopian <mathias at google dot com>  2171
total commit count: 52264


All commits:

Chris Craik <ccraik at google dot com>   301
Kostya Serebryany <kcc at google dot com>    302
Niko Catania <niko at google dot com>    305
Ray Chen <raychen at google dot com>     308
David Brown <dab at google dot com>  316
Teng-Hui Zhu <ztenghui at google dot com>    330
Ken Wakasa <kwakasa at google dot com>   337
Itzhak Katzenelson <isaack at android dot com>   342
Mike Reed <reed at google dot com>   347
Brad Fitzpatrick <bradfitz at google dot com>    350
Siva Velusamy <vsiva at google dot com>  362
Chung-yih Wang <cywang at google dot com>    368
Chet Haase <chet at google dot com>  380
Dirk Dougherty <ddougherty at google dot com>    388
San Mehat <san at google dot com>    388
Fred Quintana <fredq at google dot com>  388
Cary Clark <caryclark at google dot com>     401
Vasu Nori <vnori at google dot com>  403
Ben Komalo <benkomalo at google dot com>     405
Chia-chi Yeh <chiachi at android dot com>    409
Jorg Pleumann <UNKNOWN_AT_GOOGLE_DOT_COM>    410
Daniel Sandler <dsandler at google dot com>  410
Derek Sollenberger <djsollen at google dot com>  420
Nick Kralevich <nnk at google dot com>   434
Nicolas Roard <nicolasroard at google dot com>   436
Alex Sakhartchouk <alexst at google dot com>     437
Eino-Ville Talvala <etalvala at google dot com>  439
Daniel Lehmann <lehmannd at google dot com>  459
Jeff Hamilton <jham at android dot com>  460
Jeffrey Yasskin <jyasskin at google dot com>     466
Patrick Scott <phanna at android dot com>    468
Mindy Pereira <mindyp at google dot com>     477
Grace Kloba <klobag at google dot com>   481
Nick Pelly <npelly at google dot com>    504
Fabrice Di Meglio <fdimeglio at google dot com>  507
Christopher Tate <ctate at google dot com>   518
Hung-ying Tyan <tyanh at google dot com>     520
Doug Zongker <dougz at google dot com>   520
Jamie Gennis <jgennis at google dot com>     522
Kristian Monsen <kristianm at google dot com>    524
Justin Ho <justinho at google dot com>   524
Adam Cohen <adamcohen at google dot com>     525
Jack Palevich <jackpal at google dot com>    532
Jaikumar Ganesh <jaikumar at google dot com>     534
Bill Buzbee <buzbee at google dot com>   536
Michael Kolb <kolby at google dot com>   539
Robert Greenwalt <rgreenwalt at google dot com>  542
Michael Chan <chanm at google dot com>   544
Bjorn Bringert <bringert at android dot com>     544
Wink Saville <wink at google dot com>    553
Irfan Sheriff <isheriff at google dot com>   591
Dan Bornstein <danfuzz at android dot com>   600
Winson Chung <winsonc at google dot com>     602
Ben Cheng <bccheng at google dot com>    610
Michael Jurka <mikejurka at google dot com>  619
Jim Miller <jaggies at google dot com>   622
RoboErik <epastern at google dot com>    625
Leon Scroggins III <scroggo at google dot com>   643
David Agnew <dsandler at android dot com>    643
Stephen Hines <srhines at google dot com>    657
Svetoslav Ganov <svetoslavganov at google dot com>   678
Carl Shapiro <cshapiro at google dot com>    687
Owen Lin <owenlin at google dot com>     688
Andy Stadler <stadler at google dot com>     760
Gilles Debunne <debunne at google dot com>   764
Marco Nelissen <marcone at google dot com>   764
Ben Murdoch <benm at google dot com>     766
Tom Taylor <tomtaylor at google dot com>     782
Shih-wei Liao <sliao at google dot com>  782
Baligh Uddin <baligh at google dot com>  787
Brett Chabot <brettchabot at google dot com>     820
Brian Muramatsu <btmura at google dot com>   864
Amith Yamasani <yamasani at google dot com>  877
Jeff Sharkey <jsharkey at android dot com>   895
Chih-Chung Chang <chihchung at google dot com>   911
Kenny Root <kroot at google dot com>     913
Jean-Michel Trivi <jmtrivi at google dot com>    917
Satoshi Kataoka <satok at google dot com>    925
Eric Laurent <elaurent at google dot com>    931
Your Name <jreck at google dot com>  967
Makoto Onuki <omakoto at google dot com>     983
Joe Onorato <joeo at google dot com>     984
Jean Chalard <jchalard at google dot com>    1003
Tor Norbye <tnorbye at google dot com>   1012
James Dong <jdong at google dot com>     1045
Daisuke Miyakawa <dmiyakawa at google dot com>   1117
Brian Carlstrom <bdc at google dot com>  1169
Jason Sams <jsams at google dot com>     1184
Scott Main <smain at google dot com>     1189
Jean-Baptiste Queru <jbq at google dot com>  1196
Adam Powell <adamp at google dot com>    1202
Ying Wang <wangying at google dot com>   1230
Dmitri Plotnikov <dplotnikov at google dot com>  1324
Wu-cheng Li <wuchengli at google dot com>    1383
Steve Block <steveblock at google dot com>   1404
Jeff Brown <jeffbrown at google dot com>     1458
David Turner <digit at google dot com>   1486
Glenn Kasten <gkasten at google dot com>     1503
Takaoka G. Tadashi <takaoka at google dot com>   1533
Mike Lockwood <lockwood at google dot com>   1607
Andy McFadden <fadden at android dot com>    1719
Romain Guy <romainguy at google dot com>     1793
Andreas Huber <andih at google dot com>  1874
Raphael Moll <raphael at google dot com>     1981
Marc Blank <mblank at google dot com>    2077
Mathias Agopian <mathias at google dot com>  2240
Jesse Wilson <jessewilson at google dot com>     2350
Xavier Ducrohet <xav at google dot com>  2377
Dianne Hackborn <hackbod at google dot com>  2463
Elliott Hughes <enh at google dot com>   3828
Eric Fischer <enf at google dot com>     5647
total commit count: 119826

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment