From 3f5568d6b343132d7836d0f8a7910682413c812c Mon Sep 17 00:00:00 2001 From: Benedikt Schesch Date: Sat, 4 May 2024 21:56:51 -0700 Subject: [PATCH] Added adjacent code --- .github/workflows/check-reproducibility.yml | 48 +++++++++++++++ .github/workflows/small-test.yml | 2 - gitmerge_ort_imports.sh | 28 +++++++++ run.sh | 3 + src/scripts/merge_tools/README | 3 - .../merge_tools/gitmerge_ort_adjacent.sh | 28 ++++++--- .../merge_tools/gitmerge_ort_imports.sh | 26 +++----- .../gitmerge_ort_imports_ignorespace.sh | 29 +++------ src/scripts/merge_tools/merging | 2 +- .../merge_tools/resolve-adjacent-conflicts | 61 ------------------- .../merge_tools/resolve-import-conflicts | 39 ++++++++++++ 11 files changed, 156 insertions(+), 113 deletions(-) create mode 100644 .github/workflows/check-reproducibility.yml create mode 100755 gitmerge_ort_imports.sh delete mode 100755 src/scripts/merge_tools/resolve-adjacent-conflicts create mode 100755 src/scripts/merge_tools/resolve-import-conflicts diff --git a/.github/workflows/check-reproducibility.yml b/.github/workflows/check-reproducibility.yml new file mode 100644 index 0000000000..dc47ed0160 --- /dev/null +++ b/.github/workflows/check-reproducibility.yml @@ -0,0 +1,48 @@ +name: Run Reproducibility Check +on: [push, pull_request] +jobs: + test: + strategy: + matrix: + maven: [ '3.9.2' ] + runs-on: ubuntu-latest + defaults: + run: + shell: bash -l {0} + steps: + - uses: actions/setup-java@v3 + with: + distribution: 'zulu' + java-version: 17 + - run: echo "JAVA17_HOME=$JAVA_HOME" >> $GITHUB_ENV + - run: java -version + - uses: actions/checkout@v4 + - name: Set up Python 3.12 + uses: actions/setup-python@v5 + with: + python-version: '3.12' + - name: Setup miniconda + uses: conda-incubator/setup-miniconda@v3 + with: + python-version: 3.12 + auto-update-conda: true + mamba-version: "*" + channels: conda-forge,defaults + activate-environment: AST + environment-file: environment.yml + - name: Install maven + uses: s4u/setup-maven-action@v1.8.0 + with: + java-version: 17 + maven-version: ${{ matrix.maven }} + - name: Clean caches & workspace + run: make clean + - run: echo "LOGURU_COLORIZE=NO" >> $GITHUB_ENV + - name: Run small test + run: | + git config --global user.email "example@example.com" + git config --global user.name "Example Example" + head -n 101 results/combined/result.csv > results/combined/result_trimmed.csv + make check-merges-reproducibility + env: + GITHUB_TOKEN: ${{ secrets.TOKEN_GITHUB }} diff --git a/.github/workflows/small-test.yml b/.github/workflows/small-test.yml index 3ddc480ec3..aa12d188c1 100644 --- a/.github/workflows/small-test.yml +++ b/.github/workflows/small-test.yml @@ -29,8 +29,6 @@ jobs: - run: echo "JAVA17_HOME=$JAVA_HOME" >> $GITHUB_ENV - run: java -version - uses: actions/checkout@v4 - with: - submodules: 'true' - name: Set up Python 3.8 uses: actions/setup-python@v5 with: 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 a3712325d9..55a3609dd9 100755 --- a/run.sh +++ b/run.sh @@ -63,6 +63,9 @@ 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 + # Check if cache.tar exists and cache is missing if [ -f cache.tar ] && [ ! -d cache ]; then echo "Decompressing cache.tar" 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 fb2c1969d2..0f092d230c 100755 --- a/src/scripts/merge_tools/gitmerge_ort_adjacent.sh +++ b/src/scripts/merge_tools/gitmerge_ort_adjacent.sh @@ -1,20 +1,28 @@ #!/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 - echo "Conflict" - 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" --only-adjacent' + +git merge --no-edit "$branch2" +retVal=$? + +# report conflicts +if [ "$retVal" -ne 0 ]; then + echo "Conflict" fi -exit 0 +exit "$retVal" diff --git a/src/scripts/merge_tools/gitmerge_ort_imports.sh b/src/scripts/merge_tools/gitmerge_ort_imports.sh index 0cdda305fc..f19dab922b 100755 --- a/src/scripts/merge_tools/gitmerge_ort_imports.sh +++ b/src/scripts/merge_tools/gitmerge_ort_imports.sh @@ -2,27 +2,19 @@ # usage: ./gitmerge_ort_imports.sh +MERGE_SCRIPTS_DIR="$(cd "$(dirname "$0")" && pwd -P)" clone_dir=$1 branch1=$2 branch2=$3 - -export JAVA_HOME="$JAVA17_HOME" +strategy="-s ort" +if "$MERGE_SCRIPTS_DIR"/gitmerge.sh "$clone_dir" "$branch1" "$branch2" "$strategy"; then + exit 0 +fi 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" +if ! "$MERGE_SCRIPTS_DIR"/resolve-import-conflicts; then + echo "Conflict" + exit 1 fi -exit "$retVal" +exit 0 diff --git a/src/scripts/merge_tools/gitmerge_ort_imports_ignorespace.sh b/src/scripts/merge_tools/gitmerge_ort_imports_ignorespace.sh index 096ff0baf4..fc245a003d 100755 --- a/src/scripts/merge_tools/gitmerge_ort_imports_ignorespace.sh +++ b/src/scripts/merge_tools/gitmerge_ort_imports_ignorespace.sh @@ -1,29 +1,20 @@ #!/usr/bin/env sh -# usage: ./gitmerge_ort_imports_ingorespace.sh +# usage: ./gitmerge_ort_imports_ignorespace.sh +MERGE_SCRIPTS_DIR="$(cd "$(dirname "$0")" && pwd -P)" clone_dir=$1 branch1=$2 branch2=$3 -strategy="-Xignore-space-change" - -export JAVA_HOME="$JAVA17_HOME" +strategy="-s ort -Xignore-space-change" +if "$MERGE_SCRIPTS_DIR"/gitmerge.sh "$clone_dir" "$branch1" "$branch2" "$strategy"; then + exit 0 +fi 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 "$strategy" "$branch2" -retVal=$? - -# report conflicts -if [ "$retVal" -ne 0 ]; then - echo "Conflict" +if ! "$MERGE_SCRIPTS_DIR"/resolve-import-conflicts; then + echo "Conflict" + exit 1 fi -exit "$retVal" +exit 0 diff --git a/src/scripts/merge_tools/merging b/src/scripts/merge_tools/merging index 801f71b918..12f1ad3b8f 160000 --- a/src/scripts/merge_tools/merging +++ b/src/scripts/merge_tools/merging @@ -1 +1 @@ -Subproject commit 801f71b91813c837add5312cd885737676c8abca +Subproject commit 12f1ad3b8f897bb9e5d95a3fa06d600bf8aa450f 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 diff --git a/src/scripts/merge_tools/resolve-import-conflicts b/src/scripts/merge_tools/resolve-import-conflicts new file mode 100755 index 0000000000..73db46473d --- /dev/null +++ b/src/scripts/merge_tools/resolve-import-conflicts @@ -0,0 +1,39 @@ +#!/bin/bash +# bash, not POSIX sh, because of "readarray". + +# This script edits files in place to remove conflict markers related to Java +# imports. For a given conflict that involves only `import` statements and +# blank lines, the output includes every `import` statement that is in either +# of the parents. This script leaves other conflicts untouched. + +# Usage: +# resolve-import-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 in all the files. +# The exit status code is 1 (failure) if any conflict remains. + +# This script 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. + +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 ! "${SCRIPTDIR}"/resolve-conflicts.py --java_imports "$file" ; then + status=1 + fi +done + +exit $status