vendor/libgit2/src/clone.c in rugged-0.27.9 vs vendor/libgit2/src/clone.c in rugged-0.27.10

- old
+ new

@@ -5,23 +5,21 @@ * a Linking Exception. For full terms see the included COPYING file. */ #include "clone.h" -#include <assert.h> - #include "git2/clone.h" #include "git2/remote.h" #include "git2/revparse.h" #include "git2/branch.h" #include "git2/config.h" #include "git2/checkout.h" #include "git2/commit.h" #include "git2/tree.h" #include "remote.h" -#include "fileops.h" +#include "futils.h" #include "refs.h" #include "path.h" #include "repository.h" #include "odb.h" @@ -46,11 +44,11 @@ /* Create the new branch */ if ((error = git_buf_printf(&refname, GIT_REFS_HEADS_DIR "%s", name)) < 0) return error; error = git_reference_create(&branch_ref, repo, git_buf_cstr(&refname), target, 0, log_message); - git_buf_free(&refname); + git_buf_dispose(&refname); git_commit_free(head_obj); if (!error) *branch = branch_ref; else @@ -85,12 +83,12 @@ goto cleanup; error = 0; cleanup: - git_buf_free(&remote_key); - git_buf_free(&merge_key); + git_buf_dispose(&remote_key); + git_buf_dispose(&merge_key); return error; } static int create_tracking_branch( git_reference **branch, @@ -174,11 +172,11 @@ } refspec = git_remote__matching_refspec(remote, git_buf_cstr(&branch)); if (refspec == NULL) { - giterr_set(GITERR_NET, "the remote's default branch does not fit the refspec configuration"); + git_error_set(GIT_ERROR_NET, "the remote's default branch does not fit the refspec configuration"); error = GIT_EINVALIDSPEC; goto cleanup; } /* Determine the remote tracking reference name from the local master */ @@ -193,12 +191,12 @@ remote_head_id, git_buf_cstr(&branch), reflog_message); cleanup: - git_buf_free(&remote_master_name); - git_buf_free(&branch); + git_buf_dispose(&remote_master_name); + git_buf_dispose(&branch); return error; } static int update_head_to_branch( @@ -223,11 +221,11 @@ retcode = update_head_to_new_branch(repo, git_reference_target(remote_ref), branch, reflog_message); cleanup: git_reference_free(remote_ref); - git_buf_free(&remote_branch_name); + git_buf_dispose(&remote_branch_name); return retcode; } static int default_repository_create(git_repository **out, const char *path, int bare, void *payload) { @@ -330,11 +328,11 @@ git_remote *remote; assert(repo && _remote); if (!git_repository_is_empty(repo)) { - giterr_set(GITERR_INVALID, "the repository is not empty"); + git_error_set(GIT_ERROR_INVALID, "the repository is not empty"); return -1; } if ((error = git_remote_dup(&remote, _remote)) < 0) return error; @@ -349,11 +347,11 @@ error = checkout_branch(repo, remote, co_opts, branch, git_buf_cstr(&reflog_message)); cleanup: git_remote_free(remote); - git_buf_free(&reflog_message); + git_buf_dispose(&reflog_message); return error; } int git_clone__should_clone_local(const char *url_or_path, git_clone_local_t local) @@ -376,19 +374,20 @@ is_local = (!is_url || local != GIT_CLONE_LOCAL_AUTO) && git_path_isdir(path); done: - git_buf_free(&fromurl); + git_buf_dispose(&fromurl); return is_local; } -int git_clone( +static int git__clone( git_repository **out, const char *url, const char *local_path, - const git_clone_options *_options) + const git_clone_options *_options, + int use_existing) { int error = 0; git_repository *repo = NULL; git_remote *origin; git_clone_options options = GIT_CLONE_OPTIONS_INIT; @@ -398,15 +397,15 @@ assert(out && url && local_path); if (_options) memcpy(&options, _options, sizeof(git_clone_options)); - GITERR_CHECK_VERSION(&options, GIT_CLONE_OPTIONS_VERSION, "git_clone_options"); + GIT_ERROR_CHECK_VERSION(&options, GIT_CLONE_OPTIONS_VERSION, "git_clone_options"); /* Only clone to a new directory or an empty directory */ - if (git_path_exists(local_path) && !git_path_is_empty_dir(local_path)) { - giterr_set(GITERR_INVALID, + if (git_path_exists(local_path) && !use_existing && !git_path_is_empty_dir(local_path)) { + git_error_set(GIT_ERROR_INVALID, "'%s' exists and is not an empty directory", local_path); return GIT_EEXISTS; } /* Only remove the root directory on failure if we create it */ @@ -439,31 +438,54 @@ git_remote_free(origin); } if (error != 0) { git_error_state last_error = {0}; - giterr_state_capture(&last_error, error); + git_error_state_capture(&last_error, error); git_repository_free(repo); repo = NULL; (void)git_futils_rmdir_r(local_path, NULL, rmdir_flags); - giterr_state_restore(&last_error); + git_error_state_restore(&last_error); } *out = repo; return error; } -int git_clone_init_options(git_clone_options *opts, unsigned int version) +int git_clone( + git_repository **out, + const char *url, + const char *local_path, + const git_clone_options *_options) { + return git__clone(out, url, local_path, _options, 0); +} + +int git_clone__submodule( + git_repository **out, + const char *url, + const char *local_path, + const git_clone_options *_options) +{ + return git__clone(out, url, local_path, _options, 1); +} + +int git_clone_options_init(git_clone_options *opts, unsigned int version) +{ GIT_INIT_STRUCTURE_FROM_TEMPLATE( opts, version, git_clone_options, GIT_CLONE_OPTIONS_INIT); return 0; } +int git_clone_init_options(git_clone_options *opts, unsigned int version) +{ + return git_clone_options_init(opts, version); +} + static bool can_link(const char *src, const char *dst, int link) { #ifdef GIT_WIN32 GIT_UNUSED(src); GIT_UNUSED(dst); @@ -494,11 +516,11 @@ git_buf reflog_message = GIT_BUF_INIT; assert(repo && remote); if (!git_repository_is_empty(repo)) { - giterr_set(GITERR_INVALID, "the repository is not empty"); + git_error_set(GIT_ERROR_INVALID, "the repository is not empty"); return -1; } /* * Let's figure out what path we should use for the source @@ -508,11 +530,11 @@ if ((error = git_path_from_url_or_path(&src_path, git_remote_url(remote))) < 0) return error; /* Copy .git/objects/ from the source to the target */ if ((error = git_repository_open(&src, git_buf_cstr(&src_path))) < 0) { - git_buf_free(&src_path); + git_buf_dispose(&src_path); return error; } if (git_repository_item_path(&src_odb, src, GIT_REPOSITORY_ITEM_OBJECTS) < 0 || git_repository_item_path(&dst_odb, repo, GIT_REPOSITORY_ITEM_OBJECTS) < 0) { @@ -547,12 +569,12 @@ goto cleanup; error = checkout_branch(repo, remote, co_opts, branch, git_buf_cstr(&reflog_message)); cleanup: - git_buf_free(&reflog_message); - git_buf_free(&src_path); - git_buf_free(&src_odb); - git_buf_free(&dst_odb); + git_buf_dispose(&reflog_message); + git_buf_dispose(&src_path); + git_buf_dispose(&src_odb); + git_buf_dispose(&dst_odb); git_repository_free(src); return error; }