Skip to content

Commit

Permalink
Merge branch 'main' into revert_plumelib_2
Browse files Browse the repository at this point in the history
  • Loading branch information
benedikt-schesch committed Sep 22, 2024
2 parents 89a1c3e + cedc855 commit bbf4804
Show file tree
Hide file tree
Showing 37 changed files with 164 additions and 53 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
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,14 @@ If `make small-test` fails in a branch that you wish to merge into the main
branch, run `make small-test` in the main branch (which should succeed) and also
in your branch, and investigate the differences.

#### Updating the goal files

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 @@ -238,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
14 changes: 8 additions & 6 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 Down Expand Up @@ -268,11 +269,11 @@ def merge_replay(
stderr=subprocess.PIPE,
)
if len(process.stderr.decode("utf-8")) == 0:
conflict_files = process.stdout.decode("utf-8")
is_conflict = len(conflict_files) > 0
git_conflict_files = process.stdout.decode("utf-8")
is_conflict = len(git_conflict_files) > 0
assert (
is_conflict == (merge_result == MERGE_STATE.Merge_failed)
), f"merge_replay: tool{merge_tool} merge_result {merge_result} does not match conflict_files {conflict_files} at path {repo.local_repo_path}"
), f"merge_replay: tool merge result is inconsistent with `git diff --diff-filter=U`: tool={merge_tool} merge_result={merge_result} git_conflict_files={git_conflict_files} path={repo.local_repo_path}"

