Skip to content

Commit

Permalink
Merged main
Browse files Browse the repository at this point in the history
  • Loading branch information
benedikt-schesch committed Sep 22, 2024
2 parents 2272868 + db1e07d commit 0f42586
Show file tree
Hide file tree
Showing 13 changed files with 56 additions and 47 deletions.
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,7 @@ check-merges-reproducibility:
echo "Running replay_merge for idx $$idx"; \
src/python/replay_merge.py --testing --merges_csv $(CSV_RESULTS) -skip_build -delete_workdir --idx $$idx || FAILED_IDXES="$$FAILED_IDXES $$idx"; \
done; \
echo "$$FAILED_IDXES"; \
test -z "$$FAILED_IDXES"
test -z "$$FAILED_IDXES" || { echo "Failed indexes = $$FAILED_IDXES"; false; }

protect-repos:
find repos -mindepth 1 -type d -exec chmod a-w {} +
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ If you make a change to the mergers that changes merge results, you need to
update the goal files or else reproducibility checks will fail.
Copy certain files from `results/small/` to `test/small-goal-files/`.

To update the reproducibility tests, run `make run-all`.

### Load the stored cache

To decompress the cache run `make decompress-cache`. This is done automatically in `run_combined.sh` if `cache/` does not exist.
Expand Down Expand Up @@ -244,6 +246,8 @@ To investigate differences between two mergers:
* Set `DELETE_WORKDIRS` to `false` in `src/python/variables.py`.
* run `src/python/replay_merge.py --idx INDEX` (maybe add `-test`) for the index of the merge you are interested in.

If the merge is in the small test, you may need to add `--merges_csv ./test/small-goal-files/result.csv`.

## Overwriting results manually

In some cases it might be worth to overwrite the computed results. To do that you should modify the `results/manual_override.csv` file. In that file for the merge you want to overwrite a result of you should include at least the information `repository,merge,left,right` and a new column for the result you want to overwrite. You can overwrite anything you want but if there is a column you don't want to overwrite either do not include that column or leave the entry blanck i.e. `,,`. See the file for an example.
2 changes: 1 addition & 1 deletion run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ fi
cd ./src/scripts/merge_tools/merging
export JAVA_HOME=$JAVA17_HOME
export PATH="$JAVA_HOME/bin:$PATH"
./gradlew shadowJar
./gradlew -q nativeCompile
)

