-
Notifications
You must be signed in to change notification settings - Fork 62
/
Copy pathunmerged-commits.py
executable file
·147 lines (125 loc) · 5.12 KB
/
unmerged-commits.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
#!/usr/bin/env python3
"""
Copyright 2017-Present Couchbase, Inc.
Use of this software is governed by the Business Source License included in
the file licenses/BSL-Couchbase.txt. As of the Change Date specified in that
file, in accordance with the Business Source License, use of this software will
be governed by the Apache License, Version 2.0, included in the file
licenses/APL2.txt.
"""
# Script to show which commit(s) are not yet merged between our release
# branches.
import os
import subprocess
import sys
class bcolors:
"""Define ANSI color codes, if we're running under a TTY."""
if sys.stdout.isatty():
HEADER = '\033[36m'
WARNING = '\033[33m'
INFO = '\033[0;34m'
FAINT = '\033[2m'
ENDC = '\033[0m'
else:
HEADER = ''
WARNING = ''
INFO = ''
FAINT = ''
ENDC = ''
# Sequences of branches to check for unmerged patches. Each toplevel
# element is a series of branches (ordered by ancestry) which should
# be merged into each other. i.e. the oldest supported branch to the
# newest, which is the order patches should be merged.
#
# There is a single sequence of branches for branches representing
# whole release "trains" for a given project - for example
# kv_engine/7.1.x is a train of (7.1.0, 7.1.1, 7.1.2, ...) and should
# be kept merged into neo (7.2.0, ...), as new maintenance releases
# come along.
#
# However, we sometimes have specific branches for a single release
# (e.g. 7.1.4) to support maintenance patches (MPs) which occur
# concurrently alongside the next GA release - 7.1.4-MP1, 7.1.4-MP2.
# Those should be merged back into the GA release branch.
#
# As such, there are multiple sequence of branches -
# one for the main release train and one for each MP branch.
sequences = {
'couchstore': [
[('couchbase/trinity', 'couchbase/master')],
[('couchbase/neo', 'couchbase/trinity')]
],
'kv_engine': [
# main kv_engine release train sequence
[('couchbase/trinity', 'couchbase/master')],
[('couchbase/neo', 'couchbase/trinity')],
# 7.6 release train (trinity)
[('couchbase/7.6.2', 'couchbase/trinity'),
('couchbase/7.6.3', 'couchbase/trinity'),
('couchbase/7.6.4', 'couchbase/trinity'),
('couchbase/7.6.5', 'couchbase/trinity')],
# 7.2 release train (neo) (neo is the confusing release name
# used both for 7.1 and 7.2...). Ideally we should have
# 7.2.4 -> 7.2.5, but the script reports unmerged changes
# and it would be surprising if we suddenly started to
# create new 7.2.5 builds with the forward merge at this point
[('couchbase/7.2.5', 'couchbase/neo'),
('couchbase/7.2.6', 'couchbase/neo')],
# kv_engine 7.1.x release train; one branch for each
# maintenance release which required subsequent maintenance
# patches, finishing in neo branch.
[('couchbase/7.1.3', 'couchbase/7.1.x'),
('couchbase/7.1.4', 'couchbase/7.1.x'),
('couchbase/7.1.x', 'couchbase/neo')]
],
'platform': [
# main platform release train
[('couchbase/trinity', 'couchbase/master')],
[('couchbase/neo', 'couchbase/trinity')],
# platform 7.1.x maintenance train
[('couchbase/7.1.4', 'couchbase/7.1.x'),
('couchbase/7.1.4', 'couchbase/neo')]
],
'sigar': [
# main sigar release train
[('couchbase/neo', 'couchbase/master')]
]
}
def format_commit(sha):
"""Pretty prints the commit."""
# Short hash, message, committer name
return subprocess.check_output(
['git', 'log', '-1', '--pretty=format:%h %s (%cn)', sha],
text=True)
project = os.path.basename(
subprocess.check_output(['git', 'rev-parse', '--show-toplevel'],
text=True).strip())
total_unmerged = 0
for sequence in sequences[project]:
for (downstream, upstream) in sequence:
commits = subprocess.check_output(['git', 'cherry',
upstream, downstream],
text=True)
commits = commits.splitlines()
count = len(commits)
total_unmerged += count
if count > 0:
print(
f"{bcolors.HEADER}{count} commits in '{downstream}' not present in '{upstream}':{bcolors.ENDC}")
for commit in commits:
status, sha = commit.split(' ', maxsplit=1)
commit_text = f'{status} {format_commit(sha)}'
if status == '-':
# Equivalent in upstream, de-emphasise
color = bcolors.FAINT
else:
color = bcolors.ENDC
print(f" {color}{commit_text}{bcolors.ENDC}")
print()
if total_unmerged:
print(f"{bcolors.INFO}Commits listed in oldest to newest order.{bcolors.ENDC}")
print(f"{bcolors.FAINT} '-' for commits that have an equivalent in <upstream>.{bcolors.ENDC}")
print(" '+' for commits that do not.")
print()
print(f"{bcolors.WARNING}Total of {total_unmerged} commits outstanding{bcolors.ENDC}")
sys.exit(total_unmerged)