-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgit_ext_diff
executable file
·84 lines (65 loc) · 2.04 KB
/
git_ext_diff
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
#!/usr/bin/env python3
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.opt'
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, 'src', 'ast', 'analyzing', 'bin', 'diffast.opt')
if not os.path.exists(VIEWER_CMD):
VIEWER_CMD = os.path.join(DIST_DIR, 'diffviewer', 'run.py')
#
DIFFAST_CMD_FMT = '{} -dump:delta {{}} {{}}'.format(DIFFAST_CMD)
VIEWER_CMD_FMT = '{} --foreground {{}} {{}}'.format(VIEWER_CMD)
DIFF_CMD_FMT = 'diff -u {} {}'
#
def is_src(path):
_, ext = os.path.splitext(path)
b = False
try:
b = ext[1:] in EXTS
except:
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('\nSource file comparison found: {} {}'.format(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)
else:
print('.', end='', flush=True)
if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
pass