Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ben merge analysis addition #253

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,068 changes: 2,068 additions & 0 deletions results_greatest_hits/result.csv

Large diffs are not rendered by default.

1,096 changes: 0 additions & 1,096 deletions src/python/analysis.ipynb

This file was deleted.

143 changes: 143 additions & 0 deletions src/python/ben_analysis.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"SonarSource/sonar-findbugs : Cloning repo\n",
"Repository 'SonarSource/sonar-findbugs' cloned to path: ./repos/merge_attempt/SonarSource/sonar-findbugs\n",
"SonarSource/sonar-findbugs : Finished cloning\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"Switched to branch 'TEMP_LEFT_BRANCH'\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"SonarSource/sonar-findbugs : Cloning repo\n",
"Repository 'SonarSource/sonar-findbugs' cloned to path: ./repos/base/SonarSource/sonar-findbugs\n",
"SonarSource/sonar-findbugs : Finished cloning\n",
"SonarSource/sonar-findbugs : Cloning repo\n",
"Repository 'SonarSource/sonar-findbugs' cloned to path: ./repos/merge/SonarSource/sonar-findbugs\n",
"SonarSource/sonar-findbugs : Finished cloning\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/snap/core20/current/lib/x86_64-linux-gnu/libstdc++.so.6: version `GLIBCXX_3.4.29' not found (required by /lib/x86_64-linux-gnu/libproxy.so.1)\n",
"Failed to load module: /home/benrr/snap/code/common/.cache/gio-modules/libgiolibproxy.so\n"
]
}
],
"source": [
"import subprocess\n",
"import re\n",
"import os\n",
"import tempfile\n",
"\n",
"import pandas as pd\n",
"from validate_repos import clone_repo_to_path\n",
"from merge_tester import MERGE_STATE\n",
"\n",
"df = pd.read_csv('../../results/result.csv')\n",
"\n",
"repo_num = 1084\n",
"# merge_tool = \"gitmerge-recursive-patience\"\n",
"# merge_tool = \"spork\"\n",
"# merge_tool = \"gitmerge-recursive-minimal\"\n",
"# merge_tool = \"gitmerge-resrepo_num = 3595\n",
"# merge_tool = \"gitmerge-recursive-patience\"\n",
"# merge_tool = \"spork\"\n",
"# merge_tool = \"git merge-resolve\"\n",
"# merge_tool = \"intellimerge\"\n",
"merge_tool = 'gitmerge-ort-ignorespace'\n",
"# merge_tool = 'gitmerge-ort'\n",
"\n",
"repo_name = df.iloc[repo_num][\"repo_name\"]\n",
"\n",
"script = \"../scripts/merge_tools/\" + merge_tool + \".sh\"\n",
"repo = clone_repo_to_path(repo_name, \"./repos/merge_attempt\") # Return a Git-Python repo object\n",
"repo.remote().fetch()\n",
"repo.git.checkout(df.iloc[repo_num][\"left\"], force=True)\n",
"repo.submodule_update()\n",
"repo.git.checkout(\"-b\", \"TEMP_LEFT_BRANCH\", force=True)\n",
"repo.git.checkout(df.iloc[repo_num][\"right\"], force=True)\n",
"repo.submodule_update()\n",
"repo.git.checkout(\"-b\", \"TEMP_RIGHT_BRANCH\", force=True)\n",
"repo_path = repo.git.rev_parse(\"--show-toplevel\")\n",
"\n",
"\n",
"result = subprocess.run([script, repo_path, \"TEMP_LEFT_BRANCH\", \"TEMP_RIGHT_BRANCH\"], stdout=subprocess.PIPE, text=True)\n",
"conflict_file_match = re.search(r'CONFLICT \\(.+\\): Merge conflict in (.+)', result.stdout)\n",
"\n",
"\n",
"if conflict_file_match:\n",
" conflicting_file = conflict_file_match.group(1)\n",
" conflict_path = os.path.join(repo_name, conflicting_file)\n",
" conflict_path_merge_attempt = os.path.join(\"./repos/merge_attempt\", conflict_path)\n",
"\n",
" repo = clone_repo_to_path(repo_name, \"./repos/base\") # Return a Git-Python repo object\n",
" repo.remote().fetch()\n",
" repo.git.checkout(df.iloc[repo_num][\"base\"], force=True)\n",
" repo.submodule_update()\n",
" conflict_path_base = os.path.join(\"./repos/base\", conflict_path)\n",
"\n",
" repo = clone_repo_to_path(repo_name, \"./repos/merge\") # Return a Git-Python repo object\n",
" repo.remote().fetch()\n",
" repo.git.checkout(df.iloc[repo_num][\"merge\"], force=True)\n",
" repo.submodule_update()\n",
" conflict_path_merge = os.path.join(\"./repos/merge\", conflict_path)\n",
"\n",
" diff_results = subprocess.run([\"diff3\", conflict_path_base, conflict_path_merge_attempt, conflict_path_merge], stdout=subprocess.PIPE, text=True)\n",
"\n",
" # Use a temporary file to store the diff results\n",
" with tempfile.NamedTemporaryFile(mode='w+', delete=False) as temp_file:\n",
" temp_file.write(diff_results.stdout)\n",
" temp_file_path = temp_file.name\n",
"\n",
" # Open the saved text file with the default application\n",
" subprocess.run([\"xdg-open\", temp_file_path], check=True)\n",
"\n",
" # Delete the temporary file\n",
" os.remove(temp_file_path)\n",
"\n",
"else:\n",
" print(\"No conflicting file found in the output.\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "AST",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.4"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
221 changes: 221 additions & 0 deletions src/python/benedikt_analysis.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 50,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"import numpy as np\n",
"df = pd.read_csv('../../results/result.csv')\n",
"\n",
"repo_num = 6990\n",
"# merge_tool = \"gitmerge-recursive-patience\"\n",
"# merge_tool = \"gitmerge-recursive-minimal\"\n",
"# merge_tool = \"spork\"\n",
"# merge_tool = \"gitmerge-resolve\"\n",
"# merge_tool = \"intellimerge\"\n",
"# merge_tool = \"gitmerge-ort-ignorespace\"\n",
"merge_tool = \"gitmerge-ort\"\n",
"\n",
"script = \"../scripts/merge_tools/\" + merge_tool + \".sh\""
]
},
{
"cell_type": "code",
"execution_count": 51,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<MERGE_STATE.Tests_passed: 5>"
]
},
"execution_count": 51,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from merge_tester import MERGE_STATE\n",
"df[merge_tool].apply(lambda x: MERGE_STATE[x])[0]"
]
},
{
"cell_type": "code",
"execution_count": 52,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"uniVocity/univocity-parsers : Cloning repo\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Repository 'uniVocity/univocity-parsers' cloned to path: ./repos/uniVocity/univocity-parsers\n",
"uniVocity/univocity-parsers : Finished cloning\n"
]
}
],
"source": [
"from validate_repos import clone_repo\n",
"repo = clone_repo(df.iloc[repo_num][\"repo_name\"]) # Return a Git-Python repo object"
]
},
{
"cell_type": "code",
"execution_count": 53,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"''"
]
},
"execution_count": 53,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# For a git to work you need to pass a name for each branch\n",
"repo.remote().fetch()\n",
"repo.git.checkout(df.iloc[repo_num][\"left\"], force=True)\n",
"repo.submodule_update()\n",
"repo.git.checkout(\"-b\", \"TEMP_LEFT_BRANCH\", force=True)\n",
"repo.git.checkout(df.iloc[repo_num][\"right\"], force=True)\n",
"repo.submodule_update()\n",
"repo.git.checkout(\"-b\", \"TEMP_RIGHT_BRANCH\", force=True)"
]
},
{
"cell_type": "code",
"execution_count": 54,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'/home/benrr/miniconda3/envs/merge/AST-Merging-Ben-Analysis/src/python/repos/uniVocity/univocity-parsers'"
]
},
"execution_count": 54,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"repo_path = repo.git.rev_parse(\"--show-toplevel\")\n",
"repo_path"
]
},
{
"cell_type": "code",
"execution_count": 55,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Path: /home/benrr/miniconda3/envs/merge/AST-Merging-Ben-Analysis/src/python/repos/uniVocity/univocity-parsers\n",
"Running: git merge --no-edit -s ort TEMP_RIGHT_BRANCH\n",
"Auto-merging README.md\n",
"Auto-merging pom.xml\n",
"CONFLICT (content): Merge conflict in pom.xml\n",
"Auto-merging src/test/java/com/univocity/parsers/issues/github/Github_31.java\n",
"CONFLICT (content): Merge conflict in src/test/java/com/univocity/parsers/issues/github/Github_31.java\n",
"Automatic merge failed; fix conflicts and then commit the result.\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"Switched to branch 'TEMP_LEFT_BRANCH'\n"
]
},
{
"data": {
"text/plain": [
"1"
]
},
"execution_count": 55,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import subprocess\n",
"# Returns = 1 process fails\n",
"subprocess.call([script,repo_path,\"TEMP_LEFT_BRANCH\",\"TEMP_RIGHT_BRANCH\"])"
]
},
{
"cell_type": "code",
"execution_count": 56,
"metadata": {},
"outputs": [
{
"ename": "FileNotFoundError",
"evalue": "[Errno 2] No such file or directory: 'cd'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mFileNotFoundError\u001b[0m Traceback (most recent call last)",
"\u001b[1;32m/home/benrr/miniconda3/envs/merge/AST-Merging-Ben-Analysis/src/python/benedikt_analysis.ipynb Cell 7\u001b[0m line \u001b[0;36m1\n\u001b[0;32m----> <a href='vscode-notebook-cell:/home/benrr/miniconda3/envs/merge/AST-Merging-Ben-Analysis/src/python/benedikt_analysis.ipynb#W6sZmlsZQ%3D%3D?line=0'>1</a>\u001b[0m subprocess\u001b[39m.\u001b[39;49mcall([\u001b[39m\"\u001b[39;49m\u001b[39mcd\u001b[39;49m\u001b[39m\"\u001b[39;49m,repo_path,\u001b[39m\"\u001b[39;49m\u001b[39m&&\u001b[39;49m\u001b[39m\"\u001b[39;49m,\u001b[39m\"\u001b[39;49m\u001b[39mgit\u001b[39;49m\u001b[39m\"\u001b[39;49m,\u001b[39m\"\u001b[39;49m\u001b[39mmerge\u001b[39;49m\u001b[39m\"\u001b[39;49m,\u001b[39m\"\u001b[39;49m\u001b[39m--abort\u001b[39;49m\u001b[39m\"\u001b[39;49m])\n",
"File \u001b[0;32m~/miniconda3/lib/python3.11/subprocess.py:389\u001b[0m, in \u001b[0;36mcall\u001b[0;34m(timeout, *popenargs, **kwargs)\u001b[0m\n\u001b[1;32m 381\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39mcall\u001b[39m(\u001b[39m*\u001b[39mpopenargs, timeout\u001b[39m=\u001b[39m\u001b[39mNone\u001b[39;00m, \u001b[39m*\u001b[39m\u001b[39m*\u001b[39mkwargs):\n\u001b[1;32m 382\u001b[0m \u001b[39m \u001b[39m\u001b[39m\"\"\"Run command with arguments. Wait for command to complete or\u001b[39;00m\n\u001b[1;32m 383\u001b[0m \u001b[39m timeout, then return the returncode attribute.\u001b[39;00m\n\u001b[1;32m 384\u001b[0m \n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 387\u001b[0m \u001b[39m retcode = call([\"ls\", \"-l\"])\u001b[39;00m\n\u001b[1;32m 388\u001b[0m \u001b[39m \"\"\"\u001b[39;00m\n\u001b[0;32m--> 389\u001b[0m \u001b[39mwith\u001b[39;00m Popen(\u001b[39m*\u001b[39;49mpopenargs, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mkwargs) \u001b[39mas\u001b[39;00m p:\n\u001b[1;32m 390\u001b[0m \u001b[39mtry\u001b[39;00m:\n\u001b[1;32m 391\u001b[0m \u001b[39mreturn\u001b[39;00m p\u001b[39m.\u001b[39mwait(timeout\u001b[39m=\u001b[39mtimeout)\n",
"File \u001b[0;32m~/miniconda3/lib/python3.11/subprocess.py:1026\u001b[0m, in \u001b[0;36mPopen.__init__\u001b[0;34m(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, user, group, extra_groups, encoding, errors, text, umask, pipesize, process_group)\u001b[0m\n\u001b[1;32m 1022\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mtext_mode:\n\u001b[1;32m 1023\u001b[0m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mstderr \u001b[39m=\u001b[39m io\u001b[39m.\u001b[39mTextIOWrapper(\u001b[39mself\u001b[39m\u001b[39m.\u001b[39mstderr,\n\u001b[1;32m 1024\u001b[0m encoding\u001b[39m=\u001b[39mencoding, errors\u001b[39m=\u001b[39merrors)\n\u001b[0;32m-> 1026\u001b[0m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_execute_child(args, executable, preexec_fn, close_fds,\n\u001b[1;32m 1027\u001b[0m pass_fds, cwd, env,\n\u001b[1;32m 1028\u001b[0m startupinfo, creationflags, shell,\n\u001b[1;32m 1029\u001b[0m p2cread, p2cwrite,\n\u001b[1;32m 1030\u001b[0m c2pread, c2pwrite,\n\u001b[1;32m 1031\u001b[0m errread, errwrite,\n\u001b[1;32m 1032\u001b[0m restore_signals,\n\u001b[1;32m 1033\u001b[0m gid, gids, uid, umask,\n\u001b[1;32m 1034\u001b[0m start_new_session, process_group)\n\u001b[1;32m 1035\u001b[0m \u001b[39mexcept\u001b[39;00m:\n\u001b[1;32m 1036\u001b[0m \u001b[39m# Cleanup if the child failed starting.\u001b[39;00m\n\u001b[1;32m 1037\u001b[0m \u001b[39mfor\u001b[39;00m f \u001b[39min\u001b[39;00m \u001b[39mfilter\u001b[39m(\u001b[39mNone\u001b[39;00m, (\u001b[39mself\u001b[39m\u001b[39m.\u001b[39mstdin, \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mstdout, \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mstderr)):\n",
"File \u001b[0;32m~/miniconda3/lib/python3.11/subprocess.py:1950\u001b[0m, in \u001b[0;36mPopen._execute_child\u001b[0;34m(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, restore_signals, gid, gids, uid, umask, start_new_session, process_group)\u001b[0m\n\u001b[1;32m 1948\u001b[0m \u001b[39mif\u001b[39;00m errno_num \u001b[39m!=\u001b[39m \u001b[39m0\u001b[39m:\n\u001b[1;32m 1949\u001b[0m err_msg \u001b[39m=\u001b[39m os\u001b[39m.\u001b[39mstrerror(errno_num)\n\u001b[0;32m-> 1950\u001b[0m \u001b[39mraise\u001b[39;00m child_exception_type(errno_num, err_msg, err_filename)\n\u001b[1;32m 1951\u001b[0m \u001b[39mraise\u001b[39;00m child_exception_type(err_msg)\n",
"\u001b[0;31mFileNotFoundError\u001b[0m: [Errno 2] No such file or directory: 'cd'"
]
}
],
"source": [
"subprocess.call([\"cd\",repo_path,\"&&\",\"git\",\"merge\",\"--abort\"])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Merge Sucess (Return 0)\n",
"subprocess.call([\"../scripts/merge_tools/gitmerge-ort-ignorespace.sh\",repo_path,\"NAME_OF_LEFT_BRANCH\",\"NAME_OF_RIGHT_BRANCH\"])\n",
"# Be careful the merge has been completed the history of the left branch has now changed and you can't \n",
"# merge again unless you delete the repo and clone it again"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "AST",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.4"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Loading
Loading