-
Notifications
You must be signed in to change notification settings - Fork 196
Expand file tree
/
Copy pathresolve.py
More file actions
65 lines (59 loc) · 2.12 KB
/
Copy pathresolve.py
File metadata and controls
65 lines (59 loc) · 2.12 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
import os
def resolve_file(filepath, strategy):
with open(filepath, 'r') as f:
content = f.read()
out = []
lines = content.split('\n')
i = 0
while i < len(lines):
if lines[i].startswith('<<<<<<<'):
head = []
upstream = []
i += 1
while not lines[i].startswith('======='):
head.append(lines[i])
i += 1
i += 1
while not lines[i].startswith('>>>>>>>'):
upstream.append(lines[i])
i += 1
if strategy == 'ours':
out.extend(head)
elif strategy == 'theirs':
out.extend(upstream)
elif strategy == 'both':
out.extend(head)
out.extend(upstream)
elif strategy == 'smart_lib':
# Custom logic for lib.rs
if "symbol_to_asset_id" in "\n".join(upstream):
out.extend(upstream) # Use upstream's symbol_to_asset_id
elif "EpochClosed" in "\n".join(head):
out.extend(head)
out.extend(upstream)
else:
out.extend(head)
out.extend(upstream)
elif strategy == 'smart_test':
# Custom logic for test.rs
if "std::println" in "\n".join(head):
out.extend(upstream) # Drop our debug prints
else:
out.extend(head) # keep our sequence fixes
else:
out.append(lines[i])
i += 1
with open(filepath, 'w') as f:
f.write('\n'.join(out))
resolve_file('src/auth.rs', 'theirs')
resolve_file('src/governance.rs', 'theirs')
resolve_file('src/consensus.rs', 'both')
resolve_file('src/lib.rs', 'smart_lib')
resolve_file('src/test.rs', 'smart_test')
# For snapshots, we'll just accept ours because the test runner will regenerate them anyway
import glob
for file in glob.glob('test_snapshots/**/*.json', recursive=True):
try:
resolve_file(file, 'ours')
except Exception:
pass