-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit_ext_diff
More file actions
executable file
·108 lines (80 loc) · 2.68 KB
/
git_ext_diff
File metadata and controls
executable file
·108 lines (80 loc) · 2.68 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
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
#!/usr/bin/env python3
'''
A driver script for Diff/AST
Copyright 2025 Codinuum Software Lab <https://codinuum.com>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
'''
import sys
import os
import subprocess
EXTS = set([
'java',
'py',
'v',
'f', 'F', 'for', 'FOR', 'f77', 'F77',
'f90', 'F90', 'f95', 'F95', 'f03', 'F03', 'f08', 'F08',
'c', 'h', 'cc', 'hh', 'cpp', 'hpp', 'C', 'H',
])
#
DIFFAST_CMD = '/opt/cca/bin/diffast.exe'
VIEWER_CMD = '/opt/cca/bin/diffviewer/run.py'
DIST_DIR = os.path.dirname(os.path.realpath(sys.argv[0]))
if not os.path.exists(DIFFAST_CMD):
DIFFAST_CMD = os.path.join(DIST_DIR, 'dist', 'bin', 'diffast.exe')
if not os.path.exists(VIEWER_CMD):
VIEWER_CMD = os.path.join(DIST_DIR, 'diffviewer', 'run.py')
#
DIFFAST_CMD_FMT = f'{DIFFAST_CMD} -dump:delta {{}} {{}}'
VIEWER_CMD_FMT = f'{VIEWER_CMD} --foreground {{}} {{}}'
DIFF_CMD_FMT = 'diff -u {} {}'
#
def is_src(path):
_, _ext = os.path.splitext(path)
ext = _ext[1:]
b = False
try:
b = ext in EXTS
except Exception:
pass
return b
def diff(file1, file2):
cmd = DIFF_CMD_FMT.format(file1, file2)
subprocess.run(cmd, shell=True, universal_newlines=True)
def diffast(file1, file2):
diffast_cmd = DIFFAST_CMD_FMT.format(file1, file2)
p = subprocess.run(diffast_cmd, shell=True, universal_newlines=True)
if p.returncode == 0:
viewer_cmd = VIEWER_CMD_FMT.format(file1, file2)
subprocess.run(viewer_cmd, shell=True, universal_newlines=True)
def main():
args = sys.argv[1:]
file1 = args[0]
file2 = args[1]
file1_is_src = is_src(file1)
file2_is_src = is_src(file2)
if file1_is_src and file2_is_src:
print(f'\nSource file comparison found: {file1} {file2}', flush=True)
while True:
a = input('Do you want to launch diffast (y/n)? ')
if a == 'y':
break
elif a == 'n':
return
print('launching diffast...', flush=True)
diffast(file1, file2)
# diff(file1, file2) # for testing
else:
print('.', end='', flush=True)
if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
pass