echo "Machine ID: $machine_id"
Expand Down
22 changes: 20 additions & 2 deletions src/python/replay_merge.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Replay merges and their test results.
The output appears in the .workdirs/ directory.
The output appears in the `.workdirs`/ directory.
Logs appear in the `replay_logs/merges/` directory.
Command-line arguments are listed just after the line:
if __name__ == "__main__":
Expand All @@ -13,6 +14,7 @@
import argparse
import git
import os
import os.path
import sys
import tarfile
from pathlib import Path
Expand Down Expand Up @@ -92,7 +94,22 @@ def merge_replay(
plumelib_merging_dir = Path(ast_merging_evaluation_repo.working_tree_dir) / Path(
"src/scripts/merge_tools/merging"
)
subprocess.run(["./gradlew", "-q", "shadowJar"], cwd=plumelib_merging_dir)
print(f"About to compile in {plumelib_merging_dir}")
p = subprocess.run(
["./gradlew", "-q", "shadowJar"],
cwd=plumelib_merging_dir,
capture_output=True,
text=True,
)
if p.returncode != 0:
print("Failure in: ./gradlew -q shadowJar")
print(p.stdout)
print(p.stderr)
sys.exit(1)
p = subprocess.run(
["./gradlew", "-q", "nativeCompile"], cwd=plumelib_merging_dir, check=False
)
print("Finished compiling")

result_df = pd.DataFrame()
with Progress(
Expand Down Expand Up @@ -157,6 +174,7 @@ def merge_replay(
["git", "merge-base", merge_data["left"], merge_data["right"]],
cwd=repo.local_repo_path,
stdout=subprocess.PIPE,
check=True,
)
.stdout.decode("utf-8")
.strip()
Expand Down
9 changes: 7 additions & 2 deletions src/python/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,13 +568,18 @@ def merge(
str(timeout),
f"src/scripts/merge_tools/{tool.name}.sh {self.local_repo_path.resolve()} {LEFT_BRANCH_NAME} {RIGHT_BRANCH_NAME}",
]
logger.debug(
f"merge: Merging {self.repo_slug} {left_commit} {right_commit} with {tool.name}"
)
p = subprocess.run(
command,
capture_output=True,
check=False,
)
std_streams = stdout_and_stderr(command, p)
logger.debug(std_streams)
if p.returncode == 124: # Timeout
explanation = explanation + "\n" + stdout_and_stderr(command, p)
explanation = explanation + "\n" + std_streams
if use_cache:
cache_entry["merge status"] = MERGE_STATE.Merge_timedout.name
cache_entry["explanation"] = explanation
Expand All @@ -593,7 +598,7 @@ def merge(
-1,
)
run_time = time.time() - start_time
explanation = explanation + "\n" + stdout_and_stderr(command, p)
explanation = explanation + "\n" + std_streams
merge_status = (
MERGE_STATE.Merge_success if p.returncode == 0 else MERGE_STATE.Merge_failed
)
Expand Down
6 changes: 4 additions & 2 deletions src/scripts/merge_tools/git_hires_merge.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ clone_dir=$1
branch1=$2
branch2=$3

SCRIPTDIR="$(cd "$(dirname "$0")" && pwd -P)"

# Print the current PATH
echo "PATH: $PATH"
echo "$0 PATH: $PATH"

cd "$clone_dir" || { echo "$0: cannot cd to $clone_dir from $(pwd)"; exit 2; }

Expand All @@ -25,7 +27,7 @@ attributes_file=".git/info/attributes"
echo "* merge=git-hires-merge" >> "$attributes_file"

git config --local merge.git-hires-merge.name "An interactive merge driver for resolving conflicts on individual or adjacent lines"
git config --local merge.git-hires-merge.driver "git-hires-merge %O %A %B %L %P"
git config --local merge.git-hires-merge.driver "${SCRIPTDIR}/git-hires-merge %O %A %B %L %P"
git config --local merge.git-hires-merge.recursive "binary"
git config --local merge.conflictstyle diff3

Expand Down
5 changes: 0 additions & 5 deletions src/scripts/merge_tools/gitmerge.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env sh

# usage: ./git_hires_merge_plus.sh <clone_dir> <branch-1> <branch-2>
# usage: ./gitmerge.sh <clone_dir> <branch-1> <branch-2> <git_strategy>
# Merges branch2 into branch1, in <clone_dir>, using merge strategy <git_strategy>.
# <clone_dir> must contain a clone of a repository.
Expand Down Expand Up @@ -31,26 +30,22 @@ cd "$clone_dir" || { echo "$0: cannot cd to $clone_dir"; exit 2; }

if [ -n "$VERBOSE" ] ; then
echo "$0: about to run: git checkout $branch1 in $(pwd)"
echo "$0: about to run: git checkout $branch1 in $(pwd)" >&2
fi
git checkout "$branch1" --force
if [ -n "$VERBOSE" ] ; then
echo "$0: ran: git checkout $branch1 in $(pwd)"
echo "$0: ran: git checkout $branch1 in $(pwd)" >&2
fi
git config --local merge.conflictstyle diff3
git config --local mergetool.prompt false

echo "$0: about to run: git merge --no-edit $git_strategy $branch2 in $(pwd)"
echo "$0: about to run: git merge --no-edit $git_strategy $branch2 in $(pwd)" >&2

# shellcheck disable=SC2086
git merge --no-edit $git_strategy "$branch2"
retVal=$?

if [ -n "$VERBOSE" ] ; then
echo "$0: ran: git merge --no-edit $git_strategy $branch2 in $(pwd)"
echo "$0: ran: git merge --no-edit $git_strategy $branch2 in $(pwd)" >&2
fi

# report conflicts
Expand Down
19 changes: 6 additions & 13 deletions src/scripts/merge_tools/merge_git_then_plumelib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ branch2=$3
git_strategy=$4 #"-Xignore-space-change"
plumelib_strategy=$5 #"--only-adjacent"

SCRIPTDIR="$(cd "$(dirname "$0")" && pwd -P)"

VERBOSE=
## Enable for debugging
# VERBOSE=YES
Expand All @@ -32,34 +34,30 @@ cd "$clone_dir" || { echo "$0: cannot cd to $clone_dir"; exit 2; }

if [ -n "$VERBOSE" ] ; then
echo "$0: about to run: git checkout $branch1 in $(pwd)"
echo "$0: about to run: git checkout $branch1 in $(pwd)" >&2
fi
git checkout "$branch1" --force
if [ -n "$VERBOSE" ] ; then
echo "$0: ran: git checkout $branch1 in $(pwd)"
echo "$0: ran: git checkout $branch1 in $(pwd)" >&2
fi
git config --local merge.conflictstyle diff3
git config --local mergetool.prompt false

if [ -n "$VERBOSE" ] ; then
echo "$0: about to run: git merge --no-edit $git_strategy $branch2 in $(pwd)"
echo "$0: about to run: git merge --no-edit $git_strategy $branch2 in $(pwd)" >&2
fi

# shellcheck disable=SC2086
git merge --no-edit $git_strategy "$branch2"

if [ -n "$VERBOSE" ] ; then
echo "$0: ran: git merge --no-edit $git_strategy $branch2 in $(pwd)"
echo "$0: ran: git merge --no-edit $git_strategy $branch2 in $(pwd)" >&2
fi

## Now, run Plume-lib Merging to improve the result of `git merge`.

git config --local merge.tool merge-plumelib
# shellcheck disable=SC2016
git config --local mergetool.merge-plumelib.cmd 'merge-tool.sh '"$plumelib_strategy"' ${BASE} ${LOCAL} ${REMOTE} ${MERGED}'
git config --local mergetool.merge-plumelib.cmd "$SCRIPTDIR"/'java-merge-tool.sh '"$plumelib_strategy"' ${BASE} ${LOCAL} ${REMOTE} ${MERGED}'
git config --local mergetool.merge-plumelib.trustExitCode true

case "$plumelib_strategy" in
Expand All @@ -75,12 +73,10 @@ esac

if [ -n "$VERBOSE" ] ; then
echo "$0: about to run: git-mergetool.sh $all_arg --tool=merge-plumelib in $(pwd)"
echo "$0: about to run: git-mergetool.sh $all_arg --tool=merge-plumelib in $(pwd)" >&2
fi
git-mergetool.sh $all_arg --tool=merge-plumelib
if [ -n "$VERBOSE" ] ; then
git-mergetool.sh --verbose $all_arg --tool=merge-plumelib
echo "$0: ran: git-mergetool.sh $all_arg --tool=merge-plumelib in $(pwd)"
echo "$0: ran: git-mergetool.sh $all_arg --tool=merge-plumelib in $(pwd)" >&2
else
git-mergetool.sh $all_arg --tool=merge-plumelib
fi

# Check if there are still conflicts
Expand All @@ -89,17 +85,14 @@ if [ -z "$diffs" ]; then
git add .
if [ -n "$VERBOSE" ] ; then
echo "$0: about to run: git commit in $(pwd)"
echo "$0: about to run: git commit in $(pwd)" >&2
fi
git commit -m "Resolved conflicts by calling: git-mergetool.sh $all_arg --tool=merge-plumelib"
if [ -n "$VERBOSE" ] ; then
echo "$0: ran: git commit in $(pwd)"
echo "$0: ran: git commit in $(pwd)" >&2
fi
exit 0
fi
echo "$0: exiting with status 1"
echo "$0: exiting with status 1" >&2
echo "$0: diffs=$diffs"
echo "$0: Conflict after running in $(pwd):"
echo " git merge --no-edit $git_strategy $branch2"
Expand Down
13 changes: 3 additions & 10 deletions src/scripts/merge_tools/merge_script_then_plumelib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ branch2=$3
merge_script=$4 #"-Xignore-space-change"
plumelib_strategy=$5 #"--only-adjacent"

SCRIPTDIR="$(cd "$(dirname "$0")" && pwd -P)"

VERBOSE=
## Enable for debugging
# VERBOSE=YES
Expand All @@ -33,34 +35,30 @@ cd "$clone_dir" || { echo "$0: cannot cd to $clone_dir"; exit 2; }

if [ -n "$VERBOSE" ] ; then
echo "$0: about to run: git checkout $branch1 in $(pwd)"
echo "$0: about to run: git checkout $branch1 in $(pwd)" >&2
fi
git checkout "$branch1" --force
if [ -n "$VERBOSE" ] ; then
echo "$0: ran: git checkout $branch1 in $(pwd)"
echo "$0: ran: git checkout $branch1 in $(pwd)" >&2
fi
git config --local merge.conflictstyle diff3
git config --local mergetool.prompt false

if [ -n "$VERBOSE" ] ; then
echo "$0: about to run: $merge_script $clone_dir $branch1 $branch2 in $(pwd)"
echo "$0: about to run: $merge_script $clone_dir $branch1 $branch2 in $(pwd)" >&2
fi

# shellcheck disable=SC2086
$merge_script "$clone_dir" "$branch1" "$branch2"

if [ -n "$VERBOSE" ] ; then
echo "$0: ran: $merge_script $clone_dir $branch1 $branch2 in $(pwd)"
echo "$0: ran: $merge_script $clone_dir $branch1 $branch2 in $(pwd)" >&2
fi

## Now, run Plume-lib Merging to improve the result of `$merge_script`.

git config --local merge.tool merge-plumelib
# shellcheck disable=SC2016
git config --local mergetool.merge-plumelib.cmd 'merge-tool.sh '"$plumelib_strategy"' ${BASE} ${LOCAL} ${REMOTE} ${MERGED}'
git config --local mergetool.merge-plumelib.cmd "$SCRIPTDIR"/'java-merge-tool.sh '"$plumelib_strategy"' ${BASE} ${LOCAL} ${REMOTE} ${MERGED}'
git config --local mergetool.merge-plumelib.trustExitCode true

case "$plumelib_strategy" in
Expand All @@ -76,12 +74,10 @@ esac

if [ -n "$VERBOSE" ] ; then
echo "$0: about to run: git-mergetool.sh $all_arg --tool=merge-plumelib in $(pwd)"
echo "$0: about to run: git-mergetool.sh $all_arg --tool=merge-plumelib in $(pwd)" >&2
fi
git-mergetool.sh $all_arg --tool=merge-plumelib
if [ -n "$VERBOSE" ] ; then
echo "$0: ran: git-mergetool.sh $all_arg --tool=merge-plumelib in $(pwd)"
echo "$0: ran: git-mergetool.sh $all_arg --tool=merge-plumelib in $(pwd)" >&2
fi

# Check if there are still conflicts
Expand All @@ -90,17 +86,14 @@ if [ -z "$diffs" ]; then
git add .
if [ -n "$VERBOSE" ] ; then
echo "$0: about to run: git commit in $(pwd)"
echo "$0: about to run: git commit in $(pwd)" >&2
fi
git commit -m "Resolved conflicts by calling: git-mergetool.sh $all_arg --tool=merge-plumelib"
if [ -n "$VERBOSE" ] ; then
echo "$0: ran: git commit in $(pwd)"
echo "$0: ran: git commit in $(pwd)" >&2
fi
exit 0
fi
echo "$0: exiting with status 1"
echo "$0: exiting with status 1" >&2
echo "$0: diffs=$diffs"
echo "$0: Conflict after running in $(pwd):"
echo " $merge_script $clone_dir $branch1 $branch2"
Expand Down
Loading

0 comments on commit 0f42586

Please sign in to comment.