34 lines
1.5 KiB
Python
34 lines
1.5 KiB
Python
|
|
# 프리팹 파일 두 판(커밋된 것 · 작업 트리의 것)이 '내용으로' 같은지 본다 — 저장할 때마다 바뀌는 파일 안 번호(fileID)는 빼고 견준다.
|
||
|
|
# python prefab_same.py <저장소 폴더> <프리팹 경로> [...]
|
||
|
|
# · 오브젝트 종류별 수, 이름 · 값 줄의 묶음(번호를 # 로 바꾼 뒤 정렬)이 같으면 같은 내용으로 본다
|
||
|
|
import sys, io, re, subprocess, collections
|
||
|
|
|
||
|
|
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
|
||
|
|
repo = sys.argv[1]
|
||
|
|
ID = re.compile(r'(fileID: |&)-?\d+')
|
||
|
|
|
||
|
|
|
||
|
|
def norm(text):
|
||
|
|
kinds = collections.Counter()
|
||
|
|
lines = collections.Counter()
|
||
|
|
for line in text.split('\n'):
|
||
|
|
line = line.rstrip('\r')
|
||
|
|
if line.startswith('--- !u!'):
|
||
|
|
kinds[line.split(' ')[1]] += 1
|
||
|
|
continue
|
||
|
|
lines[ID.sub(r'\1#', line)] += 1
|
||
|
|
return kinds, lines
|
||
|
|
|
||
|
|
|
||
|
|
for path in sys.argv[2:]:
|
||
|
|
old = subprocess.run(['git', '-C', repo, 'show', 'HEAD:' + path], capture_output=True).stdout.decode('utf-8', errors='replace')
|
||
|
|
new = io.open(repo + '/' + path, encoding='utf-8', errors='replace').read()
|
||
|
|
ok, ol = norm(old)
|
||
|
|
nk, nl = norm(new)
|
||
|
|
same_kinds = ok == nk
|
||
|
|
diff = (ol - nl) + (nl - ol)
|
||
|
|
print(path.split('/')[-1], '| 오브젝트 종류별 수 같음' if same_kinds else '| 오브젝트 수 다름', '| 다른 줄', sum(diff.values()))
|
||
|
|
for line, count in list(diff.most_common(12)):
|
||
|
|
side = '커밋' if ol[line] > nl[line] else '작업'
|
||
|
|
print(' x%d [%s쪽이 많음] %s' % (count, side, line.strip()[:150]))
|