-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcount_backports
executable file
·51 lines (45 loc) · 1.28 KB
/
count_backports
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
#!/usr/bin/python
#
# A hack to count how many commits in a given mainline release were
# backported to a previous series of stable commits.
#
# git log stable..stable | count_backports v5.17
#
import pickle, re
import gitlog
def vmatch(v1, v2):
return v2.startswith(v1)
p_upstream = re.compile(r'commit ([0-9a-f]+) upstream', re.I)
p_upstream2 = re.compile(r'upstream commit ([0-9a-f]+)', re.I)
def upstream(patch):
m = p_upstream.search(patch.changelog) or \
p_upstream2.search(patch.changelog)
if m:
return m.group(1)
return None
db = pickle.load(open('committags.db', 'rb'))
#
# Add 12-char versions of all commit IDs since that's what appears
# in some stable commits. Copy it to a new dict since otherwise the
# keys iterator complains.
#
VDB = { }
for commit in db.keys():
VDB[commit[:12]] = VDB[commit] = db[commit]
versions = { }
seen = 0
input = open(0, 'rb')
patch = gitlog.grabpatch(input)
while patch:
seen += 1
up = upstream(patch)
if up:
if up in VDB:
try:
versions[VDB[up]] += 1
except KeyError:
versions[VDB[up]] = 1
patch = gitlog.grabpatch(input)
print(f'{seen} patches seen.')
for v in sorted(versions):
print(f' {v}: {versions[v]} ({100*versions[v]/seen:.2f}%)')