From 92be2088d6a14fe853b69cd849dcb5890b16a1b7 Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Tue, 7 Apr 2026 12:19:13 -0700 Subject: [PATCH 1/2] Simplify --- git-clone-related | 3 ++- resolve-adjacent-conflicts | 6 +++--- resolve-conflicts.py | 25 ++++--------------------- resolve-import-conflicts | 6 +++--- 4 files changed, 12 insertions(+), 28 deletions(-) diff --git a/git-clone-related b/git-clone-related index 53d6a41..addd1da 100755 --- a/git-clone-related +++ b/git-clone-related @@ -40,7 +40,7 @@ # Do not attempt to add "--filter=blob:none" to the git command, as older git # clients (apparently including GitHub, as of 2024-01-27) do not support it. -# Fail if any command fails. +# Do not fail on error; this script handles errors explicitly. set +e if [ "$1" = "--debug" ]; then @@ -111,6 +111,7 @@ else for dir in "../plume-scripts" ".plume-scripts" "../.plume-scripts"; do if [ -d "${SCRIPT_DIR}/${dir}" ]; then PLUME_SCRIPTS="${SCRIPT_DIR}/${dir}" + break fi done if [ -z "$PLUME_SCRIPTS" ]; then diff --git a/resolve-adjacent-conflicts b/resolve-adjacent-conflicts index 0d7935b..081f0d2 100755 --- a/resolve-adjacent-conflicts +++ b/resolve-adjacent-conflicts @@ -1,9 +1,9 @@ #!/bin/bash # bash, not POSIX sh, because of "readarray". -echo "Please use the program in https://github.com/plume-lib/merging ." -echo "You are using $0," -echo "which is an obsolete version in https://github.com/plume-lib/git-scripts ." +echo "Please use the program in https://github.com/plume-lib/merging ." >&2 +echo "You are using $0," >&2 +echo "which is an obsolete version in https://github.com/plume-lib/git-scripts ." >&2 # This script edits files in place to resolve conflict markers due to edits on # adjacent lines. (This is like the behavior of SVN and darcs, but different diff --git a/resolve-conflicts.py b/resolve-conflicts.py index 3e5afd8..90493ca 100755 --- a/resolve-conflicts.py +++ b/resolve-conflicts.py @@ -25,8 +25,6 @@ from __future__ import annotations -import itertools -import shutil import sys import tempfile from argparse import ArgumentParser @@ -64,13 +62,7 @@ def main() -> None: # pylint: disable=too-many-locals args = arg_parser.parse_args() filename = args.filename - num_options = 0 - if args.adjacent_lines: - num_options += 1 - if args.blank_lines: - num_options += 1 - if args.java_imports: - num_options += 1 + num_options = sum([args.adjacent_lines, args.blank_lines, args.java_imports]) if num_options != 1: print("resolve-conflicts.py: supply exactly one option.") sys.exit(1) @@ -107,9 +99,7 @@ def main() -> None: # pylint: disable=too-many-locals tmp.write(line) i = i + num_lines - tmp.close() - shutil.copy(tmp.name, filename) - Path.unlink(Path(tmp.name)) + Path.replace(Path(tmp.name), filename) if conflicts_remain: sys.exit(1) @@ -268,11 +258,7 @@ def merge_edits_on_different_lines( result: list[str] | None = None if base_len == len(parent1) and base_len == len(parent2): result = [] - for base_line, parent1_line, parent2_line in itertools.zip_longest( - base, - parent1, - parent2, - ): + for base_line, parent1_line, parent2_line in zip(base, parent1, parent2, strict=True): debug_print("Considering line:", base_line, parent1_line, parent2_line) if parent1_line == parent2_line: result.append(parent1_line) @@ -395,10 +381,7 @@ def with_one_space(lines: list[str]) -> str: # TODO: This could be more efficient. Even better, I could write a loop in # merge_blank_lines that wouldn't need to create new strings at all. But this is # expedient to write and is probably fast enough. - result_lines = [] - for line in lines: - result_lines += line.split() - return " ".join(result_lines) + return " ".join(word for line in lines for word in line.split()) def debug_print(*args: object) -> None: diff --git a/resolve-import-conflicts b/resolve-import-conflicts index 7fadb5c..4691454 100755 --- a/resolve-import-conflicts +++ b/resolve-import-conflicts @@ -1,9 +1,9 @@ #!/bin/bash # bash, not POSIX sh, because of "readarray". -echo "Please use the program in https://github.com/plume-lib/merging ." -echo "You are using $0," -echo "which is an obsolete version in https://github.com/plume-lib/git-scripts ." +echo "Please use the program in https://github.com/plume-lib/merging ." >&2 +echo "You are using $0," >&2 +echo "which is an obsolete version in https://github.com/plume-lib/git-scripts ." >&2 # This script edits files in place to remove conflict markers related to Java # imports. For a given conflict that involves only `import` statements and From b8046007b0cf60443252d9236f83949676232539 Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Tue, 7 Apr 2026 12:31:49 -0700 Subject: [PATCH 2/2] Undo changes --- resolve-conflicts.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/resolve-conflicts.py b/resolve-conflicts.py index 90493ca..23ecaa0 100755 --- a/resolve-conflicts.py +++ b/resolve-conflicts.py @@ -25,6 +25,7 @@ from __future__ import annotations +import shutil import sys import tempfile from argparse import ArgumentParser @@ -99,7 +100,9 @@ def main() -> None: # pylint: disable=too-many-locals tmp.write(line) i = i + num_lines - Path.replace(Path(tmp.name), filename) + tmp.close() + shutil.copy(tmp.name, filename) + Path.unlink(Path(tmp.name)) if conflicts_remain: sys.exit(1)