Skip to content

Commit

Permalink
Get base, left, right, and programmer merge
Browse files Browse the repository at this point in the history
  • Loading branch information
mernst committed May 16, 2024
1 parent 20959e1 commit 998a6e1
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ clean-local:
check-merges-reproducibility:
@echo "Running replay_merge for each idx in parallel using GNU Parallel..."
@set -e; \
tail -n +2 $(CSV_RESULTS) | awk -F, '{print $$1}' | parallel --halt now,fail=1 -j 50% python3 src/python/replay_merge.py --merges_csv $(CSV_RESULTS) -skip_build -delete_workdir --idx {}
tail -n +2 $(CSV_RESULTS) | awk -F, '{print $$1}' | parallel --halt now,fail=1 -j 50% python3 src/python/replay_merge.py -delete_workdir --idx {}

protect-repos:
find repos -mindepth 1 -type d -exec chmod a-w {} +
Expand Down
64 changes: 61 additions & 3 deletions src/python/replay_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import tarfile
from pathlib import Path
import shutil
import subprocess
import pandas as pd
from repo import Repository, MERGE_TOOL, TEST_STATE, MERGE_STATE
from variables import TIMEOUT_TESTING_MERGE, N_TESTS, WORKDIR_DIRECTORY
Expand Down Expand Up @@ -84,6 +85,63 @@ def merge_replay(
f"Replaying {repo_slug} {merge_data['left']} {merge_data['right']}",
total=len(MERGE_TOOL),
)

# Get base, left, right, and programmer merge.

workdir = Path(
f"{repo_slug}-merge-left"
)
if not (WORKDIR_DIRECTORY / workdir).exists():
repo = Repository(
repo_slug,
cache_directory=Path("no_cache/"),
workdir_id=workdir,
delete_workdir=False,
lazy_clone=False,
)
repo.checkout(merge_data['left'])

workdir = Path(
f"{repo_slug}-merge-right"
)
if not (WORKDIR_DIRECTORY / workdir).exists():
repo = Repository(
repo_slug,
cache_directory=Path("no_cache/"),
workdir_id=workdir,
delete_workdir=False,
lazy_clone=False,
)
repo.checkout(merge_data['right'])

workdir = Path(
f"{repo_slug}-merge-base"
)
if not (WORKDIR_DIRECTORY / workdir).exists():
repo = Repository(
repo_slug,
cache_directory=Path("no_cache/"),
workdir_id=workdir,
delete_workdir=False,
lazy_clone=False,
)
base_commit = subprocess.run(['git', 'merge-base', merge_data['left'], merge_data['right']], stdout=subprocess.PIPE).stdout.decode('utf-8')
repo.checkout(base_commit)

workdir = Path(
f"{repo_slug}-merge-programmer"
)
if not (WORKDIR_DIRECTORY / workdir).exists():
repo = Repository(
repo_slug,
cache_directory=Path("no_cache/"),
workdir_id=workdir,
delete_workdir=False,
lazy_clone=False,
)
repo.checkout(merge_data['merge'])


for merge_tool in MERGE_TOOL:
progress.update(task, advance=1)
workdir = Path(
Expand All @@ -98,19 +156,19 @@ def merge_replay(
if (WORKDIR_DIRECTORY / workdir).exists():
# Ask the user if they want to delete the workdir
logger.info(
f"workdir {WORKDIR_DIRECTORY / workdir} already exists for idx: {merge_idx}"
f"Workdir {WORKDIR_DIRECTORY / workdir} already exists for idx: {merge_idx}"
)
if delete_workdir:
answer = "y"
else:
answer = input(
f"workdir {workdir} exists for idx: {merge_idx}. Delete it? (y/n)"
f"Workdir {workdir} exists for idx: {merge_idx}. Delete it? (y/n)"
)
if answer == "y":
shutil.rmtree(WORKDIR_DIRECTORY / workdir)
else:
logger.info(
f"workdir {WORKDIR_DIRECTORY/workdir} already exists. Skipping"
f"Workdir {WORKDIR_DIRECTORY/workdir} already exists. Skipping."
)
continue
try:
Expand Down
9 changes: 8 additions & 1 deletion src/python/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,14 @@ def clone_repo(self) -> None:
with lock:
if self.repo_path.exists():
return
print(
"Cloning",
self.repo_slug,
"to",
self.repo_path,
"because:",
self.repo_path.exists(),
)
try:
clone_repo(self.repo_slug, self.repo_path)
except Exception as e:
Expand Down Expand Up @@ -242,7 +250,6 @@ def copy_repo(self) -> None:
ignore_dangling_symlinks=True,
)
os.system("chmod -R 777 " + str(self.local_repo_path))

self.repo = Repo(self.local_repo_path)

def checkout(self, commit: str, use_cache: bool = True) -> Tuple[bool, str]:
Expand Down

0 comments on commit 998a6e1

Please sign in to comment.