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

cloning only target branch with depth 1 #16

Merged
merged 5 commits into from
Mar 1, 2024
Merged
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
41 changes: 33 additions & 8 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,36 @@ def is_git_directory(dir):
git_dir_path = os.path.join(dir, '.git')
return os.path.exists(git_dir_path) and os.path.isdir(git_dir_path)

def get_target_data(url, branch, commit, directory):
'''
Get target repository data

Parameters:
url (str): repository url
branch(str): branch name
commit(str): commit #
directory (str): directory to clone in
'''
project_name = get_repository_name(url)
if (os.path.exists(os.path.join(directory, project_name))):
print(f"{project_name} repository already exists. Aborting cloning")
return

clone_command = ["git", "clone"]
if branch:
clone_command.extend(["-b", branch])
if not commit:
clone_command.extend(["--depth", "1"])
clone_command.append(url)
subprocess.run(clone_command, cwd=directory) # targetted clone is fast, no need to reuse existing one.
else:
clone_command.append(url)
subprocess.run(clone_command, cwd=directory)
checkout_commit(commit, os.path.join(directory, get_repository_name(url)))

cmd_str = ' '.join(clone_command)
print(f"get_target_data -> {cmd_str}")

def clone_repository(url, directory):
'''
Clone a repository from 'url' in 'directory'
Expand Down Expand Up @@ -171,7 +201,7 @@ def clone_specimin(path_to_clone, url):
if (os.path.exists(spcimin_source_path)) and os.path.isdir(spcimin_source_path):
perform_git_pull(spcimin_source_path)
else:
clone_repository(url, path_to_clone)
get_target_data(url, "", "", path_to_clone)


def build_specimin_command(project_name: str,
Expand Down Expand Up @@ -299,15 +329,10 @@ def performEvaluation(issue_data) -> Result:

issue_folder_abs_dir = os.path.abspath(issue_folder_dir)
input_dir = create_issue_directory(issue_folder_abs_dir, issue_id)
clone_repository(url, input_dir)
repo_name = get_repository_name(url)

if branch:
change_branch(branch, os.path.join(input_dir, repo_name))
get_target_data(url, branch, commit_hash, input_dir)

if commit_hash:
checkout_commit(commit_hash, os.path.join(input_dir, repo_name))

repo_name = get_repository_name(url)
specimin_command = ""
result: Result = None
specimin_path = get_specimin_env_var()
Expand Down
16 changes: 8 additions & 8 deletions resources/test_data.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[
{
"issue_id" : "cf-1291",
"url": "https://github.com/codespecs/daikon.git",
"branch": "",
"commit_hash": "15d7c2d84",
"url": "https://github.com/tahiat/daikon.git",
"branch": "cf-1291",
"commit_hash": "",
"project_name": "daikon",
"build_command": "this can be cf command or java",
"root_dir": "java",
Expand Down Expand Up @@ -39,9 +39,9 @@
},
{
"issue_id" : "cf-6077",
"url": "https://github.com/jacek-lewandowski/cassandra.git",
"branch": "checker-framework-testing",
"commit_hash": "7b3c4ce8e5d6da41791492903ec367b8857cd57d",
"url": "https://github.com/tahiat/cassandra.git",
"branch": "cf-6077",
"commit_hash": "",
"project_name": "cassandra",
"build_command": "ant cf-only -Dcf.check.only=org/apache/cassandra/index/sasi/conf/IndexMode.java",
"root_dir": "src/java",
Expand Down Expand Up @@ -328,8 +328,8 @@
},
{
"issue_id" : "cf-6388",
"url": "https://github.com/kennknowles/beam.git",
"branch": "checkerframework-StructuralEqualityComparer",
"url": "https://github.com/tahiat/beam.git",
"branch": "cf-6388",
"commit_hash": "",
"project_name": "beam",
"build_command": "checkerframework-StructuralEqualityComparer",
Expand Down
Loading