From 7fbb50db92b41cf49e8df7aa1a525ffd43848eab Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Tue, 8 Oct 2024 12:55:58 +0000 Subject: [PATCH] scripts/gendiff.py: support diff options --- scripts/gendiff.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/scripts/gendiff.py b/scripts/gendiff.py index ed7a0b81..20b3f5f9 100755 --- a/scripts/gendiff.py +++ b/scripts/gendiff.py @@ -18,7 +18,8 @@ The cleaned source files are saved with the .clean extension. import sys,re from difflib import unified_diff -fns = sys.argv[1:] +fns = sys.argv[1:3] +diff_opts = sys.argv[4:] if sys.argv[3:4] == ['--'] else None translate = { '\r': None, @@ -55,7 +56,11 @@ cleaned_texts = [cleanup_file(fn) for fn in fns] if len(fns) == 2: # chunk headers have trailing newlines, hence the rstrip() sys.stderr.write('Generating diff\n') - print( - f'diff a/{fns[0]} b/{fns[1]}\n' + - '\n'.join(a.rstrip() for a in unified_diff(*cleaned_texts,fromfile=f'a/{fns[0]}',tofile=f'b/{fns[1]}')) - ) + if diff_opts: + from subprocess import run + run(['diff', '-u'] + [f'{fn}.clean' for fn in fns]) + else: + print( + f'diff a/{fns[0]} b/{fns[1]}\n' + + '\n'.join(a.rstrip() for a in unified_diff(*cleaned_texts,fromfile=f'a/{fns[0]}',tofile=f'b/{fns[1]}')) + )