diff --git a/gitmerge_ort_imports.sh b/gitmerge_ort_imports.sh new file mode 100755 index 0000000000..0cdda305fc --- /dev/null +++ b/gitmerge_ort_imports.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env sh + +# usage: ./gitmerge_ort_imports.sh + +clone_dir=$1 +branch1=$2 +branch2=$3 + +export JAVA_HOME="$JAVA17_HOME" + +cd "$clone_dir" || exit 1 + +git checkout "$branch1" --force + +attributes_file=".git/info/attributes" +echo "*.java merge=merge-java" >> "$attributes_file" +git config --local merge.merge-java.name "Merge Java files" +git config --local merge.merge-java.driver 'java-merge-driver.sh "%A" "%O" "%B"' + +git merge --no-edit "$branch2" +retVal=$? + +# report conflicts +if [ "$retVal" -ne 0 ]; then + echo "Conflict" +fi + +exit "$retVal" diff --git a/run.sh b/run.sh index 4848d21388..c7bd7bc631 100755 --- a/run.sh +++ b/run.sh @@ -70,6 +70,10 @@ PATH=$(pwd)/src/scripts/merge_tools:$PATH PATH=$(pwd)/src/scripts/merge_tools/merging/src/main/sh:$PATH export PATH +# Clone all submodules +git submodule update --init --recursive + +# Empty config file GIT_CONFIG_GLOBAL=$(pwd)/.gitconfig export GIT_CONFIG_GLOBAL diff --git a/src/python/delete_adjacent_keys_from_cache.py b/src/python/delete_adjacent_keys_from_cache.py new file mode 100644 index 0000000000..44d313b82f --- /dev/null +++ b/src/python/delete_adjacent_keys_from_cache.py @@ -0,0 +1,61 @@ +# -*- coding: utf-8 -*- +""" Delete the keys containing 'imports' in the JSON files in the given directory. """ +import os +import json + + +def count_import_keys(directory): + """Count the number of keys containing 'imports' in the JSON files in the given directory.""" + count = 0 + for root, _, files in os.walk(directory): + json_files = [f for f in files if f.endswith(".json")] + for json_file in json_files: + file_path = os.path.join(root, json_file) + with open(file_path, "r", encoding="utf-8") as file: + data = json.load(file) + + # Count keys containing 'adjacent' + keys_to_delete = [key for key in data if "adjacent" in key] + count += len(keys_to_delete) + return count + + +def delete_import_keys(directory): + """Delete the keys containing 'imports' in the JSON files in the given directory.""" + total_deleted = 0 + for root, _, files in os.walk(directory): + json_files = [f for f in files if f.endswith(".json")] + for json_file in json_files: + file_path = os.path.join(root, json_file) + with open(file_path, "r", encoding="utf-8") as file: + data = json.load(file) + + # Record keys to delete + keys_to_delete = [key for key in data.keys() if "adjacent" in key] + if keys_to_delete: + for key in keys_to_delete: + del data[key] + total_deleted += 1 + + # Save the modified data back to file + with open(file_path, "w", encoding="utf-8") as file: + json.dump(data, file, indent=4) + + return total_deleted + + +def main(): + """Main function.""" + directory = "cache" + potential_deletions = count_import_keys(directory) + print(f"Potential deletions: {potential_deletions}") + confirm = input("Do you want to proceed with deleting these keys? (yes/no): ") + if confirm.lower() == "yes": + total_deleted = delete_import_keys(directory) + print(f"Total keys deleted: {total_deleted}") + else: + print("Operation cancelled.") + + +if __name__ == "__main__": + main() diff --git a/src/scripts/merge_tools/README b/src/scripts/merge_tools/README index d27c2dc6ca..228bc7b0bb 100644 --- a/src/scripts/merge_tools/README +++ b/src/scripts/merge_tools/README @@ -1,4 +1 @@ git-hires-merge is from https://github.com/paulaltin/git-hires-merge . - -resolve-adjacent-conflicts, resolve-conflicts.py, and resolve-import-conflicts -are from https://github.com/plume-lib/manage-git-branches . diff --git a/src/scripts/merge_tools/gitmerge_ort_adjacent.sh b/src/scripts/merge_tools/gitmerge_ort_adjacent.sh index 674155b511..b93587a52d 100755 --- a/src/scripts/merge_tools/gitmerge_ort_adjacent.sh +++ b/src/scripts/merge_tools/gitmerge_ort_adjacent.sh @@ -1,15 +1,12 @@ #!/usr/bin/env sh -# usage: ./gitmerge_ort_adjacent.sh +# usage: ./gitmerge_ort_imports.sh -MERGE_SCRIPTS_DIR="$(cd "$(dirname "$0")" && pwd -P)" clone_dir=$1 branch1=$2 branch2=$3 -strategy="-s ort" -if "$MERGE_SCRIPTS_DIR"/gitmerge.sh "$clone_dir" "$branch1" "$branch2" "$strategy"; then - exit 0 -fi + +export JAVA_HOME="$JAVA17_HOME" cd "$clone_dir" || exit 1 if ! "$MERGE_SCRIPTS_DIR"/resolve-adjacent-conflicts; then @@ -17,4 +14,4 @@ if ! "$MERGE_SCRIPTS_DIR"/resolve-adjacent-conflicts; then exit 1 fi -exit 0 +exit "$retVal" diff --git a/src/scripts/merge_tools/resolve-adjacent-conflicts b/src/scripts/merge_tools/resolve-adjacent-conflicts deleted file mode 100755 index 66f40c6ab8..0000000000 --- a/src/scripts/merge_tools/resolve-adjacent-conflicts +++ /dev/null @@ -1,61 +0,0 @@ -#!/bin/bash -# bash, not POSIX sh, because of "readarray". - -# 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 -# than the default behavior of Git, Mercurial, and Bazaar.) This script leaves -# other conflict markers untouched. -# Usage: -# resolve-adjacent-conflicts [file ...] -# -# The script works on all files given on the command line. -# If none are given, the script works on all files in or under the current directory. -# -# The exit status code is 0 (success) if all conflicts are resolved. -# The exit status code is 1 (failure) if any conflict remains. -# -# This is not a git mergetool. A git mergetool is given the base, parent 1, and -# parent 2 files, all without conflict markers. -# However, this can be run after a git mergetool that leaves conflict markers -# in files, as the default git mergetool does. - -# Comparison to other tools -# -# git-hires-merge does more than this script: it resolves non-overlapping -# changes at the character level rather than just the line level. Also, -# git-hires-merge is a mergetool whereas this script is not. -# -# kdiff3 can resolve some conflicts that are on adjacent lines (but not as many -# as this script does). kdiff3 has no way of outputting a file containing -# conflict markers. Invoked like this, it still goes into a GUI if there are -# any merge conflicts that a human must resolve: -# kdiff3 --auto --cs "ShowInfoDialogs=0" base.txt parent1.txt parent2.txt -o merged.txt -# Also, the `--auto` option is ignored for folder comparison. - -DEBUG=0 - -if [ "$#" -eq 0 ] ; then - readarray -t files < <(grep -l -r '^<<<<<<< HEAD' .) -else - files=("$@") -fi - -SCRIPTDIR="$(cd "$(dirname "$0")" && pwd -P)" - -status=0 - -for file in "${files[@]}" ; do - if [ "$DEBUG" ] ; then - echo "before resolve-conflicts.py: $(sha256sum "$file")" - cat "$file" - fi - if ! "${SCRIPTDIR}"/resolve-conflicts.py --adjacent_lines "$file" ; then - status=1 - fi - if [ "$DEBUG" ] ; then - echo "after resolve-conflicts.py: (status=$status: $(sha256sum "$file")" - cat "$file" - fi -done - -exit $status