From 998a6e1625711b6954e729a7a6bbd193467793b3 Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Thu, 16 May 2024 06:26:45 -0700 Subject: [PATCH] Get base, left, right, and programmer merge --- Makefile | 2 +- src/python/replay_merge.py | 64 ++++++++++++++++++++++++++++++++++++-- src/python/repo.py | 9 +++++- 3 files changed, 70 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index b5f5159c2c..550074143b 100644 --- a/Makefile +++ b/Makefile @@ -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 {} + diff --git a/src/python/replay_merge.py b/src/python/replay_merge.py index 5722195b73..dcd2801086 100755 --- a/src/python/replay_merge.py +++ b/src/python/replay_merge.py @@ -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 @@ -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( @@ -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: diff --git a/src/python/repo.py b/src/python/repo.py index 3424647f23..b64c1867b4 100755 --- a/src/python/repo.py +++ b/src/python/repo.py @@ -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: @@ -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]: