vendor/libgit2/src/clone.c in rugged-1.3.2.3 vs vendor/libgit2/src/clone.c in rugged-1.4.2
- old
+ new
@@ -17,11 +17,11 @@
#include "git2/tree.h"
#include "remote.h"
#include "futils.h"
#include "refs.h"
-#include "path.h"
+#include "fs_path.h"
#include "repository.h"
#include "odb.h"
static int clone_local_into(git_repository *repo, git_remote *remote, const git_fetch_options *fetch_opts, const git_checkout_options *co_opts, const char *branch, int link);
@@ -32,23 +32,23 @@
const char *name,
const char *log_message)
{
git_commit *head_obj = NULL;
git_reference *branch_ref = NULL;
- git_buf refname = GIT_BUF_INIT;
+ git_str refname = GIT_STR_INIT;
int error;
/* Find the target commit */
if ((error = git_commit_lookup(&head_obj, repo, target)) < 0)
return error;
/* Create the new branch */
- if ((error = git_buf_printf(&refname, GIT_REFS_HEADS_DIR "%s", name)) < 0)
+ if ((error = git_str_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_dispose(&refname);
+ error = git_reference_create(&branch_ref, repo, git_str_cstr(&refname), target, 0, log_message);
+ git_str_dispose(&refname);
git_commit_free(head_obj);
if (!error)
*branch = branch_ref;
else
@@ -62,33 +62,33 @@
const char *branch_name,
const char *remote_name,
const char *merge_target)
{
git_config *cfg;
- git_buf remote_key = GIT_BUF_INIT, merge_key = GIT_BUF_INIT;
+ git_str remote_key = GIT_STR_INIT, merge_key = GIT_STR_INIT;
int error = -1;
if (git_repository_config__weakptr(&cfg, repo) < 0)
return -1;
- if (git_buf_printf(&remote_key, "branch.%s.remote", branch_name) < 0)
+ if (git_str_printf(&remote_key, "branch.%s.remote", branch_name) < 0)
goto cleanup;
- if (git_buf_printf(&merge_key, "branch.%s.merge", branch_name) < 0)
+ if (git_str_printf(&merge_key, "branch.%s.merge", branch_name) < 0)
goto cleanup;
- if (git_config_set_string(cfg, git_buf_cstr(&remote_key), remote_name) < 0)
+ if (git_config_set_string(cfg, git_str_cstr(&remote_key), remote_name) < 0)
goto cleanup;
- if (git_config_set_string(cfg, git_buf_cstr(&merge_key), merge_target) < 0)
+ if (git_config_set_string(cfg, git_str_cstr(&merge_key), merge_target) < 0)
goto cleanup;
error = 0;
cleanup:
- git_buf_dispose(&remote_key);
- git_buf_dispose(&merge_key);
+ git_str_dispose(&remote_key);
+ git_str_dispose(&merge_key);
return error;
}
static int create_tracking_branch(
git_reference **branch,
@@ -137,11 +137,11 @@
return error;
}
static int update_head_to_default(git_repository *repo)
{
- git_buf initialbranch = GIT_BUF_INIT;
+ git_str initialbranch = GIT_STR_INIT;
const char *branch_name;
int error = 0;
if ((error = git_repository_initialbranch(&initialbranch, repo)) < 0)
goto done;
@@ -156,60 +156,60 @@
error = setup_tracking_config(repo, branch_name, GIT_REMOTE_ORIGIN,
initialbranch.ptr);
done:
- git_buf_dispose(&initialbranch);
+ git_str_dispose(&initialbranch);
return error;
}
static int update_remote_head(
git_repository *repo,
git_remote *remote,
- git_buf *target,
+ git_str *target,
const char *reflog_message)
{
git_refspec *refspec;
git_reference *remote_head = NULL;
- git_buf remote_head_name = GIT_BUF_INIT;
- git_buf remote_branch_name = GIT_BUF_INIT;
+ git_str remote_head_name = GIT_STR_INIT;
+ git_str remote_branch_name = GIT_STR_INIT;
int error;
/* Determine the remote tracking ref name from the local branch */
- refspec = git_remote__matching_refspec(remote, git_buf_cstr(target));
+ refspec = git_remote__matching_refspec(remote, git_str_cstr(target));
if (refspec == NULL) {
git_error_set(GIT_ERROR_NET, "the remote's default branch does not fit the refspec configuration");
error = GIT_EINVALIDSPEC;
goto cleanup;
}
- if ((error = git_refspec_transform(
+ if ((error = git_refspec__transform(
&remote_branch_name,
refspec,
- git_buf_cstr(target))) < 0)
+ git_str_cstr(target))) < 0)
goto cleanup;
- if ((error = git_buf_printf(&remote_head_name,
+ if ((error = git_str_printf(&remote_head_name,
"%s%s/%s",
GIT_REFS_REMOTES_DIR,
git_remote_name(remote),
GIT_HEAD_FILE)) < 0)
goto cleanup;
error = git_reference_symbolic_create(
&remote_head,
repo,
- git_buf_cstr(&remote_head_name),
- git_buf_cstr(&remote_branch_name),
+ git_str_cstr(&remote_head_name),
+ git_str_cstr(&remote_branch_name),
true,
reflog_message);
cleanup:
git_reference_free(remote_head);
- git_buf_dispose(&remote_branch_name);
- git_buf_dispose(&remote_head_name);
+ git_str_dispose(&remote_branch_name);
+ git_str_dispose(&remote_head_name);
return error;
}
static int update_head_to_remote(
git_repository *repo,
@@ -218,11 +218,11 @@
{
int error = 0;
size_t refs_len;
const git_remote_head *remote_head, **refs;
const git_oid *remote_head_id;
- git_buf branch = GIT_BUF_INIT;
+ git_str branch = GIT_STR_INIT;
if ((error = git_remote_ls(&refs, &refs_len, remote)) < 0)
return error;
/* We cloned an empty repository or one with an unborn HEAD */
@@ -233,11 +233,11 @@
remote_head = refs[0];
GIT_ASSERT(remote_head);
remote_head_id = &remote_head->oid;
- error = git_remote_default_branch(&branch, remote);
+ error = git_remote__default_branch(&branch, remote);
if (error == GIT_ENOTFOUND) {
error = git_repository_set_head_detached(
repo, remote_head_id);
goto cleanup;
}
@@ -246,15 +246,15 @@
goto cleanup;
error = update_head_to_new_branch(
repo,
remote_head_id,
- git_buf_cstr(&branch),
+ git_str_cstr(&branch),
reflog_message);
cleanup:
- git_buf_dispose(&branch);
+ git_str_dispose(&branch);
return error;
}
static int update_head_to_branch(
@@ -262,40 +262,40 @@
git_remote *remote,
const char *branch,
const char *reflog_message)
{
int retcode;
- git_buf remote_branch_name = GIT_BUF_INIT;
+ git_str remote_branch_name = GIT_STR_INIT;
git_reference *remote_ref = NULL;
- git_buf default_branch = GIT_BUF_INIT;
+ git_str default_branch = GIT_STR_INIT;
GIT_ASSERT_ARG(remote);
GIT_ASSERT_ARG(branch);
- if ((retcode = git_buf_printf(&remote_branch_name, GIT_REFS_REMOTES_DIR "%s/%s",
+ if ((retcode = git_str_printf(&remote_branch_name, GIT_REFS_REMOTES_DIR "%s/%s",
git_remote_name(remote), branch)) < 0 )
goto cleanup;
- if ((retcode = git_reference_lookup(&remote_ref, repo, git_buf_cstr(&remote_branch_name))) < 0)
+ if ((retcode = git_reference_lookup(&remote_ref, repo, git_str_cstr(&remote_branch_name))) < 0)
goto cleanup;
if ((retcode = update_head_to_new_branch(repo, git_reference_target(remote_ref), branch,
reflog_message)) < 0)
goto cleanup;
- if ((retcode = git_remote_default_branch(&default_branch, remote)) < 0)
+ if ((retcode = git_remote__default_branch(&default_branch, remote)) < 0)
goto cleanup;
- if (!git_remote__matching_refspec(remote, git_buf_cstr(&default_branch)))
+ if (!git_remote__matching_refspec(remote, git_str_cstr(&default_branch)))
goto cleanup;
retcode = update_remote_head(repo, remote, &default_branch, reflog_message);
cleanup:
git_reference_free(remote_ref);
- git_buf_dispose(&remote_branch_name);
- git_buf_dispose(&default_branch);
+ git_str_dispose(&remote_branch_name);
+ git_str_dispose(&default_branch);
return retcode;
}
static int default_repository_create(git_repository **out, const char *path, int bare, void *payload)
{
@@ -331,11 +331,11 @@
char buf[GIT_PATH_MAX];
git_remote_create_cb remote_create = options->remote_cb;
void *payload = options->remote_cb_payload;
/* If the path exists and is a dir, the url should be the absolute path */
- if (git_path_root(url) < 0 && git_path_exists(url) && git_path_isdir(url)) {
+ if (git_fs_path_root(url) < 0 && git_fs_path_exists(url) && git_fs_path_isdir(url)) {
if (p_realpath(url, buf) == NULL)
return -1;
url = buf;
}
@@ -390,11 +390,11 @@
}
static int clone_into(git_repository *repo, git_remote *_remote, const git_fetch_options *opts, const git_checkout_options *co_opts, const char *branch)
{
int error;
- git_buf reflog_message = GIT_BUF_INIT;
+ git_str reflog_message = GIT_STR_INIT;
git_fetch_options fetch_opts;
git_remote *remote;
GIT_ASSERT_ARG(repo);
GIT_ASSERT_ARG(_remote);
@@ -408,47 +408,47 @@
return error;
memcpy(&fetch_opts, opts, sizeof(git_fetch_options));
fetch_opts.update_fetchhead = 0;
fetch_opts.download_tags = GIT_REMOTE_DOWNLOAD_TAGS_ALL;
- git_buf_printf(&reflog_message, "clone: from %s", git_remote_url(remote));
+ git_str_printf(&reflog_message, "clone: from %s", git_remote_url(remote));
- if ((error = git_remote_fetch(remote, NULL, &fetch_opts, git_buf_cstr(&reflog_message))) != 0)
+ if ((error = git_remote_fetch(remote, NULL, &fetch_opts, git_str_cstr(&reflog_message))) != 0)
goto cleanup;
- error = checkout_branch(repo, remote, co_opts, branch, git_buf_cstr(&reflog_message));
+ error = checkout_branch(repo, remote, co_opts, branch, git_str_cstr(&reflog_message));
cleanup:
git_remote_free(remote);
- git_buf_dispose(&reflog_message);
+ git_str_dispose(&reflog_message);
return error;
}
int git_clone__should_clone_local(const char *url_or_path, git_clone_local_t local)
{
- git_buf fromurl = GIT_BUF_INIT;
+ git_str fromurl = GIT_STR_INIT;
const char *path = url_or_path;
bool is_url, is_local;
if (local == GIT_CLONE_NO_LOCAL)
return 0;
- if ((is_url = git_path_is_local_file_url(url_or_path)) != 0) {
- if (git_path_fromurl(&fromurl, url_or_path) < 0) {
+ if ((is_url = git_fs_path_is_local_file_url(url_or_path)) != 0) {
+ if (git_fs_path_fromurl(&fromurl, url_or_path) < 0) {
is_local = -1;
goto done;
}
path = fromurl.ptr;
}
is_local = (!is_url || local != GIT_CLONE_LOCAL_AUTO) &&
- git_path_isdir(path);
+ git_fs_path_isdir(path);
done:
- git_buf_dispose(&fromurl);
+ git_str_dispose(&fromurl);
return is_local;
}
static int git__clone(
git_repository **out,
@@ -472,18 +472,18 @@
memcpy(&options, _options, sizeof(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) && !use_existing && !git_path_is_empty_dir(local_path)) {
+ if (git_fs_path_exists(local_path) && !use_existing && !git_fs_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 */
- if (git_path_exists(local_path))
+ if (git_fs_path_exists(local_path))
rmdir_flags |= GIT_RMDIR_SKIP_ROOT;
if (options.repository_cb)
repository_cb = options.repository_cb;
else
@@ -584,12 +584,12 @@
static int clone_local_into(git_repository *repo, git_remote *remote, const git_fetch_options *fetch_opts, const git_checkout_options *co_opts, const char *branch, int link)
{
int error, flags;
git_repository *src;
- git_buf src_odb = GIT_BUF_INIT, dst_odb = GIT_BUF_INIT, src_path = GIT_BUF_INIT;
- git_buf reflog_message = GIT_BUF_INIT;
+ git_str src_odb = GIT_STR_INIT, dst_odb = GIT_STR_INIT, src_path = GIT_STR_INIT;
+ git_str reflog_message = GIT_STR_INIT;
GIT_ASSERT_ARG(repo);
GIT_ASSERT_ARG(remote);
if (!git_repository_is_empty(repo)) {
@@ -600,56 +600,56 @@
/*
* Let's figure out what path we should use for the source
* repo, if it's not rooted, the path should be relative to
* the repository's worktree/gitdir.
*/
- if ((error = git_path_from_url_or_path(&src_path, git_remote_url(remote))) < 0)
+ if ((error = git_fs_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_dispose(&src_path);
+ if ((error = git_repository_open(&src, git_str_cstr(&src_path))) < 0) {
+ git_str_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) {
+ 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) {
error = -1;
goto cleanup;
}
flags = 0;
if (can_link(git_repository_path(src), git_repository_path(repo), link))
flags |= GIT_CPDIR_LINK_FILES;
- error = git_futils_cp_r(git_buf_cstr(&src_odb), git_buf_cstr(&dst_odb),
+ error = git_futils_cp_r(git_str_cstr(&src_odb), git_str_cstr(&dst_odb),
flags, GIT_OBJECT_DIR_MODE);
/*
* can_link() doesn't catch all variations, so if we hit an
* error and did want to link, let's try again without trying
* to link.
*/
if (error < 0 && link) {
flags &= ~GIT_CPDIR_LINK_FILES;
- error = git_futils_cp_r(git_buf_cstr(&src_odb), git_buf_cstr(&dst_odb),
+ error = git_futils_cp_r(git_str_cstr(&src_odb), git_str_cstr(&dst_odb),
flags, GIT_OBJECT_DIR_MODE);
}
if (error < 0)
goto cleanup;
- git_buf_printf(&reflog_message, "clone: from %s", git_remote_url(remote));
+ git_str_printf(&reflog_message, "clone: from %s", git_remote_url(remote));
- if ((error = git_remote_fetch(remote, NULL, fetch_opts, git_buf_cstr(&reflog_message))) != 0)
+ if ((error = git_remote_fetch(remote, NULL, fetch_opts, git_str_cstr(&reflog_message))) != 0)
goto cleanup;
- error = checkout_branch(repo, remote, co_opts, branch, git_buf_cstr(&reflog_message));
+ error = checkout_branch(repo, remote, co_opts, branch, git_str_cstr(&reflog_message));
cleanup:
- git_buf_dispose(&reflog_message);
- git_buf_dispose(&src_path);
- git_buf_dispose(&src_odb);
- git_buf_dispose(&dst_odb);
+ git_str_dispose(&reflog_message);
+ git_str_dispose(&src_path);
+ git_str_dispose(&src_odb);
+ git_str_dispose(&dst_odb);
git_repository_free(src);
return error;
}