Skip to content

Commit

Permalink
temporary commit
Browse files Browse the repository at this point in the history
things are broken, but I need to store changes before going on the other branch
  • Loading branch information
cactusbranch01 committed Apr 7, 2024
1 parent 3b56780 commit 181a4ef
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 189 deletions.
181 changes: 0 additions & 181 deletions src/python/bulk_diff3_analysis.py

This file was deleted.

9 changes: 8 additions & 1 deletion src/python/diff3_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def diff3_analysis(merge_tool: str, results_index: int, repo_output_dir):
shutil.rmtree("./repos", ignore_errors=True)

# Retrieve left and right branch from hash in repo
df = pd.read_csv("../../results_greatest_hits/result.csv")
df = pd.read_csv("../../results/combined/result.csv")
repo_name = df.iloc[results_index]["repository"]

script = "../scripts/merge_tools/" + merge_tool + ".sh"
Expand Down Expand Up @@ -96,7 +96,10 @@ def diff3_analysis(merge_tool: str, results_index: int, repo_output_dir):
repo3.git.checkout(df.iloc[results_index]["merge"], force=True)
repo3.submodule_update()

print(conflict_file_matches)

for conflict_file_match in conflict_file_matches:
print("HELLO!!!")
conflicting_file = str(conflict_file_match)
conflict_path = os.path.join(repo_name, conflicting_file)
conflict_path_merge_attempt = os.path.join(
Expand All @@ -123,6 +126,7 @@ def diff3_analysis(merge_tool: str, results_index: int, repo_output_dir):
# Check that diff3 didn't run into missing files in the base
error_message = "No such file or directory"
if error_message in diff_results.stderr:
print("WHERE WE NEED TO BE")
# Since the conflict file was added in both parents we can't diff the base.
diff_results = subprocess.run(
[
Expand All @@ -139,6 +143,9 @@ def diff3_analysis(merge_tool: str, results_index: int, repo_output_dir):
repo_output_dir, f"diff_{os.path.basename(conflicting_file)}.txt"
)

# Ensure the output directory exists
os.makedirs(diff_filename, exist_ok=True)

# Write the diff results to the file
with open(diff_filename, "w") as diff_file:
diff_file.write(diff_results.stdout)
Expand Down
85 changes: 85 additions & 0 deletions src/python/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# Python Scripts for Merge Conflict Analysis




This directory contains Python scripts designed to facilitate the analysis of merge conflicts using various merge tools. The scripts allow users to recreate merges, analyze conflicts, and compare different merge algorithms' effectiveness.




## Scripts Overview




- `diff3_analysis.py`: This script analyzes merge conflicts for a single specified merge tool and commit.
- `run_diff3_analysis.py`: This script automates the analysis across multiple commits and merge tools, aggregating the results.




## Prerequisites




- Python 3.x installed on your system.
- Necessary Python packages installed (e.g., `pandas`, `GitPython`).




## Usage




### Analyzing a Single Merge Conflict




To analyze merge conflicts using a specific merge tool for a single commit:


python3 diff3_analysis.py <merge_tool> <results_index> <output_directory>




Ex:


python3 diff3_analysis.py gitmerge_ort 582 ./merge_conflict_analysis_diffs/582/gitmerge_ort




<merge_tool>: The merge tool to use for the analysis (e.g., gitmerge_ort).
<results_index>: The index of the commit in the dataset.
<output_directory>: The directory where the analysis results will be saved.




Running Bulk Analysis
To run the analysis over multiple commits and all merge tools:


python3 run_analysis.py --results_index <indexes> --repo_output_dir "<output_directory>"




Ex:


python3 run_diff3_analysis.py --results_index 582,427,930 --repo_output_dir "./merge_conflict_analysis_diffs"


<indexes>: Comma-separated list of commit indices to analyze. Example: 582,427,930.
<output_directory>: The directory where the bulk analysis results will be saved.



12 changes: 5 additions & 7 deletions src/python/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,33 +84,31 @@ def clone_repo(repo_slug: str) -> git.repo.Repo:
return repo


@timeout(10 * 60)
def clone_repo_to_path(repo_slug: str, path: str) -> git.repo.Repo:
"""Clones a repository, or runs `git fetch` if the repository is already cloned.
Args:
repo_slug (str): The slug of the repository, which is "owner/reponame".
path (str): The path to clone the repo into
"""
repo_dir = path / repo_slug
repo_dir = Path(path) / Path(repo_slug)
if repo_dir.exists():
repo = git.repo.Repo(repo_dir)
else:
repo_dir.parent.mkdir(parents=True, exist_ok=True)
os.environ["GIT_TERMINAL_PROMPT"] = "0"
os.environ["GIT_SSH_COMMAND"] = "ssh -o BatchMode=yes"
print(repo_slug, " : Cloning repo")
# ":@" in URL ensures that we are not prompted for login details
# for the repos that are now private.
github_url = "https://:@github.com/" + repo_slug + ".git"
print(repo_slug, " : Finished cloning")
try:
repo = git.repo.Repo.clone_from(github_url, repo_dir)
print(repo_slug, " : Finished cloning")
repo.remote().fetch()
repo.remote().fetch("refs/pull/*/head:refs/remotes/origin/pull/*")
repo.submodule_update()
except GitCommandError as e:
print(repo_slug, "GitCommandError during cloning:\n", e)
raise Exception("GitCommandError during cloning") from e
except Exception as e:
print(repo_slug, "Exception during cloning:\n", e)
raise
return repo


Expand Down

0 comments on commit 181a4ef

Please sign in to comment.