result_df.loc[
merge_tool.name,
Expand Down Expand Up @@ -308,10 +309,11 @@ def merge_replay(
store_artifacts(result_df)
if delete_workdir:
delete_workdirs(result_df)
print("=====================================\n")
print("fingerprints differ; details follow.")
print(f"=================== start of {log_path}:")
with open(log_path, "r", encoding="utf-8") as f:
print(f.read())
print("=====================================\n")
print(f"=================== end of {log_path}.")
raise Exception(
f"fingerprints differ: after merge of {workdir} with {merge_tool}, found"
+ f" {merge_fingerprint} but expected "
Expand Down
24 changes: 19 additions & 5 deletions src/python/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,20 @@ def stdout_and_stderr(
source: Union[subprocess.TimeoutExpired, subprocess.CompletedProcess],
) -> str:
"""Produces the standard output and standard error of a timedout process."""
explanation = "Run Command: " + " ".join(command) + "\nTimed out"
explanation = "Here is the output from: " + " ".join(command)
if source.stdout:
explanation += "\nstdout:\n" + source.stdout.decode("utf-8", "replace")
explanation += (
"\nstdout:\n"
+ source.stdout.decode("utf-8", "replace")
+ "\nEnd of stdout."
)
if source.stderr:
explanation += "\nstderr:\n" + source.stderr.decode("utf-8", "replace")
explanation += (
"\nstderr:\n"
+ source.stderr.decode("utf-8", "replace")
+ "\nEnd of stderr."
)
explanation += "\nEnd of output from: " + " ".join(command)
return explanation


Expand Down Expand Up @@ -549,13 +558,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 @@ -574,7 +588,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
2 changes: 1 addition & 1 deletion src/scripts/merge_tools/adjacent.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env sh

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

MERGE_SCRIPTS_DIR="$(cd "$(dirname "$0")" && pwd -P)"
clone_dir=$1
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/merge_tools/adjacent_ignorespace.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env sh

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

MERGE_SCRIPTS_DIR="$(cd "$(dirname "$0")" && pwd -P)"
clone_dir=$1
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/merge_tools/adjacent_plus.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env sh

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

MERGE_SCRIPTS_DIR="$(cd "$(dirname "$0")" && pwd -P)"
clone_dir=$1
Expand Down
8 changes: 5 additions & 3 deletions src/scripts/merge_tools/git_hires_merge.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env sh

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

set -o nounset

Expand All @@ -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
2 changes: 1 addition & 1 deletion src/scripts/merge_tools/git_hires_merge_plus.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env sh

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

MERGE_SCRIPTS_DIR="$(cd "$(dirname "$0")" && pwd -P)"
clone_dir=$1
Expand Down
18 changes: 17 additions & 1 deletion src/scripts/merge_tools/gitmerge.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,35 @@ branch1=$2
branch2=$3
git_strategy=$4

VERBOSE=
## Enable for debugging
# VERBOSE=YES


## Perform merge

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)"
fi
git checkout "$branch1" --force
if [ -n "$VERBOSE" ] ; then
echo "$0: ran: git checkout $branch1 in $(pwd)"
fi
git config --local merge.conflictstyle diff3
git config --local mergetool.prompt false

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

# 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)"
fi

# report conflicts
if [ $retVal -ne 0 ]; then
echo "gitmerge.sh: Conflict after running: git merge --no-edit $git_strategy $branch2"
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/merge_tools/gitmerge_ort.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env sh

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

MERGE_SCRIPTS_DIR="$(cd "$(dirname "$0")" && pwd -P)"
clone_dir=$1
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/merge_tools/gitmerge_ort_ignorespace.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env sh

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

MERGE_SCRIPTS_DIR="$(cd "$(dirname "$0")" && pwd -P)"
clone_dir=$1
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/merge_tools/gitmerge_recursive_histogram.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env sh

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

MERGE_SCRIPTS_DIR="$(cd "$(dirname "$0")" && pwd -P)"
clone_dir=$1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env sh

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

MERGE_SCRIPTS_DIR="$(cd "$(dirname "$0")" && pwd -P)"
clone_dir=$1
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/merge_tools/gitmerge_recursive_ignorespace.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env sh

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

MERGE_DIR="$(dirname "$0")"
clone_dir=$1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env sh

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

MERGE_SCRIPTS_DIR="$(cd "$(dirname "$0")" && pwd -P)"
clone_dir=$1
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/merge_tools/gitmerge_recursive_minimal.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env sh

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

MERGE_SCRIPTS_DIR="$(cd "$(dirname "$0")" && pwd -P)"
clone_dir=$1
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/merge_tools/gitmerge_recursive_minimal_plus.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env sh

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

MERGE_SCRIPTS_DIR="$(cd "$(dirname "$0")" && pwd -P)"
clone_dir=$1
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/merge_tools/gitmerge_recursive_myers.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env sh

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

MERGE_SCRIPTS_DIR="$(cd "$(dirname "$0")" && pwd -P)"
clone_dir=$1
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/merge_tools/gitmerge_recursive_myers_plus.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env sh

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

MERGE_SCRIPTS_DIR="$(cd "$(dirname "$0")" && pwd -P)"
clone_dir=$1
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/merge_tools/gitmerge_recursive_patience.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env sh

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

MERGE_SCRIPTS_DIR="$(cd "$(dirname "$0")" && pwd -P)"
clone_dir=$1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env sh

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

MERGE_SCRIPTS_DIR="$(cd "$(dirname "$0")" && pwd -P)"
clone_dir=$1
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/merge_tools/gitmerge_resolve.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

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

MERGE_SCRIPTS_DIR="$(cd "$(dirname "$0")" && pwd -P)"
clone_dir=$1
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/merge_tools/gitmerge_resolve_plus.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env sh

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

MERGE_SCRIPTS_DIR="$(cd "$(dirname "$0")" && pwd -P)"
clone_dir=$1
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/merge_tools/imports.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env sh

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

MERGE_SCRIPTS_DIR="$(cd "$(dirname "$0")" && pwd -P)"
clone_dir=$1
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/merge_tools/imports_ignorespace.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env sh

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

MERGE_SCRIPTS_DIR="$(cd "$(dirname "$0")" && pwd -P)"
clone_dir=$1
Expand Down
8 changes: 4 additions & 4 deletions src/scripts/merge_tools/intellimerge.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env sh

# usage: ./intellimerge.sh <clone_dir> <branch-1> <branch-2>
# usage: <scriptname> <clone_dir> <branch-1> <branch-2>
# <clone_dir> must contain a clone of a repository.
# Merges branch2 into branch1, in <clone_dir>.
# Return code is 0 for merge success, 1 for merge failure, 2 for script failure.
Expand Down Expand Up @@ -44,13 +44,13 @@ git checkout "$branch1" --force
git merge --no-edit "$branch2"

# List conflicitng files
conflict_files=$(git diff --name-only --diff-filter=U)
git_conflict_files=$(git diff --name-only --diff-filter=U)

# Initialize a flag to track conflict resolution
conflicts_resolved=true

# Iterate through conflicting files
for file in $conflict_files; do
for file in $git_conflict_files; do
# Check if the conflicting file exists in the temp_out_dir
if [ ! -f "$temp_out_dir$file" ]; then
echo "Conflict not resolved for file: $file"
Expand All @@ -62,7 +62,7 @@ done
if [ "$conflicts_resolved" = false ]; then
echo "Conflict detected. Aborting the merge. Please resolve the conflicts."
echo "All conflicting files:"
echo "$conflict_files"
echo "$git_conflict_files"
rm -rf $temp_out_dir $temp_intellimerge_dir
exit 1
fi
Expand Down
Loading

0 comments on commit bbf4804

Please sign in to comment.