From 078634088ea06741d39dfe2f295fe2e1e977c4aa Mon Sep 17 00:00:00 2001 From: Bob Swift Date: Sun, 24 Mar 2024 10:00:50 -0600 Subject: [PATCH] Properly accommodate multi-line header line entries. --- gitstage.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/gitstage.py b/gitstage.py index 32f5729a4..f3b4c30e5 100644 --- a/gitstage.py +++ b/gitstage.py @@ -4,7 +4,7 @@ to the headers and do not contain changes to the translation strings. """ -# Copyright (C) 2023 Bob Swift +# Copyright (C) 2023-2024 Bob Swift import argparse @@ -18,8 +18,8 @@ SCRIPT_NAME = 'Picard Docs Git File Stager' -SCRIPT_VERS = '0.4' -SCRIPT_INITIAL_COPYRIGHT = '2023' +SCRIPT_VERS = '0.5' +SCRIPT_INITIAL_COPYRIGHT = '2024' SCRIPT_INITIAL_AUTHOR = 'Bob Swift' DEFAULT_COMPARISON_DISPLAY_LEVEL = 'changed' @@ -287,7 +287,12 @@ def process_change(files_to_stage: dict, fullfilename: str, minus: str, plus: st if minus != plus: files_to_stage[fullfilename] = 'Modified' - for line in git_diff: + line_count = len(git_diff) + line_num = 0 + while line_num < line_count: + line = git_diff[line_num] + line_num += 1 + # for line in git_diff: # Ignore nearby lines and unchanged ranges if line and line[0] in {' ', '@'}: continue @@ -338,6 +343,10 @@ def process_change(files_to_stage: dict, fullfilename: str, minus: str, plus: st if re.match(r'[+-].*\\n"$', line) or re.match(r'[+-]"(' + HEADER_KEYS_TO_IGNORE + r')', line, re.IGNORECASE): process_change(files_to_stage, fullfilename, minus, plus) minus = plus = last = '' + # Keep skipping lines until header line ends with '\n"' + while line_num < line_count and not re.match(r'[+-].*\\n"$', line.strip()): + line = git_diff[line_num] + line_num += 1 continue # Add files with changed translation text lines