-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdiff-commit-lists
More file actions
executable file
·76 lines (66 loc) · 2.15 KB
/
diff-commit-lists
File metadata and controls
executable file
·76 lines (66 loc) · 2.15 KB
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
#!/usr/bin/env python3
#
# Diff two commit lists
#
import subprocess
import sys
def read_list(filename):
data = []
with open(filename) as fh:
for line in fh:
commit, subject = line.strip().split(' ', 1)
data.append({
'commit': commit,
'subject': subject,
})
return data
def search_list(list1, subject):
for line in list1:
if line['subject'] == subject:
return line['commit']
return '-'
def add_common_commits(list1, list2):
data = []
for line in list1:
line['match'] = search_list(list2, line['subject'])
data.append(line)
return data
left = read_list(sys.argv[1])
right = read_list(sys.argv[2])
left_plus = add_common_commits(left, right)
right_plus = add_common_commits(right, left)
# Write the processed lists to temp files
with open('/tmp/.left', 'w') as fh:
for line in left_plus:
fh.write('{commit:12} {match:12} {subject}\n'.format(**line))
with open('/tmp/.right', 'w') as fh:
for line in right_plus:
fh.write('{match:12} {commit:12} {subject}\n'.format(**line))
# Run 'diff' on the two temp files
width = 400
p = subprocess.run(['sdiff', '--ignore-case', '--ignore-all-space',
'--ignore-blank-lines', '--width={}'.format(2 * width + 3),
'--expand-tabs', '--tabsize=1', '--minimal',
'/tmp/.left', '/tmp/.right'],
capture_output=True, check=False)
# Process the side-by-side diff output
for line in p.stdout.decode().split('\n')[:-1]:
left = line[0:width].strip()
right = line[width + 2:].strip()
result = line[width + 1:width + 2]
if result in (' ', '>'):
# Prefer the right-side ordering
print(right)
elif result == '<':
# Drop the line if it's an out-of-order common commit
right_commit = line.split(' ')[1]
if right_commit == '-':
print(left)
elif result == '|':
print(left)
print(right)
else:
print('*************************')
print('Unable to process line:')
print(line)
print('*************************')