Skip to content

Commit

Permalink
Merge branch 'main' into update-import
Browse files Browse the repository at this point in the history
  • Loading branch information
benedikt-schesch committed May 12, 2024
2 parents c12e5df + 8ba56e9 commit 9e15703
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 71 deletions.
28 changes: 28 additions & 0 deletions gitmerge_ort_imports.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env sh

# usage: ./gitmerge_ort_imports.sh <clone_dir> <branch-1> <branch-2>

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"
4 changes: 4 additions & 0 deletions run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
61 changes: 61 additions & 0 deletions src/python/delete_adjacent_keys_from_cache.py
Original file line number Diff line number Diff line change
@@ -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()
3 changes: 0 additions & 3 deletions src/scripts/merge_tools/README
Original file line number Diff line number Diff line change
@@ -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 .
11 changes: 4 additions & 7 deletions src/scripts/merge_tools/gitmerge_ort_adjacent.sh
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
#!/usr/bin/env sh

# usage: ./gitmerge_ort_adjacent.sh <clone_dir> <branch-1> <branch-2>
# usage: ./gitmerge_ort_imports.sh <clone_dir> <branch-1> <branch-2>

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
echo "gitmerge_ort_adjacent.sh: Conflict"
exit 1
fi

exit 0
exit "$retVal"
61 changes: 0 additions & 61 deletions src/scripts/merge_tools/resolve-adjacent-conflicts

This file was deleted.

0 comments on commit 9e15703

Please sign in to comment.