Skip to content

Commit

Permalink
Added adjacent code
Browse files Browse the repository at this point in the history
  • Loading branch information
benedikt-schesch committed May 5, 2024
1 parent 660ca8d commit 3f5568d
Show file tree
Hide file tree
Showing 11 changed files with 156 additions and 113 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/check-reproducibility.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
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 "[email protected]"
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 }}
2 changes: 0 additions & 2 deletions .github/workflows/small-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
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"
3 changes: 3 additions & 0 deletions run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
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 .
28 changes: 18 additions & 10 deletions src/scripts/merge_tools/gitmerge_ort_adjacent.sh
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
#!/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 "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"
26 changes: 9 additions & 17 deletions src/scripts/merge_tools/gitmerge_ort_imports.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,19 @@

# 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

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
29 changes: 10 additions & 19 deletions src/scripts/merge_tools/gitmerge_ort_imports_ignorespace.sh
Original file line number Diff line number Diff line change
@@ -1,29 +1,20 @@
#!/usr/bin/env sh

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

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
2 changes: 1 addition & 1 deletion src/scripts/merge_tools/merging
Submodule merging updated 30 files
+9 −6 README-java-imports.md
+2 −2 README.md
+4 −1 build.gradle
+3 −0 src/main/java/name/fraser/neil/plaintext/diff_match_patch.java
+11 −20 src/main/java/org/plumelib/merging/AbstractMergeDriver.java
+23 −32 src/main/java/org/plumelib/merging/AbstractMergeTool.java
+32 −78 src/main/java/org/plumelib/merging/AdjacentLinesMerger.java
+10 −33 src/main/java/org/plumelib/merging/DmpLibrary.java
+12 −9 src/main/java/org/plumelib/merging/GitLibrary.java
+125 −164 src/main/java/org/plumelib/merging/JavaAnnotationsMerger.java
+10 −20 src/main/java/org/plumelib/merging/JavaCommandLineOptions.java
+236 −430 src/main/java/org/plumelib/merging/JavaImportsMerger.java
+94 −0 src/main/java/org/plumelib/merging/JavaLibrary.java
+28 −23 src/main/java/org/plumelib/merging/JavaMergeDriver.java
+13 −17 src/main/java/org/plumelib/merging/JavaMergeTool.java
+18 −33 src/main/java/org/plumelib/merging/MergeState.java
+77 −4 src/main/java/org/plumelib/merging/Merger.java
+120 −131 src/main/java/org/plumelib/merging/fileformat/ConflictedFile.java
+91 −72 src/main/java/org/plumelib/merging/fileformat/Diff3File.java
+19 −11 src/main/java/org/plumelib/merging/fileformat/RDiff.java
+11 −7 src/test/java/org/plumelib/merging/ConflictedFileTest.java
+4 −3 src/test/java/org/plumelib/merging/Diff3FileTest.java
+37 −0 src/test/java/org/plumelib/merging/JavaAnnotationsMergerTest.java
+6 −34 src/test/java/org/plumelib/merging/JavaImportsMergerTest.java
+35 −0 src/test/java/org/plumelib/merging/JavaLibraryTest.java
+555 −0 src/test/resources/ImportsTest6A.java
+556 −0 src/test/resources/ImportsTest6B.java
+550 −0 src/test/resources/ImportsTest6Base.java
+561 −0 src/test/resources/ImportsTest6Goal.java
+9 −9 src/test/resources/Makefile
61 changes: 0 additions & 61 deletions src/scripts/merge_tools/resolve-adjacent-conflicts

This file was deleted.

39 changes: 39 additions & 0 deletions src/scripts/merge_tools/resolve-import-conflicts
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 3f5568d

Please sign in to comment.