From e2f9c78d6c67e3693aef9d93df6a545dfd8caf0c Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Wed, 10 Jul 2024 21:42:50 -0700 Subject: [PATCH] Update `git-hires-merge` from upstream (#315) --- Makefile | 2 +- src/python/merge_runtime_measure.py | 2 +- src/python/replay_merge.py | 4 ++-- .../utils/delete_import_keys_from_cache.py | 2 -- src/scripts/merge_tools/git-hires-merge | 22 ++++++++++++++----- 5 files changed, 20 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index 5a407b2550..406c9ad7bd 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ style: shell-script-style python-style java-style SH_SCRIPTS = $(shell grep --exclude-dir=build --exclude-dir=repos --exclude-dir=cache -r -l '^\#! \?\(/bin/\|/usr/bin/env \)sh' * | grep -v 'git-hires-merge' | grep -v /.git/ | grep -v '~$$' | grep -v '\.tar$$' | grep -v gradlew) BASH_SCRIPTS = $(shell grep --exclude-dir=build --exclude-dir=repos --exclude-dir=cache -r -l '^\#! \?\(/bin/\|/usr/bin/env \)bash' * | grep -v /.git/ | grep -v '~$$' | grep -v '\.tar$$' | grep -v gradlew) -PYTHON_FILES = $(shell find . -name '*.py' ! -path './repos/*' -not -path "./.workdir/*" -not -path "./cache*/*" | grep -v '/__pycache__/' | grep -v '/.git/' | grep -v gradlew) +PYTHON_FILES = $(shell find . -name '*.py' ! -path './repos/*' -not -path "./.workdir/*" -not -path "./cache*/*" | grep -v '/__pycache__/' | grep -v '/.git/' | grep -v gradlew | grep -v git-hires-merge) CSV_RESULTS_COMBINED = results/combined/result.csv CSV_RESULTS_GREATEST_HITS = results/greatest_hits/result.csv diff --git a/src/python/merge_runtime_measure.py b/src/python/merge_runtime_measure.py index 52fd6ac702..3e1764ca6f 100755 --- a/src/python/merge_runtime_measure.py +++ b/src/python/merge_runtime_measure.py @@ -81,7 +81,7 @@ def main(): else: logger.info( f"merge_timer: Running {merge_tool.name} " - f"on {idx} {repo_slug} {left_hash} {right_hash}" + f"on {merge_idx} {repo_slug} {left_hash} {right_hash}" ) run_times = [] for _ in range(args.n_timings): diff --git a/src/python/replay_merge.py b/src/python/replay_merge.py index 5162509922..9d7608df54 100755 --- a/src/python/replay_merge.py +++ b/src/python/replay_merge.py @@ -270,8 +270,8 @@ def merge_replay( if len(process.stderr.decode("utf-8")) == 0: conflict_files = process.stdout.decode("utf-8") is_conflict = len(conflict_files) > 0 - assert is_conflict == ( - merge_result == MERGE_STATE.Merge_failed + assert ( + is_conflict == (merge_result == MERGE_STATE.Merge_failed) ), f"merge_replay: tool{merge_tool} merge_result {merge_result} does not match conflict_files {conflict_files} at path {repo.local_repo_path}" result_df.loc[ diff --git a/src/python/utils/delete_import_keys_from_cache.py b/src/python/utils/delete_import_keys_from_cache.py index 7234a4ce76..29421d28bc 100644 --- a/src/python/utils/delete_import_keys_from_cache.py +++ b/src/python/utils/delete_import_keys_from_cache.py @@ -2,10 +2,8 @@ """Delete the keys containing 'imports' in the JSON files in the given directory.""" import os -import sys import json from pathlib import Path -from argparse import ArgumentParser def count_import_keys(directory: Path) -> int: diff --git a/src/scripts/merge_tools/git-hires-merge b/src/scripts/merge_tools/git-hires-merge index 22606dd978..b673f781a9 100755 --- a/src/scripts/merge_tools/git-hires-merge +++ b/src/scripts/merge_tools/git-hires-merge @@ -49,11 +49,20 @@ try: except ImportError: pass -# for interpreting environment variables -try: - from distutils.util import strtobool -except ImportError: - from distutils import strtobool +# copied from distutils to avoid deprecation warning on python 3.11 and removal on 3.12 and onwards +def strtobool (val): + """Convert a string representation of truth to true (1) or false (0). + True values are 'y', 'yes', 't', 'true', 'on', and '1'; false values + are 'n', 'no', 'f', 'false', 'off', and '0'. Raises ValueError if + 'val' is anything else. + """ + val = val.lower() + if val in ('y', 'yes', 't', 'true', 'on', '1'): + return 1 + elif val in ('n', 'no', 'f', 'false', 'off', '0'): + return 0 + else: + raise ValueError("invalid truth value %r" % (val,)) ############# @@ -791,7 +800,7 @@ for line in tmp: # beginning of conflict zone if line.startswith(marker_start): zone = 1 - for f in hunk: + for f in hunk: f.truncate(0) f.seek(0) @@ -827,3 +836,4 @@ print(col + color.bold + newline + 'Resolved %d of %d conflicts in %s' % (resolv # only exit with success if all conflicts were resolved sys.exit(0 if resolved == num_conflicts else 1) +