-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
/
authors.py
206 lines (170 loc) · 6.28 KB
/
authors.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#!/usr/bin/env python
# -*- encoding:utf-8 -*-
"""
git-authors [OPTIONS] REV1..REV2
List the authors who contributed within a given revision interval.
"""
# Author: Pauli Virtanen <pav@iki.fi>. This script is in the public domain.
from subprocess import Popen, PIPE, call
import tempfile
import optparse
import re
import os
import subprocess
NAME_MAP = {
u'warren.weckesser': u'Warren Weckesser',
u'josef': u'Josef Perktold',
u'josef-pktd': u'Josef Perktold',
u'Gael varoquaux': u'Gaël Varoquaux',
u'rgommers': u'Ralf Gommers',
u'ArmstrongJ': u'Jeff Armstrong',
u'Collin Stocks': u'Collin RM Stocks',
u'gotgenes': u'Chris Lasher',
u'dsimcha': u'David Simcha',
u'cgholke': u'Christoph Gohlke',
u'Christolph Gohlke': u'Christoph Gohlke',
u'dhuard': u'David Huard',
u'pierregm': u'Pierre GM',
u'Derek Homier': u'Derek Homeier',
u'Derek Homeir': u'Derek Homeier',
u'87': u'Han Genuit',
u'Han': u'Han Genuit',
u'weathergod': u'Benjamin Root',
u'Mark': u'Mark Wiebe',
u'sebhaase': u'Sebastian Haase',
u'mdroe': u'Michael Droettboom',
u'chris.burns': u'Chris Burns',
u'aarchiba': u'Anne Archibald',
u'edschofield': u'Ed Schofield',
}
def main():
p = optparse.OptionParser(__doc__.strip())
p.add_option("-d", "--debug", action="store_true",
help="print debug output")
options, args = p.parse_args()
if len(args) != 1:
p.error("invalid number of arguments")
try:
rev1, rev2 = args[0].split('..')
except ValueError:
p.error("argument is not a revision range")
# Analyze log data
all_authors = set()
authors = set()
def analyze_line(line, names, disp=False):
line = line.strip().decode('utf-8')
# Check the commit author name
m = re.match('^@@@([^@]*)@@@', line)
if m:
name = m.group(1)
line = line[m.end():]
name = NAME_MAP.get(name, name)
if disp:
if name not in names:
print " - Author:", name
names.add(name)
# Look for "thanks to" messages in the commit log
m = re.search(ur'([Tt]hanks to|[Cc]ourtesy of) ([A-Z][A-Za-z]*? [A-Z][A-Za-z]*? [A-Z][A-Za-z]*|[A-Z][A-Za-z ]*? [A-Z][A-Za-z]*|[a-z0-9]+)($|\.| )', line)
if m:
name = m.group(2)
if name not in ('this',):
if disp:
print " - Log :", line.strip()
name = NAME_MAP.get(name, name)
names.add(name)
line = line[m.end():].strip()
line = re.sub(ur'^(and|, and|, ) ', u'Thanks to ', line)
analyze_line(line, names)
# Find all authors before the named range
for line in git.pipe('log', '--pretty=@@@%an@@@%n@@@%cn@@@%n%b',
'%s' % (rev1,)):
analyze_line(line, all_authors)
# Find authors in the named range
for line in git.pipe('log', '--pretty=@@@%an@@@%n@@@%cn@@@%n%b',
'%s..%s' % (rev1, rev2)):
analyze_line(line, authors, disp=options.debug)
# Sort
def name_key(fullname):
m = re.search(u' [a-z ]*[A-Za-z-]+$', fullname)
if m:
forename = fullname[:m.start()].strip()
surname = fullname[m.start():].strip()
else:
forename = u""
surname = fullname.strip()
if surname.startswith('van der '):
surname = surname[8:]
if surname.startswith('de '):
surname = surname[3:]
if surname.startswith('von '):
surname = surname[4:]
return (surname.lower(), forename.lower())
authors = list(authors)
authors.sort(key=name_key)
# Print
print """
Authors
=======
This release contains work by the following people (contributed at least
one patch to this release, names in alphabetical order):
"""
for author in authors:
if author in all_authors:
print (u"* %s" % author).encode('utf-8')
else:
print (u"* %s +" % author).encode('utf-8')
print """
A total of %(count)d people contributed to this release.
People with a "+" by their names contributed a patch for the first time.
""" % dict(count=len(authors))
print ("\nNOTE: Check this list manually! It is automatically generated "
"and some names\n may be missing.")
#------------------------------------------------------------------------------
# Communicating with Git
#------------------------------------------------------------------------------
class Cmd(object):
executable = None
def __init__(self, executable):
self.executable = executable
def _call(self, command, args, kw, repository=None, call=False):
cmd = [self.executable, command] + list(args)
cwd = None
if repository is not None:
cwd = os.getcwd()
os.chdir(repository)
try:
if call:
return subprocess.call(cmd, **kw)
else:
return subprocess.Popen(cmd, **kw)
finally:
if cwd is not None:
os.chdir(cwd)
def __call__(self, command, *a, **kw):
ret = self._call(command, a, {}, call=True, **kw)
if ret != 0:
raise RuntimeError("%s failed" % self.executable)
def pipe(self, command, *a, **kw):
stdin = kw.pop('stdin', None)
p = self._call(command, a, dict(stdin=stdin, stdout=subprocess.PIPE),
call=False, **kw)
return p.stdout
def read(self, command, *a, **kw):
p = self._call(command, a, dict(stdout=subprocess.PIPE),
call=False, **kw)
out, err = p.communicate()
if p.returncode != 0:
raise RuntimeError("%s failed" % self.executable)
return out
def readlines(self, command, *a, **kw):
out = self.read(command, *a, **kw)
return out.rstrip("\n").split("\n")
def test(self, command, *a, **kw):
ret = self._call(command, a, dict(stdout=subprocess.PIPE,
stderr=subprocess.PIPE),
call=True, **kw)
return (ret == 0)
git = Cmd("git")
#------------------------------------------------------------------------------
if __name__ == "__main__":
main()