We need to avoid decoding errors during the parsing of patches and
[git-dm.git] / count_backports
blob4b2d9f2fd6c7704336091c9a9c097d14c3d5f368
1 #!/usr/bin/python
3 # A hack to count how many commits in a given mainline release were
4 # backported to a previous series of stable commits.
6 # git log stable..stable | count_backports v5.17
8 import pickle, re
9 import gitlog
11 def vmatch(v1, v2):
12 return v2.startswith(v1)
14 p_upstream = re.compile(r'commit ([0-9a-f]+) upstream', re.I)
15 p_upstream2 = re.compile(r'upstream commit ([0-9a-f]+)', re.I)
17 def upstream(patch):
18 m = p_upstream.search(patch.changelog) or \
19 p_upstream2.search(patch.changelog)
20 if m:
21 return m.group(1)
22 return None
24 db = pickle.load(open('committags.db', 'rb'))
26 # Add 12-char versions of all commit IDs since that's what appears
27 # in some stable commits. Copy it to a new dict since otherwise the
28 # keys iterator complains.
30 VDB = { }
31 for commit in db.keys():
32 VDB[commit[:12]] = VDB[commit] = db[commit]
34 versions = { }
35 seen = 0
36 input = open(0, 'rb')
37 patch = gitlog.grabpatch(input)
38 while patch:
39 seen += 1
40 up = upstream(patch)
41 if up:
42 if up in VDB:
43 try:
44 versions[VDB[up]] += 1
45 except KeyError:
46 versions[VDB[up]] = 1
47 patch = gitlog.grabpatch(input)
49 print(f'{seen} patches seen.')
50 for v in sorted(versions):
51 print(f' {v}: {versions[v]} ({100*versions[v]/seen:.2f}%)')