summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/git2.h1
-rw-r--r--include/git2/clone.h13
-rw-r--r--include/git2/push.h94
-rw-r--r--include/git2/remote.h281
-rw-r--r--include/git2/submodule.h8
-rw-r--r--include/git2/sys/transport.h2
-rw-r--r--src/clone.c30
-rw-r--r--src/fetch.c19
-rw-r--r--src/fetch.h2
-rw-r--r--src/push.c29
-rw-r--r--src/push.h4
-rw-r--r--src/remote.c123
-rw-r--r--src/remote.h1
-rw-r--r--src/submodule.c2
-rw-r--r--src/transports/local.c8
-rw-r--r--src/transports/smart.h2
-rw-r--r--src/transports/smart_protocol.c7
-rw-r--r--tests/checkout/index.c4
-rw-r--r--tests/clone/empty.c4
-rw-r--r--tests/clone/nonetwork.c6
-rw-r--r--tests/fetchhead/nonetwork.c2
-rw-r--r--tests/network/fetchlocal.c117
-rw-r--r--tests/network/remote/defaultbranch.c6
-rw-r--r--tests/network/remote/local.c47
-rw-r--r--tests/network/remote/remotes.c10
-rw-r--r--tests/online/clone.c61
-rw-r--r--tests/online/fetch.c54
-rw-r--r--tests/online/fetchhead.c9
-rw-r--r--tests/online/push.c20
-rw-r--r--tests/submodule/update.c4
30 files changed, 459 insertions, 511 deletions
diff --git a/include/git2.h b/include/git2.h
index cf6b5cb89..a1e78376f 100644
--- a/include/git2.h
+++ b/include/git2.h
@@ -40,7 +40,6 @@
#include "git2/pack.h"
#include "git2/patch.h"
#include "git2/pathspec.h"
-#include "git2/push.h"
#include "git2/rebase.h"
#include "git2/refdb.h"
#include "git2/reflog.h"
diff --git a/include/git2/clone.h b/include/git2/clone.h
index d3bd42485..9e23aaccb 100644
--- a/include/git2/clone.h
+++ b/include/git2/clone.h
@@ -111,13 +111,12 @@ typedef struct git_clone_options {
git_checkout_options checkout_opts;
/**
- * Callbacks to use for reporting fetch progress, and for acquiring
- * credentials in the event they are needed. This parameter is ignored if
- * the remote_cb parameter is set; if you provide a remote creation
- * callback, then you have the opportunity to configure remote callbacks in
- * provided function.
+ * Options which control the fetch, including callbacks.
+ *
+ * The callbacks are used for reporting fetch progress, and for acquiring
+ * credentials in the event they are needed.
*/
- git_remote_callbacks remote_callbacks;
+ git_fetch_options fetch_opts;
/**
* Set to zero (false) to create a standard repo, or non-zero
@@ -167,7 +166,7 @@ typedef struct git_clone_options {
#define GIT_CLONE_OPTIONS_VERSION 1
#define GIT_CLONE_OPTIONS_INIT { GIT_CLONE_OPTIONS_VERSION, \
{ GIT_CHECKOUT_OPTIONS_VERSION, GIT_CHECKOUT_SAFE }, \
- GIT_REMOTE_CALLBACKS_INIT }
+ GIT_FETCH_OPTIONS_INIT }
/**
* Initializes a `git_clone_options` with default values. Equivalent to
diff --git a/include/git2/push.h b/include/git2/push.h
deleted file mode 100644
index 3f850453d..000000000
--- a/include/git2/push.h
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * Copyright (C) the libgit2 contributors. All rights reserved.
- *
- * This file is part of libgit2, distributed under the GNU GPL v2 with
- * a Linking Exception. For full terms see the included COPYING file.
- */
-#ifndef INCLUDE_git_push_h__
-#define INCLUDE_git_push_h__
-
-#include "common.h"
-#include "pack.h"
-
-/**
- * @file git2/push.h
- * @brief Git push management functions
- * @defgroup git_push push management functions
- * @ingroup Git
- * @{
- */
-GIT_BEGIN_DECL
-
-/**
- * Controls the behavior of a git_push object.
- */
-typedef struct {
- unsigned int version;
-
- /**
- * If the transport being used to push to the remote requires the creation
- * of a pack file, this controls the number of worker threads used by
- * the packbuilder when creating that pack file to be sent to the remote.
- *
- * If set to 0, the packbuilder will auto-detect the number of threads
- * to create. The default value is 1.
- */
- unsigned int pb_parallelism;
-} git_push_options;
-
-#define GIT_PUSH_OPTIONS_VERSION 1
-#define GIT_PUSH_OPTIONS_INIT { GIT_PUSH_OPTIONS_VERSION }
-
-/**
- * Initializes a `git_push_options` with default values. Equivalent to
- * creating an instance with GIT_PUSH_OPTIONS_INIT.
- *
- * @param opts the `git_push_options` instance to initialize.
- * @param version the version of the struct; you should pass
- * `GIT_PUSH_OPTIONS_VERSION` here.
- * @return Zero on success; -1 on failure.
- */
-GIT_EXTERN(int) git_push_init_options(
- git_push_options *opts,
- unsigned int version);
-
-/** Push network progress notification function */
-typedef int (*git_push_transfer_progress)(
- unsigned int current,
- unsigned int total,
- size_t bytes,
- void* payload);
-
-/**
- * Represents an update which will be performed on the remote during push
- */
-typedef struct {
- /**
- * The source name of the reference
- */
- char *src_refname;
- /**
- * The name of the reference to update on the server
- */
- char *dst_refname;
- /**
- * The current target of the reference
- */
- git_oid src;
- /**
- * The new target for the reference
- */
- git_oid dst;
-} git_push_update;
-
-/**
- * @param updates an array containing the updates which will be sent
- * as commands to the destination.
- * @param len number of elements in `updates`
- * @param payload Payload provided by the caller
- */
-typedef int (*git_push_negotiation)(const git_push_update **updates, size_t len, void *payload);
-
-/** @} */
-GIT_END_DECL
-#endif
diff --git a/include/git2/remote.h b/include/git2/remote.h
index 6e88a4680..5aea777c1 100644
--- a/include/git2/remote.h
+++ b/include/git2/remote.h
@@ -14,7 +14,7 @@
#include "indexer.h"
#include "strarray.h"
#include "transport.h"
-#include "push.h"
+#include "pack.h"
/**
* @file git2/remote.h
@@ -276,9 +276,10 @@ GIT_EXTERN(const git_refspec *)git_remote_get_refspec(const git_remote *remote,
* @param remote the remote to connect to
* @param direction GIT_DIRECTION_FETCH if you want to fetch or
* GIT_DIRECTION_PUSH if you want to push
+ * @param callbacks the callbacks to use for this connection
* @return 0 or an error code
*/
-GIT_EXTERN(int) git_remote_connect(git_remote *remote, git_direction direction);
+GIT_EXTERN(int) git_remote_connect(git_remote *remote, git_direction direction, const git_remote_callbacks *callbacks);
/**
* Get the remote repository's reference advertisement list
@@ -303,36 +304,6 @@ GIT_EXTERN(int) git_remote_connect(git_remote *remote, git_direction direction);
GIT_EXTERN(int) git_remote_ls(const git_remote_head ***out, size_t *size, git_remote *remote);
/**
- * Download and index the packfile
- *
- * Connect to the remote if it hasn't been done yet, negotiate with
- * the remote git which objects are missing, download and index the
- * packfile.
- *
- * The .idx file will be created and both it and the packfile with be
- * renamed to their final name.
- *
- * @param remote the remote
- * @param refspecs the refspecs to use for this negotiation and
- * download. Use NULL or an empty array to use the base refspecs
- * @return 0 or an error code
- */
-GIT_EXTERN(int) git_remote_download(git_remote *remote, const git_strarray *refspecs);
-
-/**
- * Create a packfile and send it to the server
- *
- * Connect to the remote if it hasn't been done yet, negotiate with
- * the remote git which objects are missing, create a packfile with the missing objects and send it.
- *
- * @param remote the remote
- * @param refspecs the refspecs to use for this negotiation and
- * upload. Use NULL or an empty array to use the base refspecs
- * @return 0 or an error code
- */
-GIT_EXTERN(int) git_remote_upload(git_remote *remote, const git_strarray *refspecs, const git_push_options *opts);
-
-/**
* Check whether the remote is connected
*
* Check whether the remote's underlying transport is connected to the
@@ -373,60 +344,6 @@ GIT_EXTERN(void) git_remote_disconnect(git_remote *remote);
GIT_EXTERN(void) git_remote_free(git_remote *remote);
/**
- * Update the tips to the new state
- *
- * @param remote the remote to update
- * @param reflog_message The message to insert into the reflogs. If
- * NULL and fetching, the default is "fetch <name>", where <name> is
- * the name of the remote (or its url, for in-memory remotes). This
- * parameter is ignored when pushing.
- * @return 0 or an error code
- */
-GIT_EXTERN(int) git_remote_update_tips(
- git_remote *remote,
- const char *reflog_message);
-
-/**
- * Prune tracking refs that are no longer present on remote
- *
- * @param remote the remote to prune
- * @return 0 or an error code
- */
-GIT_EXTERN(int) git_remote_prune(git_remote *remote);
-
-/**
- * Download new data and update tips
- *
- * Convenience function to connect to a remote, download the data,
- * disconnect and update the remote-tracking branches.
- *
- * @param remote the remote to fetch from
- * @param refspecs the refspecs to use for this fetch. Pass NULL or an
- * empty array to use the base refspecs.
- * @param reflog_message The message to insert into the reflogs. If NULL, the
- * default is "fetch"
- * @return 0 or an error code
- */
-GIT_EXTERN(int) git_remote_fetch(
- git_remote *remote,
- const git_strarray *refspecs,
- const char *reflog_message);
-
-/**
- * Perform a push
- *
- * Peform all the steps from a push.
- *
- * @param remote the remote to push to
- * @param refspecs the refspecs to use for pushing. If none are
- * passed, the configured refspecs will be used
- * @param opts the options
- */
-GIT_EXTERN(int) git_remote_push(git_remote *remote,
- const git_strarray *refspecs,
- const git_push_options *opts);
-
-/**
* Get a list of the configured remotes for a repo
*
* The string array must be freed by the user.
@@ -447,6 +364,42 @@ typedef enum git_remote_completion_type {
GIT_REMOTE_COMPLETION_ERROR,
} git_remote_completion_type;
+/** Push network progress notification function */
+typedef int (*git_push_transfer_progress)(
+ unsigned int current,
+ unsigned int total,
+ size_t bytes,
+ void* payload);
+/**
+ * Represents an update which will be performed on the remote during push
+ */
+typedef struct {
+ /**
+ * The source name of the reference
+ */
+ char *src_refname;
+ /**
+ * The name of the reference to update on the server
+ */
+ char *dst_refname;
+ /**
+ * The current target of the reference
+ */
+ git_oid src;
+ /**
+ * The new target for the reference
+ */
+ git_oid dst;
+} git_push_update;
+
+/**
+ * @param updates an array containing the updates which will be sent
+ * as commands to the destination.
+ * @param len number of elements in `updates`
+ * @param payload Payload provided by the caller
+ */
+typedef int (*git_push_negotiation)(const git_push_update **updates, size_t len, void *payload);
+
/**
* The callback settings structure
*
@@ -548,28 +501,160 @@ GIT_EXTERN(int) git_remote_init_callbacks(
git_remote_callbacks *opts,
unsigned int version);
+typedef struct {
+ int version;
+
+ /**
+ * Callbacks to use for this fetch operation
+ */
+ git_remote_callbacks callbacks;
+} git_fetch_options;
+
+#define GIT_FETCH_OPTIONS_VERSION 1
+#define GIT_FETCH_OPTIONS_INIT { GIT_FETCH_OPTIONS_VERSION, GIT_REMOTE_CALLBACKS_INIT }
+
/**
- * Set the callbacks for a remote
+ * Initializes a `git_fetch_options` with default values. Equivalent to
+ * creating an instance with GIT_FETCH_OPTIONS_INIT.
*
- * Note that the remote keeps its own copy of the data and you need to
- * call this function again if you want to change the callbacks.
+ * @param opts the `git_push_options` instance to initialize.
+ * @param version the version of the struct; you should pass
+ * `GIT_FETCH_OPTIONS_VERSION` here.
+ * @return Zero on success; -1 on failure.
+ */
+GIT_EXTERN(int) git_fetch_init_options(
+ git_fetch_options *opts,
+ unsigned int version);
+
+
+/**
+ * Controls the behavior of a git_push object.
+ */
+typedef struct {
+ unsigned int version;
+
+ /**
+ * If the transport being used to push to the remote requires the creation
+ * of a pack file, this controls the number of worker threads used by
+ * the packbuilder when creating that pack file to be sent to the remote.
+ *
+ * If set to 0, the packbuilder will auto-detect the number of threads
+ * to create. The default value is 1.
+ */
+ unsigned int pb_parallelism;
+
+ /**
+ * Callbacks to use for this push operation
+ */
+ git_remote_callbacks callbacks;
+} git_push_options;
+
+#define GIT_PUSH_OPTIONS_VERSION 1
+#define GIT_PUSH_OPTIONS_INIT { GIT_PUSH_OPTIONS_VERSION, 0, GIT_REMOTE_CALLBACKS_INIT }
+
+/**
+ * Initializes a `git_push_options` with default values. Equivalent to
+ * creating an instance with GIT_PUSH_OPTIONS_INIT.
*
- * @param remote the remote to configure
- * @param callbacks a pointer to the user's callback settings
+ * @param opts the `git_push_options` instance to initialize.
+ * @param version the version of the struct; you should pass
+ * `GIT_PUSH_OPTIONS_VERSION` here.
+ * @return Zero on success; -1 on failure.
+ */
+GIT_EXTERN(int) git_push_init_options(
+ git_push_options *opts,
+ unsigned int version);
+
+/**
+ * Download and index the packfile
+ *
+ * Connect to the remote if it hasn't been done yet, negotiate with
+ * the remote git which objects are missing, download and index the
+ * packfile.
+ *
+ * The .idx file will be created and both it and the packfile with be
+ * renamed to their final name.
+ *
+ * @param remote the remote
+ * @param refspecs the refspecs to use for this negotiation and
+ * download. Use NULL or an empty array to use the base refspecs
+ * @param opts the options to use for this fetch
* @return 0 or an error code
*/
-GIT_EXTERN(int) git_remote_set_callbacks(git_remote *remote, const git_remote_callbacks *callbacks);
+ GIT_EXTERN(int) git_remote_download(git_remote *remote, const git_strarray *refspecs, const git_fetch_options *opts);
/**
- * Retrieve the current callback structure
+ * Create a packfile and send it to the server
*
- * This provides read access to the callbacks structure as the remote
- * sees it.
+ * Connect to the remote if it hasn't been done yet, negotiate with
+ * the remote git which objects are missing, create a packfile with the missing objects and send it.
*
- * @param remote the remote to query
- * @return a pointer to the callbacks structure
+ * @param remote the remote
+ * @param refspecs the refspecs to use for this negotiation and
+ * upload. Use NULL or an empty array to use the base refspecs
+ * @param opts the options to use for this push
+ * @return 0 or an error code
+ */
+GIT_EXTERN(int) git_remote_upload(git_remote *remote, const git_strarray *refspecs, const git_push_options *opts);
+
+/**
+ * Update the tips to the new state
+ *
+ * @param remote the remote to update
+ * @param reflog_message The message to insert into the reflogs. If
+ * NULL and fetching, the default is "fetch <name>", where <name> is
+ * the name of the remote (or its url, for in-memory remotes). This
+ * parameter is ignored when pushing.
+ * @param callbacks pointer to the callback structure to use
+ * @return 0 or an error code
+ */
+GIT_EXTERN(int) git_remote_update_tips(
+ git_remote *remote,
+ const git_remote_callbacks *callbacks,
+ const char *reflog_message);
+
+/**
+ * Download new data and update tips
+ *
+ * Convenience function to connect to a remote, download the data,
+ * disconnect and update the remote-tracking branches.
+ *
+ * @param remote the remote to fetch from
+ * @param refspecs the refspecs to use for this fetch. Pass NULL or an
+ * empty array to use the base refspecs.
+ * @param opts options to use for this fetch
+ * @param reflog_message The message to insert into the reflogs. If NULL, the
+ * default is "fetch"
+ * @return 0 or an error code
*/
-GIT_EXTERN(const git_remote_callbacks *) git_remote_get_callbacks(git_remote *remote);
+GIT_EXTERN(int) git_remote_fetch(
+ git_remote *remote,
+ const git_strarray *refspecs,
+ const git_fetch_options *opts,
+ const char *reflog_message);
+
+/**
+ * Prune tracking refs that are no longer present on remote
+ *
+ * @param remote the remote to prune
+ * @param callbacks callbacks to use for this prune
+ * @return 0 or an error code
+ */
+GIT_EXTERN(int) git_remote_prune(git_remote *remote, const git_remote_callbacks *callbacks);
+
+/**
+ * Perform a push
+ *
+ * Peform all the steps from a push.
+ *
+ * @param remote the remote to push to
+ * @param refspecs the refspecs to use for pushing. If none are
+ * passed, the configured refspecs will be used
+ * @param opts options to use for this push
+ */
+GIT_EXTERN(int) git_remote_push(git_remote *remote,
+ const git_strarray *refspecs,
+ const git_push_options *opts);
/**
* Get the statistics structure that is filled in by the fetch operation.
diff --git a/include/git2/submodule.h b/include/git2/submodule.h
index 86f5fef22..48faf8a49 100644
--- a/include/git2/submodule.h
+++ b/include/git2/submodule.h
@@ -130,10 +130,12 @@ typedef struct git_submodule_update_options {
git_checkout_options checkout_opts;
/**
- * Callbacks to use for reporting fetch progress, and for acquiring
+ * Options which control the fetch, including callbacks.
+ *
+ * The callbacks to use for reporting fetch progress, and for acquiring
* credentials in the event they are needed.
*/
- git_remote_callbacks remote_callbacks;
+ git_fetch_options fetch_opts;
/**
* The checkout strategy to use when the sub repository needs to
@@ -147,7 +149,7 @@ typedef struct git_submodule_update_options {
#define GIT_SUBMODULE_UPDATE_OPTIONS_INIT \
{ GIT_CHECKOUT_OPTIONS_VERSION, \
{ GIT_CHECKOUT_OPTIONS_VERSION, GIT_CHECKOUT_SAFE }, \
- GIT_REMOTE_CALLBACKS_INIT, GIT_CHECKOUT_SAFE }
+ GIT_FETCH_OPTIONS_INIT, GIT_CHECKOUT_SAFE }
/**
* Initializes a `git_submodule_update_options` with default values.
diff --git a/include/git2/sys/transport.h b/include/git2/sys/transport.h
index 2cb1a97eb..d6ca8ff05 100644
--- a/include/git2/sys/transport.h
+++ b/include/git2/sys/transport.h
@@ -61,7 +61,7 @@ struct git_transport {
git_transport *transport);
/* Executes the push whose context is in the git_push object. */
- int (*push)(git_transport *transport, git_push *push);
+ int (*push)(git_transport *transport, git_push *push, const git_remote_callbacks *callbacks);
/* This function may be called after a successful call to connect(), when
* the direction is FETCH. The function performs a negotiation to calculate
diff --git a/src/clone.c b/src/clone.c
index 7e5d3302e..53cdae673 100644
--- a/src/clone.c
+++ b/src/clone.c
@@ -24,7 +24,7 @@
#include "repository.h"
#include "odb.h"
-static int clone_local_into(git_repository *repo, git_remote *remote, const git_checkout_options *co_opts, const char *branch, int link);
+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);
static int create_branch(
git_reference **branch,
@@ -242,13 +242,9 @@ static int default_remote_create(
const char *url,
void *payload)
{
- int error;
- git_remote_callbacks *callbacks = payload;
-
- if ((error = git_remote_create(out, repo, name, url)) < 0)
- return error;
+ GIT_UNUSED(payload);
- return git_remote_set_callbacks(*out, callbacks);
+ return git_remote_create(out, repo, name, url);
}
/*
@@ -277,7 +273,7 @@ static int create_and_configure_origin(
if (!remote_create) {
remote_create = default_remote_create;
- payload = (void *)&options->remote_callbacks;
+ payload = NULL;
}
if ((error = remote_create(&origin, repo, "origin", url, payload)) < 0)
@@ -328,12 +324,11 @@ static int checkout_branch(git_repository *repo, git_remote *remote, const git_c
return error;
}
-static int clone_into(git_repository *repo, git_remote *_remote, const git_checkout_options *co_opts, const char *branch)
+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_remote *remote;
- const git_remote_callbacks *callbacks;
assert(repo && _remote);
@@ -345,18 +340,13 @@ static int clone_into(git_repository *repo, git_remote *_remote, const git_check
if ((error = git_remote_dup(&remote, _remote)) < 0)
return error;
- callbacks = git_remote_get_callbacks(_remote);
- if (!giterr__check_version(callbacks, 1, "git_remote_callbacks") &&
- (error = git_remote_set_callbacks(remote, callbacks)) < 0)
- goto cleanup;
-
if ((error = git_remote_add_fetch(remote, "refs/tags/*:refs/tags/*")) < 0)
goto cleanup;
git_remote_set_update_fetchhead(remote, 0);
git_buf_printf(&reflog_message, "clone: from %s", git_remote_url(remote));
- if ((error = git_remote_fetch(remote, NULL, git_buf_cstr(&reflog_message))) != 0)
+ if ((error = git_remote_fetch(remote, NULL, opts, git_buf_cstr(&reflog_message))) != 0)
goto cleanup;
error = checkout_branch(repo, remote, co_opts, branch, git_buf_cstr(&reflog_message));
@@ -439,11 +429,11 @@ int git_clone(
if (clone_local == 1)
error = clone_local_into(
- repo, origin, &options.checkout_opts,
+ repo, origin, &options.fetch_opts, &options.checkout_opts,
options.checkout_branch, link);
else if (clone_local == 0)
error = clone_into(
- repo, origin, &options.checkout_opts,
+ repo, origin, &options.fetch_opts, &options.checkout_opts,
options.checkout_branch);
else
error = -1;
@@ -506,7 +496,7 @@ static bool can_link(const char *src, const char *dst, int link)
#endif
}
-static int clone_local_into(git_repository *repo, git_remote *remote, const git_checkout_options *co_opts, const char *branch, int link)
+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;
@@ -551,7 +541,7 @@ static int clone_local_into(git_repository *repo, git_remote *remote, const git_
git_buf_printf(&reflog_message, "clone: from %s", git_remote_url(remote));
- if ((error = git_remote_fetch(remote, NULL, git_buf_cstr(&reflog_message))) != 0)
+ if ((error = git_remote_fetch(remote, NULL, fetch_opts, git_buf_cstr(&reflog_message))) != 0)
goto cleanup;
error = checkout_branch(repo, remote, co_opts, branch, git_buf_cstr(&reflog_message));
diff --git a/src/fetch.c b/src/fetch.c
index f61685619..e59ae8621 100644
--- a/src/fetch.c
+++ b/src/fetch.c
@@ -127,13 +127,26 @@ int git_fetch_negotiate(git_remote *remote)
remote->refs.length);
}
-int git_fetch_download_pack(git_remote *remote)
+int git_fetch_download_pack(git_remote *remote, const git_remote_callbacks *callbacks)
{
git_transport *t = remote->transport;
+ git_transfer_progress_cb progress = NULL;
+ void *payload = NULL;
if (!remote->need_pack)
return 0;
- return t->download_pack(t, remote->repo, &remote->stats,
- remote->callbacks.transfer_progress, remote->callbacks.payload);
+ if (callbacks) {
+ progress = callbacks->transfer_progress;
+ payload = callbacks->payload;
+ }
+
+ return t->download_pack(t, remote->repo, &remote->stats, progress, payload);
+}
+
+int git_fetch_init_options(git_fetch_options *opts, unsigned int version)
+{
+ GIT_INIT_STRUCTURE_FROM_TEMPLATE(
+ opts, version, git_fetch_options, GIT_FETCH_OPTIONS_INIT);
+ return 0;
}
diff --git a/src/fetch.h b/src/fetch.h
index f66e44663..26d8a6b9d 100644
--- a/src/fetch.h
+++ b/src/fetch.h
@@ -11,7 +11,7 @@
int git_fetch_negotiate(git_remote *remote);
-int git_fetch_download_pack(git_remote *remote);
+int git_fetch_download_pack(git_remote *remote, const git_remote_callbacks *callbacks);
int git_fetch__download_pack(
git_transport *t,
diff --git a/src/push.c b/src/push.c
index a4b61cd35..cd219e905 100644
--- a/src/push.c
+++ b/src/push.c
@@ -155,7 +155,7 @@ int git_push_add_refspec(git_push *push, const char *refspec)
return 0;
}
-int git_push_update_tips(git_push *push)
+int git_push_update_tips(git_push *push, const git_remote_callbacks *callbacks)
{
git_buf remote_ref_name = GIT_BUF_INIT;
size_t i, j;
@@ -212,9 +212,9 @@ int git_push_update_tips(git_push *push)
fire_callback = 0;
}
- if (fire_callback && push->remote->callbacks.update_tips) {
- error = push->remote->callbacks.update_tips(git_buf_cstr(&remote_ref_name),
- &push_spec->roid, &push_spec->loid, push->remote->callbacks.payload);
+ if (fire_callback && callbacks && callbacks->update_tips) {
+ error = callbacks->update_tips(git_buf_cstr(&remote_ref_name),
+ &push_spec->roid, &push_spec->loid, callbacks->payload);
if (error < 0)
goto on_error;
@@ -571,11 +571,10 @@ static int calculate_work(git_push *push)
return 0;
}
-static int do_push(git_push *push)
+static int do_push(git_push *push, const git_remote_callbacks *callbacks)
{
int error = 0;
git_transport *transport = push->remote->transport;
- git_remote_callbacks *cbs = &push->remote->callbacks;
if (!transport->push) {
giterr_set(GITERR_NET, "Remote transport doesn't support push");
@@ -594,20 +593,20 @@ static int do_push(git_push *push)
git_packbuilder_set_threads(push->pb, push->pb_parallelism);
- if (cbs->pack_progress)
- if ((error = git_packbuilder_set_callbacks(push->pb, cbs->pack_progress, cbs->payload)) < 0)
+ if (callbacks && callbacks->pack_progress)
+ if ((error = git_packbuilder_set_callbacks(push->pb, callbacks->pack_progress, callbacks->payload)) < 0)
goto on_error;
if ((error = calculate_work(push)) < 0)
goto on_error;
- if (cbs->push_negotiation &&
- (error = cbs->push_negotiation((const git_push_update **) push->updates.contents,
- push->updates.length, cbs->payload)) < 0)
+ if (callbacks && callbacks->push_negotiation &&
+ (error = callbacks->push_negotiation((const git_push_update **) push->updates.contents,
+ push->updates.length, callbacks->payload)) < 0)
goto on_error;
if ((error = queue_objects(push)) < 0 ||
- (error = transport->push(transport, push)) < 0)
+ (error = transport->push(transport, push, callbacks)) < 0)
goto on_error;
on_error:
@@ -633,16 +632,16 @@ static int filter_refs(git_remote *remote)
return 0;
}
-int git_push_finish(git_push *push)
+int git_push_finish(git_push *push, const git_remote_callbacks *callbacks)
{
int error;
if (!git_remote_connected(push->remote) &&
- (error = git_remote_connect(push->remote, GIT_DIRECTION_PUSH)) < 0)
+ (error = git_remote_connect(push->remote, GIT_DIRECTION_PUSH, callbacks)) < 0)
return error;
if ((error = filter_refs(push->remote)) < 0 ||
- (error = do_push(push)) < 0)
+ (error = do_push(push, callbacks)) < 0)
return error;
if (!push->unpack_ok) {
diff --git a/src/push.h b/src/push.h
index fcba45c8e..094f96ca9 100644
--- a/src/push.h
+++ b/src/push.h
@@ -87,7 +87,7 @@ int git_push_add_refspec(git_push *push, const char *refspec);
*
* @return 0 or an error code
*/
-int git_push_update_tips(git_push *push);
+int git_push_update_tips(git_push *push, const git_remote_callbacks *callbacks);
/**
* Perform the push
@@ -103,7 +103,7 @@ int git_push_update_tips(git_push *push);
*
* @return 0 or an error code
*/
-int git_push_finish(git_push *push);
+int git_push_finish(git_push *push, const git_remote_callbacks *callbacks);
/**
* Invoke callback `cb' on each status entry
diff --git a/src/remote.c b/src/remote.c
index 91ebdd53c..85da2dc1b 100644
--- a/src/remote.c
+++ b/src/remote.c
@@ -691,15 +691,32 @@ const char* git_remote__urlfordirection(git_remote *remote, int direction)
return NULL;
}
-int git_remote_connect(git_remote *remote, git_direction direction)
+int set_transport_callbacks(git_transport *t, const git_remote_callbacks *cbs)
+{
+ if (!t->set_callbacks || !cbs)
+ return 0;
+
+ return t->set_callbacks(t, cbs->sideband_progress, NULL,
+ cbs->certificate_check, cbs->payload);
+}
+
+int git_remote_connect(git_remote *remote, git_direction direction, const git_remote_callbacks *callbacks)
{
git_transport *t;
const char *url;
int flags = GIT_TRANSPORTFLAGS_NONE;
int error;
+ void *payload = NULL;
+ git_cred_acquire_cb credentials;
assert(remote);
+ if (callbacks) {
+ GITERR_CHECK_VERSION(callbacks, GIT_REMOTE_CALLBACKS_VERSION, "git_remote_callbacks");
+ credentials = callbacks->credentials;
+ payload = callbacks->payload;
+ }
+
t = remote->transport;
url = git_remote__urlfordirection(remote, direction);
@@ -720,11 +737,8 @@ int git_remote_connect(git_remote *remote, git_direction direction)
if (!t && (error = git_transport_new(&t, remote, url)) < 0)
return error;
- if (t->set_callbacks &&
- (error = t->set_callbacks(t, remote->callbacks.sideband_progress, NULL, remote->callbacks.certificate_check, remote->callbacks.payload)) < 0)
- goto on_error;
-
- if ((error = t->connect(t, url, remote->callbacks.credentials, remote->callbacks.payload, direction, flags)) != 0)
+ if ((error = set_transport_callbacks(t, callbacks)) < 0 ||
+ (error = t->connect(t, url, credentials, payload, direction, flags)) != 0)
goto on_error;
remote->transport = t;
@@ -866,14 +880,24 @@ static int ls_to_vector(git_vector *out, git_remote *remote)
return 0;
}
-int git_remote_download(git_remote *remote, const git_strarray *refspecs)
+int git_remote_download(git_remote *remote, const git_strarray *refspecs, const git_fetch_options *opts)
{
int error = -1;
size_t i;
git_vector refs, specs, *to_active;
+ const git_remote_callbacks *cbs = NULL;
assert(remote);
+ if (opts) {
+ GITERR_CHECK_VERSION(&opts->callbacks, GIT_REMOTE_CALLBACKS_VERSION, "git_remote_callbacks");
+ cbs = &opts->callbacks;
+ }
+
+ if (!git_remote_connected(remote) &&
+ (error = git_remote_connect(remote, GIT_DIRECTION_FETCH, cbs)) < 0)
+ goto on_error;
+
if (ls_to_vector(&refs, remote) < 0)
return -1;
@@ -915,7 +939,7 @@ int git_remote_download(git_remote *remote, const git_strarray *refspecs)
if ((error = git_fetch_negotiate(remote)) < 0)
return error;
- return git_fetch_download_pack(remote);
+ return git_fetch_download_pack(remote, cbs);
on_error:
git_vector_free(&refs);
@@ -927,16 +951,23 @@ on_error:
int git_remote_fetch(
git_remote *remote,
const git_strarray *refspecs,
+ const git_fetch_options *opts,
const char *reflog_message)
{
int error;
git_buf reflog_msg_buf = GIT_BUF_INIT;
+ const git_remote_callbacks *cbs = NULL;
+
+ if (opts) {
+ GITERR_CHECK_VERSION(&opts->callbacks, GIT_REMOTE_CALLBACKS_VERSION, "git_remote_callbacks");
+ cbs = &opts->callbacks;
+ }
/* Connect and download everything */
- if ((error = git_remote_connect(remote, GIT_DIRECTION_FETCH)) != 0)
+ if ((error = git_remote_connect(remote, GIT_DIRECTION_FETCH, cbs)) != 0)
return error;
- error = git_remote_download(remote, refspecs);
+ error = git_remote_download(remote, refspecs, opts);
/* We don't need to be connected anymore */
git_remote_disconnect(remote);
@@ -954,13 +985,13 @@ int git_remote_fetch(
}
/* Create "remote/foo" branches for all remote branches */
- error = git_remote_update_tips(remote, git_buf_cstr(&reflog_msg_buf));
+ error = git_remote_update_tips(remote, cbs, git_buf_cstr(&reflog_msg_buf));
git_buf_free(&reflog_msg_buf);
if (error < 0)
return error;
if (remote->prune_refs)
- error = git_remote_prune(remote);
+ error = git_remote_prune(remote, cbs);
return error;
}
@@ -1156,7 +1187,7 @@ static int find_head(const void *_a, const void *_b)
return strcmp(a->name, b->name);
}
-int git_remote_prune(git_remote *remote)
+int git_remote_prune(git_remote *remote, const git_remote_callbacks *callbacks)
{
size_t i, j;
git_vector remote_refs = GIT_VECTOR_INIT;
@@ -1166,6 +1197,9 @@ int git_remote_prune(git_remote *remote)
int error;
git_oid zero_id = {{ 0 }};
+ if (callbacks)
+ GITERR_CHECK_VERSION(callbacks, GIT_REMOTE_CALLBACKS_VERSION, "git_remote_callbacks");
+
if ((error = ls_to_vector(&remote_refs, remote)) < 0)
goto cleanup;
@@ -1242,8 +1276,8 @@ int git_remote_prune(git_remote *remote)
if (error < 0)
goto cleanup;
- if (remote->callbacks.update_tips)
- error = remote->callbacks.update_tips(refname, &id, &zero_id, remote->callbacks.payload);
+ if (callbacks && callbacks->update_tips)
+ error = callbacks->update_tips(refname, &id, &zero_id, callbacks->payload);
if (error < 0)
goto cleanup;
@@ -1257,6 +1291,7 @@ cleanup:
static int update_tips_for_spec(
git_remote *remote,
+ const git_remote_callbacks *callbacks,
git_refspec *spec,
git_vector *refs,
const char *log_message)
@@ -1339,8 +1374,8 @@ static int update_tips_for_spec(
git_reference_free(ref);
- if (remote->callbacks.update_tips != NULL) {
- if (remote->callbacks.update_tips(refname.ptr, &old, &head->oid, remote->callbacks.payload) < 0)
+ if (callbacks && callbacks->update_tips != NULL) {
+ if (callbacks->update_tips(refname.ptr, &old, &head->oid, callbacks->payload) < 0)
goto on_error;
}
}
@@ -1455,6 +1490,7 @@ static int opportunistic_updates(const git_remote *remote, git_vector *refs, con
int git_remote_update_tips(
git_remote *remote,
+ const git_remote_callbacks *callbacks,
const char *reflog_message)
{
git_refspec *spec, tagspec;
@@ -1464,7 +1500,7 @@ int git_remote_update_tips(
/* push has its own logic hidden away in the push object */
if (remote->push) {
- return git_push_update_tips(remote->push);
+ return git_push_update_tips(remote->push, callbacks);
}
if (git_refspec__parse(&tagspec, GIT_REFSPEC_TAGS, true) < 0)
@@ -1475,7 +1511,7 @@ int git_remote_update_tips(
goto out;
if (remote->download_tags == GIT_REMOTE_DOWNLOAD_TAGS_ALL) {
- if ((error = update_tips_for_spec(remote, &tagspec, &refs, reflog_message)) < 0)
+ if ((error = update_tips_for_spec(remote, callbacks, &tagspec, &refs, reflog_message)) < 0)
goto out;
}
@@ -1483,7 +1519,7 @@ int git_remote_update_tips(
if (spec->push)
continue;
- if ((error = update_tips_for_spec(remote, spec, &refs, reflog_message)) < 0)
+ if ((error = update_tips_for_spec(remote, callbacks, spec, &refs, reflog_message)) < 0)
goto out;
}
@@ -1600,31 +1636,6 @@ int git_remote_list(git_strarray *remotes_list, git_repository *repo)
return 0;
}
-int git_remote_set_callbacks(git_remote *remote, const git_remote_callbacks *callbacks)
-{
- assert(remote && callbacks);
-
- GITERR_CHECK_VERSION(callbacks, GIT_REMOTE_CALLBACKS_VERSION, "git_remote_callbacks");
-
- memcpy(&remote->callbacks, callbacks, sizeof(git_remote_callbacks));
-
- if (remote->transport && remote->transport->set_callbacks)
- return remote->transport->set_callbacks(remote->transport,
- remote->callbacks.sideband_progress,
- NULL,
- remote->callbacks.certificate_check,
- remote->callbacks.payload);
-
- return 0;
-}
-
-const git_remote_callbacks *git_remote_get_callbacks(git_remote *remote)
-{
- assert(remote);
-
- return &remote->callbacks;
-}
-
int git_remote_set_transport(
git_remote *remote,
git_transport_cb transport_cb,
@@ -2321,12 +2332,15 @@ int git_remote_upload(git_remote *remote, const git_strarray *refspecs, const gi
int error;
git_push *push;
git_refspec *spec;
- git_remote_callbacks *cbs;
+ const git_remote_callbacks *cbs = NULL;
assert(remote);
+ if (opts)
+ cbs = &opts->callbacks;
+
if (!git_remote_connected(remote) &&
- (error = git_remote_connect(remote, GIT_DIRECTION_PUSH)) < 0)
+ (error = git_remote_connect(remote, GIT_DIRECTION_PUSH, cbs)) < 0)
goto cleanup;
free_refspecs(&remote->active_refspecs);
@@ -2360,11 +2374,10 @@ int git_remote_upload(git_remote *remote, const git_strarray *refspecs, const gi
}
}
- if ((error = git_push_finish(push)) < 0)
+ if ((error = git_push_finish(push, cbs)) < 0)
goto cleanup;
- cbs = &remote->callbacks;
- if (cbs->push_update_reference &&
+ if (cbs && cbs->push_update_reference &&
(error = git_push_status_foreach(push, cbs->push_update_reference, cbs->payload)) < 0)
goto cleanup;
@@ -2375,16 +2388,22 @@ cleanup:
int git_remote_push(git_remote *remote, const git_strarray *refspecs, const git_push_options *opts)
{
int error;
+ const git_remote_callbacks *cbs = NULL;
+
+ if (opts) {
+ GITERR_CHECK_VERSION(&opts->callbacks, GIT_REMOTE_CALLBACKS_VERSION, "git_remote_callbacks");
+ cbs = &opts->callbacks;
+ }
assert(remote && refspecs);
- if ((error = git_remote_connect(remote, GIT_DIRECTION_PUSH)) < 0)
+ if ((error = git_remote_connect(remote, GIT_DIRECTION_PUSH, cbs)) < 0)
return error;
if ((error = git_remote_upload(remote, refspecs, opts)) < 0)
return error;
- error = git_remote_update_tips(remote, NULL);
+ error = git_remote_update_tips(remote, cbs, NULL);
git_remote_disconnect(remote);
return error;
diff --git a/src/remote.h b/src/remote.h
index a28b565ce..4fb2351d9 100644
--- a/src/remote.h
+++ b/src/remote.h
@@ -29,7 +29,6 @@ struct git_remote {
git_transport *transport;
git_repository *repo;
git_push *push;
- git_remote_callbacks callbacks;
git_transfer_progress stats;
unsigned int need_pack;
git_remote_autotag_option_t download_tags;
diff --git a/src/submodule.c b/src/submodule.c
index d24a7773a..1139df973 100644
--- a/src/submodule.c
+++ b/src/submodule.c
@@ -950,7 +950,7 @@ int git_submodule_update(git_submodule *sm, int init, git_submodule_update_optio
GITERR_CHECK_VERSION(&update_options, GIT_SUBMODULE_UPDATE_OPTIONS_VERSION, "git_submodule_update_options");
/* Copy over the remote callbacks */
- clone_options.remote_callbacks = update_options.remote_callbacks;
+ memcpy(&clone_options.fetch_opts, &update_options.fetch_opts, sizeof(git_fetch_options));
/* Get the status of the submodule to determine if it is already initialized */
if ((error = git_submodule_status(&submodule_status, sm)) < 0)
diff --git a/src/transports/local.c b/src/transports/local.c
index def8ac037..305c71bf0 100644
--- a/src/transports/local.c
+++ b/src/transports/local.c
@@ -16,7 +16,6 @@
#include "git2/pack.h"
#include "git2/commit.h"
#include "git2/revparse.h"
-#include "git2/push.h"
#include "pack-objects.h"
#include "refs.h"
#include "posix.h"
@@ -366,7 +365,8 @@ static int local_push_update_remote_ref(
static int local_push(
git_transport *transport,
- git_push *push)
+ git_push *push,
+ const git_remote_callbacks *cbs)
{
transport_local *t = (transport_local *)transport;
git_odb *remote_odb = NULL;
@@ -380,6 +380,8 @@ static int local_push(
unsigned int i;
size_t j;
+ GIT_UNUSED(cbs);
+
/* 'push->remote->url' may be a url or path; convert to a path */
if ((error = git_path_from_url_or_path(&buf, push->remote->url)) < 0) {
git_buf_free(&buf);
@@ -471,7 +473,7 @@ static int local_push(
if (!url || t->parent.close(&t->parent) < 0 ||
t->parent.connect(&t->parent, url,
- push->remote->callbacks.credentials, NULL, GIT_DIRECTION_PUSH, flags))
+ NULL, NULL, GIT_DIRECTION_PUSH, flags))
goto on_error;
}
diff --git a/src/transports/smart.h b/src/transports/smart.h
index 44e241adc..4c728c7cc 100644
--- a/src/transports/smart.h
+++ b/src/transports/smart.h
@@ -158,7 +158,7 @@ typedef struct {
/* smart_protocol.c */
int git_smart__store_refs(transport_smart *t, int flushes);
int git_smart__detect_caps(git_pkt_ref *pkt, transport_smart_caps *caps, git_vector *symrefs);
-int git_smart__push(git_transport *transport, git_push *push);
+int git_smart__push(git_transport *transport, git_push *push, const git_remote_callbacks *cbs);
int git_smart__negotiate_fetch(
git_transport *transport,
diff --git a/src/transports/smart_protocol.c b/src/transports/smart_protocol.c
index 9e7b0a72b..7f6b74ca7 100644
--- a/src/transports/smart_protocol.c
+++ b/src/transports/smart_protocol.c
@@ -946,11 +946,10 @@ static int stream_thunk(void *buf, size_t size, void *data)
return error;
}
-int git_smart__push(git_transport *transport, git_push *push)
+int git_smart__push(git_transport *transport, git_push *push, const git_remote_callbacks *cbs)
{
transport_smart *t = (transport_smart *)transport;
struct push_packbuilder_payload packbuilder_payload = {0};
- git_remote_callbacks *cbs = &push->remote->callbacks;
git_buf pktline = GIT_BUF_INIT;
int error = 0, need_pack = 0;
push_spec *spec;
@@ -958,7 +957,7 @@ int git_smart__push(git_transport *transport, git_push *push)
packbuilder_payload.pb = push->pb;
- if (cbs->transfer_progress) {
+ if (cbs && cbs->transfer_progress) {
packbuilder_payload.cb = cbs->push_transfer_progress;
packbuilder_payload.cb_payload = cbs->payload;
}
@@ -1011,7 +1010,7 @@ int git_smart__push(git_transport *transport, git_push *push)
goto done;
/* If progress is being reported write the final report */
- if (cbs->push_transfer_progress) {
+ if (cbs && cbs->push_transfer_progress) {
error = cbs->push_transfer_progress(
push->pb->nr_written,
push->pb->nr_objects,
diff --git a/tests/checkout/index.c b/tests/checkout/index.c
index b759db206..de0770dba 100644
--- a/tests/checkout/index.c
+++ b/tests/checkout/index.c
@@ -154,9 +154,7 @@ void test_checkout_index__honor_coresymlinks_default(void)
cl_git_pass(git_repository_set_workdir(repo, "symlink", 1));
cl_git_pass(git_remote_create(&origin, repo, GIT_REMOTE_ORIGIN, url));
- cl_git_pass(git_remote_connect(origin, GIT_DIRECTION_FETCH));
- cl_git_pass(git_remote_download(origin, NULL));
- cl_git_pass(git_remote_update_tips(origin, NULL));
+ cl_git_pass(git_remote_fetch(origin, NULL, NULL, NULL));
git_remote_free(origin);
cl_git_pass(git_revparse_single(&target, repo, "remotes/origin/master"));
diff --git a/tests/clone/empty.c b/tests/clone/empty.c
index 8f6071096..2a6217580 100644
--- a/tests/clone/empty.c
+++ b/tests/clone/empty.c
@@ -10,14 +10,14 @@ static git_repository *g_repo_cloned;
void test_clone_empty__initialize(void)
{
git_repository *sandbox = cl_git_sandbox_init("empty_bare.git");
- git_remote_callbacks dummy_callbacks = GIT_REMOTE_CALLBACKS_INIT;
+ git_fetch_options dummy_options = GIT_FETCH_OPTIONS_INIT;
cl_git_remove_placeholders(git_repository_path(sandbox), "dummy-marker.txt");
g_repo = NULL;
memset(&g_options, 0, sizeof(git_clone_options));
g_options.version = GIT_CLONE_OPTIONS_VERSION;
- g_options.remote_callbacks = dummy_callbacks;
+ g_options.fetch_opts = dummy_options;
}
void test_clone_empty__cleanup(void)
diff --git a/tests/clone/nonetwork.c b/tests/clone/nonetwork.c
index e4794fc14..fec6aff2e 100644
--- a/tests/clone/nonetwork.c
+++ b/tests/clone/nonetwork.c
@@ -15,7 +15,7 @@ static git_remote* g_remote;
void test_clone_nonetwork__initialize(void)
{
git_checkout_options dummy_opts = GIT_CHECKOUT_OPTIONS_INIT;
- git_remote_callbacks dummy_callbacks = GIT_REMOTE_CALLBACKS_INIT;
+ git_fetch_options dummy_fetch = GIT_FETCH_OPTIONS_INIT;
g_repo = NULL;
@@ -23,7 +23,7 @@ void test_clone_nonetwork__initialize(void)
g_options.version = GIT_CLONE_OPTIONS_VERSION;
g_options.checkout_opts = dummy_opts;
g_options.checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE;
- g_options.remote_callbacks = dummy_callbacks;
+ g_options.fetch_opts = dummy_fetch;
}
void test_clone_nonetwork__cleanup(void)
@@ -179,7 +179,7 @@ void test_clone_nonetwork__can_cancel_clone_in_fetch(void)
{
g_options.checkout_branch = "test";
- g_options.remote_callbacks.transfer_progress =
+ g_options.fetch_opts.callbacks.transfer_progress =
clone_cancel_fetch_transfer_progress_cb;
cl_git_fail_with(git_clone(
diff --git a/tests/fetchhead/nonetwork.c b/tests/fetchhead/nonetwork.c
index 2d6d53eb6..489481826 100644
--- a/tests/fetchhead/nonetwork.c
+++ b/tests/fetchhead/nonetwork.c
@@ -335,7 +335,7 @@ void test_fetchhead_nonetwork__unborn_with_upstream(void)
cl_git_pass(git_remote_set_url(remote, cl_fixture("testrepo.git")));
cl_git_pass(git_remote_save(remote));
- cl_git_pass(git_remote_fetch(remote, NULL, NULL));
+ cl_git_pass(git_remote_fetch(remote, NULL, NULL, NULL));
git_remote_free(remote);
cl_git_pass(git_repository_fetchhead_foreach(repo, assert_master_for_merge, NULL));
diff --git a/tests/network/fetchlocal.c b/tests/network/fetchlocal.c
index 13b3cf07c..a191b7b6b 100644
--- a/tests/network/fetchlocal.c
+++ b/tests/network/fetchlocal.c
@@ -34,19 +34,16 @@ void test_network_fetchlocal__complete(void)
git_strarray refnames = {0};
const char *url = cl_git_fixture_url("testrepo.git");
- git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;
+ git_fetch_options options = GIT_FETCH_OPTIONS_INIT;
- callbacks.transfer_progress = transfer_cb;
- callbacks.payload = &callcount;
+ options.callbacks.transfer_progress = transfer_cb;
+ options.callbacks.payload = &callcount;
cl_set_cleanup(&cleanup_local_repo, "foo");
cl_git_pass(git_repository_init(&repo, "foo", true));
cl_git_pass(git_remote_create(&origin, repo, GIT_REMOTE_ORIGIN, url));
- git_remote_set_callbacks(origin, &callbacks);
- cl_git_pass(git_remote_connect(origin, GIT_DIRECTION_FETCH));
- cl_git_pass(git_remote_download(origin, NULL));
- cl_git_pass(git_remote_update_tips(origin, NULL));
+ cl_git_pass(git_remote_fetch(origin, NULL, &options, NULL));
cl_git_pass(git_reference_list(&refnames, repo));
cl_assert_equal_i(19, (int)refnames.count);
@@ -66,17 +63,16 @@ void test_network_fetchlocal__prune(void)
git_reference *ref;
git_repository *remote_repo = cl_git_sandbox_init("testrepo.git");
const char *url = cl_git_path_url(git_repository_path(remote_repo));
- git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;
+ git_fetch_options options = GIT_FETCH_OPTIONS_INIT;
- callbacks.transfer_progress = transfer_cb;
- callbacks.payload = &callcount;
+ options.callbacks.transfer_progress = transfer_cb;
+ options.callbacks.payload = &callcount;
cl_set_cleanup(&cleanup_local_repo, "foo");
cl_git_pass(git_repository_init(&repo, "foo", true));
cl_git_pass(git_remote_create(&origin, repo, GIT_REMOTE_ORIGIN, url));
- git_remote_set_callbacks(origin, &callbacks);
- cl_git_pass(git_remote_fetch(origin, NULL, NULL));
+ cl_git_pass(git_remote_fetch(origin, NULL, &options, NULL));
cl_git_pass(git_reference_list(&refnames, repo));
cl_assert_equal_i(19, (int)refnames.count);
@@ -89,11 +85,8 @@ void test_network_fetchlocal__prune(void)
git_reference_free(ref);
cl_git_pass(git_remote_lookup(&origin, repo, GIT_REMOTE_ORIGIN));
- git_remote_set_callbacks(origin, &callbacks);
- cl_git_pass(git_remote_connect(origin, GIT_DIRECTION_FETCH));
- cl_git_pass(git_remote_download(origin, NULL));
- cl_git_pass(git_remote_prune(origin));
- cl_git_pass(git_remote_update_tips(origin, NULL));
+ cl_git_pass(git_remote_fetch(origin, NULL, &options, NULL));
+ cl_git_pass(git_remote_prune(origin, &options.callbacks));
cl_git_pass(git_reference_list(&refnames, repo));
cl_assert_equal_i(18, (int)refnames.count);
@@ -105,11 +98,8 @@ void test_network_fetchlocal__prune(void)
git_reference_free(ref);
cl_git_pass(git_remote_lookup(&origin, repo, GIT_REMOTE_ORIGIN));
- git_remote_set_callbacks(origin, &callbacks);
- cl_git_pass(git_remote_connect(origin, GIT_DIRECTION_FETCH));
- cl_git_pass(git_remote_download(origin, NULL));
- cl_git_pass(git_remote_prune(origin));
- cl_git_pass(git_remote_update_tips(origin, NULL));
+ cl_git_pass(git_remote_fetch(origin, NULL, &options, NULL));
+ cl_git_pass(git_remote_prune(origin, &options.callbacks));
cl_git_pass(git_reference_list(&refnames, repo));
cl_assert_equal_i(17, (int)refnames.count);
@@ -151,9 +141,9 @@ void test_network_fetchlocal__prune_overlapping(void)
git_repository *remote_repo = cl_git_sandbox_init("testrepo.git");
const char *url = cl_git_path_url(git_repository_path(remote_repo));
- git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;
- callbacks.transfer_progress = transfer_cb;
- callbacks.payload = &callcount;
+ git_fetch_options options = GIT_FETCH_OPTIONS_INIT;
+ options.callbacks.transfer_progress = transfer_cb;
+ options.callbacks.payload = &callcount;
cl_git_pass(git_reference_lookup(&ref, remote_repo, "refs/heads/master"));
git_oid_cpy(&target, git_reference_target(ref));
@@ -165,7 +155,6 @@ void test_network_fetchlocal__prune_overlapping(void)
cl_git_pass(git_repository_init(&repo, "foo", true));
cl_git_pass(git_remote_create(&origin, repo, GIT_REMOTE_ORIGIN, url));
- git_remote_set_callbacks(origin, &callbacks);
cl_git_pass(git_repository_config(&config, repo));
cl_git_pass(git_config_set_bool(config, "remote.origin.prune", true));
@@ -173,8 +162,7 @@ void test_network_fetchlocal__prune_overlapping(void)
git_remote_free(origin);
cl_git_pass(git_remote_lookup(&origin, repo, GIT_REMOTE_ORIGIN));
- git_remote_set_callbacks(origin, &callbacks);
- cl_git_pass(git_remote_fetch(origin, NULL, NULL));
+ cl_git_pass(git_remote_fetch(origin, NULL, &options, NULL));
assert_ref_exists(repo, "refs/remotes/origin/master");
assert_ref_exists(repo, "refs/remotes/origin/pr/42");
@@ -188,9 +176,8 @@ void test_network_fetchlocal__prune_overlapping(void)
git_remote_free(origin);
cl_git_pass(git_remote_lookup(&origin, repo, GIT_REMOTE_ORIGIN));
- callbacks.update_tips = update_tips_fail_on_call;
- git_remote_set_callbacks(origin, &callbacks);
- cl_git_pass(git_remote_fetch(origin, NULL, NULL));
+ options.callbacks.update_tips = update_tips_fail_on_call;
+ cl_git_pass(git_remote_fetch(origin, NULL, &options, NULL));
assert_ref_exists(repo, "refs/remotes/origin/master");
assert_ref_exists(repo, "refs/remotes/origin/pr/42");
@@ -204,9 +191,8 @@ void test_network_fetchlocal__prune_overlapping(void)
git_remote_free(origin);
cl_git_pass(git_remote_lookup(&origin, repo, GIT_REMOTE_ORIGIN));
- callbacks.update_tips = update_tips_fail_on_call;
- git_remote_set_callbacks(origin, &callbacks);
- cl_git_pass(git_remote_fetch(origin, NULL, NULL));
+ options.callbacks.update_tips = update_tips_fail_on_call;
+ cl_git_pass(git_remote_fetch(origin, NULL, &options, NULL));
git_config_free(config);
git_strarray_free(&refnames);
@@ -224,17 +210,16 @@ void test_network_fetchlocal__fetchprune(void)
git_config *config;
git_repository *remote_repo = cl_git_sandbox_init("testrepo.git");
const char *url = cl_git_path_url(git_repository_path(remote_repo));
- git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;
+ git_fetch_options options = GIT_FETCH_OPTIONS_INIT;
- callbacks.transfer_progress = transfer_cb;
- callbacks.payload = &callcount;
+ options.callbacks.transfer_progress = transfer_cb;
+ options.callbacks.payload = &callcount;
cl_set_cleanup(&cleanup_local_repo, "foo");
cl_git_pass(git_repository_init(&repo, "foo", true));
cl_git_pass(git_remote_create(&origin, repo, GIT_REMOTE_ORIGIN, url));
- git_remote_set_callbacks(origin, &callbacks);
- cl_git_pass(git_remote_fetch(origin, NULL, NULL));
+ cl_git_pass(git_remote_fetch(origin, NULL, &options, NULL));
cl_git_pass(git_reference_list(&refnames, repo));
cl_assert_equal_i(19, (int)refnames.count);
@@ -247,9 +232,8 @@ void test_network_fetchlocal__fetchprune(void)
git_reference_free(ref);
cl_git_pass(git_remote_lookup(&origin, repo, GIT_REMOTE_ORIGIN));
- git_remote_set_callbacks(origin, &callbacks);
- cl_git_pass(git_remote_fetch(origin, NULL, NULL));
- cl_git_pass(git_remote_prune(origin));
+ cl_git_pass(git_remote_fetch(origin, NULL, &options, NULL));
+ cl_git_pass(git_remote_prune(origin, &options.callbacks));
cl_git_pass(git_reference_list(&refnames, repo));
cl_assert_equal_i(18, (int)refnames.count);
@@ -265,8 +249,7 @@ void test_network_fetchlocal__fetchprune(void)
git_config_free(config);
cl_git_pass(git_remote_lookup(&origin, repo, GIT_REMOTE_ORIGIN));
cl_assert_equal_i(1, git_remote_prune_refs(origin));
- git_remote_set_callbacks(origin, &callbacks);
- cl_git_pass(git_remote_fetch(origin, NULL, NULL));
+ cl_git_pass(git_remote_fetch(origin, NULL, &options, NULL));
cl_git_pass(git_reference_list(&refnames, repo));
cl_assert_equal_i(17, (int)refnames.count);
@@ -289,17 +272,16 @@ void test_network_fetchlocal__prune_tag(void)
git_repository *remote_repo = cl_git_sandbox_init("testrepo.git");
const char *url = cl_git_path_url(git_repository_path(remote_repo));
- git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;
+ git_fetch_options options = GIT_FETCH_OPTIONS_INIT;
- callbacks.transfer_progress = transfer_cb;
- callbacks.payload = &callcount;
+ options.callbacks.transfer_progress = transfer_cb;
+ options.callbacks.payload = &callcount;
cl_set_cleanup(&cleanup_local_repo, "foo");
cl_git_pass(git_repository_init(&repo, "foo", true));
cl_git_pass(git_remote_create(&origin, repo, GIT_REMOTE_ORIGIN, url));
- git_remote_set_callbacks(origin, &callbacks);
- cl_git_pass(git_remote_fetch(origin, NULL, NULL));
+ cl_git_pass(git_remote_fetch(origin, NULL, &options, NULL));
git_remote_free(origin);
cl_git_pass(git_revparse_single(&obj, repo, "origin/master"));
@@ -321,8 +303,7 @@ void test_network_fetchlocal__prune_tag(void)
git_config_free(config);
cl_git_pass(git_remote_lookup(&origin, repo, GIT_REMOTE_ORIGIN));
cl_assert_equal_i(1, git_remote_prune_refs(origin));
- git_remote_set_callbacks(origin, &callbacks);
- cl_git_pass(git_remote_fetch(origin, NULL, NULL));
+ cl_git_pass(git_remote_fetch(origin, NULL, &options, NULL));
assert_ref_exists(repo, "refs/tags/some-tag");
cl_git_fail_with(GIT_ENOTFOUND, git_reference_lookup(&ref, repo, "refs/remotes/origin/fake-remote"));
@@ -346,10 +327,10 @@ void test_network_fetchlocal__partial(void)
int callcount = 0;
git_strarray refnames = {0};
const char *url;
- git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;
+ git_fetch_options options = GIT_FETCH_OPTIONS_INIT;
- callbacks.transfer_progress = transfer_cb;
- callbacks.payload = &callcount;
+ options.callbacks.transfer_progress = transfer_cb;
+ options.callbacks.payload = &callcount;
cl_set_cleanup(&cleanup_sandbox, NULL);
cl_git_pass(git_reference_list(&refnames, repo));
@@ -357,10 +338,7 @@ void test_network_fetchlocal__partial(void)
url = cl_git_fixture_url("testrepo.git");
cl_git_pass(git_remote_create(&origin, repo, GIT_REMOTE_ORIGIN, url));
- git_remote_set_callbacks(origin, &callbacks);
- cl_git_pass(git_remote_connect(origin, GIT_DIRECTION_FETCH));
- cl_git_pass(git_remote_download(origin, NULL));
- cl_git_pass(git_remote_update_tips(origin, NULL));
+ cl_git_pass(git_remote_fetch(origin, NULL, &options, NULL));
git_strarray_free(&refnames);
@@ -418,16 +396,13 @@ void test_network_fetchlocal__multi_remotes(void)
git_repository *repo = cl_git_sandbox_init("testrepo.git");
git_remote *test, *test2;
git_strarray refnames = {0};
- git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;
+ git_fetch_options options = GIT_FETCH_OPTIONS_INIT;
cl_set_cleanup(&cleanup_sandbox, NULL);
- callbacks.transfer_progress = transfer_cb;
+ options.callbacks.transfer_progress = transfer_cb;
cl_git_pass(git_remote_lookup(&test, repo, "test"));
cl_git_pass(git_remote_set_url(test, cl_git_fixture_url("testrepo.git")));
- git_remote_set_callbacks(test, &callbacks);
- cl_git_pass(git_remote_connect(test, GIT_DIRECTION_FETCH));
- cl_git_pass(git_remote_download(test, NULL));
- cl_git_pass(git_remote_update_tips(test, NULL));
+ cl_git_pass(git_remote_fetch(test, NULL, &options, NULL));
cl_git_pass(git_reference_list(&refnames, repo));
cl_assert_equal_i(32, (int)refnames.count);
@@ -435,10 +410,7 @@ void test_network_fetchlocal__multi_remotes(void)
cl_git_pass(git_remote_lookup(&test2, repo, "test_with_pushurl"));
cl_git_pass(git_remote_set_url(test2, cl_git_fixture_url("testrepo.git")));
- git_remote_set_callbacks(test2, &callbacks);
- cl_git_pass(git_remote_connect(test2, GIT_DIRECTION_FETCH));
- cl_git_pass(git_remote_download(test2, NULL));
- cl_git_pass(git_remote_update_tips(test2, NULL));
+ cl_git_pass(git_remote_fetch(test2, NULL, &options, NULL));
cl_git_pass(git_reference_list(&refnames, repo));
cl_assert_equal_i(44, (int)refnames.count);
@@ -463,7 +435,7 @@ void test_network_fetchlocal__call_progress(void)
{
git_repository *repo;
git_remote *remote;
- git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;
+ git_fetch_options options = GIT_FETCH_OPTIONS_INIT;
int callcount = 0;
cl_git_pass(git_repository_init(&repo, "foo.git", true));
@@ -471,11 +443,10 @@ void test_network_fetchlocal__call_progress(void)
cl_git_pass(git_remote_create_with_fetchspec(&remote, repo, "origin", cl_git_fixture_url("testrepo.git"), "+refs/heads/*:refs/heads/*"));
- callbacks.sideband_progress = sideband_cb;
- callbacks.payload = &callcount;
- cl_git_pass(git_remote_set_callbacks(remote, &callbacks));
+ options.callbacks.sideband_progress = sideband_cb;
+ options.callbacks.payload = &callcount;
- cl_git_pass(git_remote_fetch(remote, NULL, NULL));
+ cl_git_pass(git_remote_fetch(remote, NULL, &options, NULL));
cl_assert(callcount != 0);
git_remote_free(remote);
diff --git a/tests/network/remote/defaultbranch.c b/tests/network/remote/defaultbranch.c
index c83d5c8b0..e83755ef6 100644
--- a/tests/network/remote/defaultbranch.c
+++ b/tests/network/remote/defaultbranch.c
@@ -26,7 +26,7 @@ static void assert_default_branch(const char *should)
{
git_buf name = GIT_BUF_INIT;
- cl_git_pass(git_remote_connect(g_remote, GIT_DIRECTION_FETCH));
+ cl_git_pass(git_remote_connect(g_remote, GIT_DIRECTION_FETCH, NULL));
cl_git_pass(git_remote_default_branch(&name, g_remote));
cl_assert_equal_s(should, name.ptr);
git_buf_free(&name);
@@ -57,7 +57,7 @@ void test_network_remote_defaultbranch__no_default_branch(void)
git_buf buf = GIT_BUF_INIT;
cl_git_pass(git_remote_create(&remote_b, g_repo_b, "self", git_repository_path(g_repo_b)));
- cl_git_pass(git_remote_connect(remote_b, GIT_DIRECTION_FETCH));
+ cl_git_pass(git_remote_connect(remote_b, GIT_DIRECTION_FETCH, NULL));
cl_git_pass(git_remote_ls(&heads, &len, remote_b));
cl_assert_equal_i(0, len);
@@ -80,7 +80,7 @@ void test_network_remote_defaultbranch__detached_sharing_nonbranch_id(void)
cl_git_pass(git_reference_create(&ref, g_repo_a, "refs/foo/bar", &id, 1, NULL));
git_reference_free(ref);
- cl_git_pass(git_remote_connect(g_remote, GIT_DIRECTION_FETCH));
+ cl_git_pass(git_remote_connect(g_remote, GIT_DIRECTION_FETCH, NULL));
cl_git_fail_with(GIT_ENOTFOUND, git_remote_default_branch(&buf, g_remote));
cl_git_pass(git_clone(&cloned_repo, git_repository_path(g_repo_a), "./local-detached", NULL));
diff --git a/tests/network/remote/local.c b/tests/network/remote/local.c
index ba54de6af..1e03371f0 100644
--- a/tests/network/remote/local.c
+++ b/tests/network/remote/local.c
@@ -40,7 +40,7 @@ static void connect_to_local_repository(const char *local_repository)
git_buf_sets(&file_path_buf, cl_git_path_url(local_repository));
cl_git_pass(git_remote_create_anonymous(&remote, repo, git_buf_cstr(&file_path_buf), NULL));
- cl_git_pass(git_remote_connect(remote, GIT_DIRECTION_FETCH));
+ cl_git_pass(git_remote_connect(remote, GIT_DIRECTION_FETCH, NULL));
}
void test_network_remote_local__connected(void)
@@ -138,8 +138,7 @@ void test_network_remote_local__shorthand_fetch_refspec0(void)
connect_to_local_repository(cl_fixture("testrepo.git"));
- cl_git_pass(git_remote_download(remote, &array));
- cl_git_pass(git_remote_update_tips(remote, NULL));
+ cl_git_pass(git_remote_fetch(remote, &array, NULL, NULL));
cl_git_pass(git_reference_lookup(&ref, repo, "refs/remotes/sloppy/master"));
git_reference_free(ref);
@@ -164,8 +163,7 @@ void test_network_remote_local__shorthand_fetch_refspec1(void)
connect_to_local_repository(cl_fixture("testrepo.git"));
git_remote_clear_refspecs(remote);
- cl_git_pass(git_remote_download(remote, &array));
- cl_git_pass(git_remote_update_tips(remote, NULL));
+ cl_git_pass(git_remote_fetch(remote, &array, NULL, NULL));
cl_git_fail(git_reference_lookup(&ref, repo, "refs/remotes/master"));
@@ -178,7 +176,7 @@ void test_network_remote_local__tagopt(void)
cl_git_pass(git_remote_create(&remote, repo, "tagopt", cl_git_path_url(cl_fixture("testrepo.git"))));
git_remote_set_autotag(remote, GIT_REMOTE_DOWNLOAD_TAGS_ALL);
- cl_git_pass(git_remote_fetch(remote, NULL, NULL));
+ cl_git_pass(git_remote_fetch(remote, NULL, NULL, NULL));
cl_git_pass(git_reference_lookup(&ref, repo, "refs/remotes/tagopt/master"));
git_reference_free(ref);
@@ -186,7 +184,7 @@ void test_network_remote_local__tagopt(void)
git_reference_free(ref);
git_remote_set_autotag(remote, GIT_REMOTE_DOWNLOAD_TAGS_AUTO);
- cl_git_pass(git_remote_fetch(remote, NULL, NULL));
+ cl_git_pass(git_remote_fetch(remote, NULL, NULL, NULL));
cl_git_pass(git_reference_lookup(&ref, repo, "refs/remotes/tagopt/master"));
git_reference_free(ref);
}
@@ -206,9 +204,7 @@ void test_network_remote_local__push_to_bare_remote(void)
/* Get some commits */
connect_to_local_repository(cl_fixture("testrepo.git"));
- cl_git_pass(git_remote_download(remote, &array));
- cl_git_pass(git_remote_update_tips(remote, NULL));
- git_remote_disconnect(remote);
+ cl_git_pass(git_remote_fetch(remote, &array, NULL, NULL));
/* Set up an empty bare repo to push into */
{
@@ -219,7 +215,7 @@ void test_network_remote_local__push_to_bare_remote(void)
/* Connect to the bare repo */
cl_git_pass(git_remote_create_anonymous(&localremote, repo, "./localbare.git", NULL));
- cl_git_pass(git_remote_connect(localremote, GIT_DIRECTION_PUSH));
+ cl_git_pass(git_remote_connect(localremote, GIT_DIRECTION_PUSH, NULL));
/* Try to push */
cl_git_pass(git_remote_upload(remote, &push_array, NULL));
@@ -244,8 +240,8 @@ void test_network_remote_local__push_to_bare_remote_with_file_url(void)
/* Get some commits */
connect_to_local_repository(cl_fixture("testrepo.git"));
- cl_git_pass(git_remote_download(remote, &array));
- cl_git_pass(git_remote_update_tips(remote, NULL));
+ cl_git_pass(git_remote_download(remote, &array, NULL));
+ cl_git_pass(git_remote_update_tips(remote, NULL, NULL));
git_remote_disconnect(remote);
/* Set up an empty bare repo to push into */
@@ -260,7 +256,7 @@ void test_network_remote_local__push_to_bare_remote_with_file_url(void)
/* Connect to the bare repo */
cl_git_pass(git_remote_create_anonymous(&localremote, repo, url, NULL));
- cl_git_pass(git_remote_connect(localremote, GIT_DIRECTION_PUSH));
+ cl_git_pass(git_remote_connect(localremote, GIT_DIRECTION_PUSH, NULL));
/* Try to push */
cl_git_pass(git_remote_upload(remote, &push_array, NULL));
@@ -285,8 +281,8 @@ void test_network_remote_local__push_to_non_bare_remote(void)
/* Get some commits */
connect_to_local_repository(cl_fixture("testrepo.git"));
- cl_git_pass(git_remote_download(remote, &array));
- cl_git_pass(git_remote_update_tips(remote, NULL));
+ cl_git_pass(git_remote_download(remote, &array, NULL));
+ cl_git_pass(git_remote_update_tips(remote, NULL, NULL));
git_remote_disconnect(remote);
/* Set up an empty non-bare repo to push into */
@@ -298,7 +294,7 @@ void test_network_remote_local__push_to_non_bare_remote(void)
/* Connect to the bare repo */
cl_git_pass(git_remote_create_anonymous(&localremote, repo, "./localnonbare", NULL));
- cl_git_pass(git_remote_connect(localremote, GIT_DIRECTION_PUSH));
+ cl_git_pass(git_remote_connect(localremote, GIT_DIRECTION_PUSH, NULL));
/* Try to push */
cl_git_fail_with(GIT_EBAREREPO, git_remote_upload(localremote, &push_array, NULL));
@@ -324,7 +320,7 @@ void test_network_remote_local__fetch(void)
connect_to_local_repository(cl_fixture("testrepo.git"));
- cl_git_pass(git_remote_fetch(remote, &array, "UPDAAAAAATE!!"));
+ cl_git_pass(git_remote_fetch(remote, &array, NULL, "UPDAAAAAATE!!"));
cl_git_pass(git_reference_lookup(&ref, repo, "refs/remotes/sloppy/master"));
git_reference_free(ref);
@@ -353,8 +349,8 @@ void test_network_remote_local__reflog(void)
connect_to_local_repository(cl_fixture("testrepo.git"));
- cl_git_pass(git_remote_download(remote, &array));
- cl_git_pass(git_remote_update_tips(remote, "UPDAAAAAATE!!"));
+ cl_git_pass(git_remote_download(remote, &array, NULL));
+ cl_git_pass(git_remote_update_tips(remote, NULL, "UPDAAAAAATE!!"));
cl_git_pass(git_reflog_read(&log, repo, "refs/remotes/sloppy/master"));
cl_assert_equal_i(1, git_reflog_entrycount(log));
@@ -381,7 +377,7 @@ void test_network_remote_local__fetch_default_reflog_message(void)
connect_to_local_repository(cl_fixture("testrepo.git"));
- cl_git_pass(git_remote_fetch(remote, &array, NULL));
+ cl_git_pass(git_remote_fetch(remote, &array, NULL, NULL));
cl_git_pass(git_reflog_read(&log, repo, "refs/remotes/sloppy/master"));
cl_assert_equal_i(1, git_reflog_entrycount(log));
@@ -408,7 +404,7 @@ void test_network_remote_local__opportunistic_update(void)
/* this remote has a passive refspec of "refs/heads/<star>:refs/remotes/origin/<star>" */
cl_git_pass(git_remote_create(&remote, repo, "origin", cl_git_fixture_url("testrepo.git")));
/* and we pass the active refspec "master" */
- cl_git_pass(git_remote_fetch(remote, &array, NULL));
+ cl_git_pass(git_remote_fetch(remote, &array, NULL, NULL));
/* and we expect that to update our copy of origin's master */
cl_git_pass(git_reference_lookup(&ref, repo, "refs/remotes/origin/master"));
@@ -430,11 +426,8 @@ void test_network_remote_local__update_tips_for_new_remote(void) {
/* Push to bare repo */
cl_git_pass(git_remote_create(&new_remote, src_repo, "bare", "./localbare.git"));
- cl_git_pass(git_remote_connect(new_remote, GIT_DIRECTION_PUSH));
- cl_git_pass(git_remote_upload(new_remote, &push_array, NULL));
-
- /* Update tips and make sure remote branch has been created */
- cl_git_pass(git_remote_update_tips(new_remote, NULL));
+ cl_git_pass(git_remote_push(new_remote, &push_array, NULL));
+ /* Make sure remote branch has been created */
cl_git_pass(git_branch_lookup(&branch, src_repo, "bare/master", GIT_BRANCH_REMOTE));
git_reference_free(branch);
diff --git a/tests/network/remote/remotes.c b/tests/network/remote/remotes.c
index 3e6e438cc..456fb39fe 100644
--- a/tests/network/remote/remotes.c
+++ b/tests/network/remote/remotes.c
@@ -86,7 +86,7 @@ void test_network_remote_remotes__error_when_no_push_available(void)
cl_git_pass(git_remote_set_transport(r, git_transport_local, NULL));
- cl_git_pass(git_remote_connect(r, GIT_DIRECTION_PUSH));
+ cl_git_pass(git_remote_connect(r, GIT_DIRECTION_PUSH, NULL));
/* Make sure that push is really not available */
r->transport->push = NULL;
@@ -273,7 +273,7 @@ void test_network_remote_remotes__nonmatch_upstream_refspec(void)
cl_git_pass(git_config_set_string(config, "branch.master.remote", "taggy"));
cl_git_pass(git_config_set_string(config, "branch.master.merge", "refs/heads/foo"));
- cl_git_pass(git_remote_fetch(remote, &specs, NULL));
+ cl_git_pass(git_remote_fetch(remote, &specs, NULL, NULL));
git_remote_free(remote);
}
@@ -408,7 +408,7 @@ void test_network_remote_remotes__can_load_with_an_empty_url(void)
cl_assert(remote->url == NULL);
cl_assert(remote->pushurl == NULL);
- cl_git_fail(git_remote_connect(remote, GIT_DIRECTION_FETCH));
+ cl_git_fail(git_remote_connect(remote, GIT_DIRECTION_FETCH, NULL));
cl_assert(giterr_last() != NULL);
cl_assert(giterr_last()->klass == GITERR_INVALID);
@@ -425,7 +425,7 @@ void test_network_remote_remotes__can_load_with_only_an_empty_pushurl(void)
cl_assert(remote->url == NULL);
cl_assert(remote->pushurl == NULL);
- cl_git_fail(git_remote_connect(remote, GIT_DIRECTION_FETCH));
+ cl_git_fail(git_remote_connect(remote, GIT_DIRECTION_FETCH, NULL));
git_remote_free(remote);
}
@@ -519,6 +519,6 @@ void test_network_remote_remotes__fetch_from_anonymous(void)
cl_git_pass(git_remote_create_anonymous(&remote, _repo, cl_fixture("testrepo.git"),
"refs/heads/*:refs/other/*"));
- cl_git_pass(git_remote_fetch(remote, NULL, NULL));
+ cl_git_pass(git_remote_fetch(remote, NULL, NULL, NULL));
git_remote_free(remote);
}
diff --git a/tests/online/clone.c b/tests/online/clone.c
index 4fdeee1d2..35ddbe9af 100644
--- a/tests/online/clone.c
+++ b/tests/online/clone.c
@@ -20,7 +20,7 @@ static git_clone_options g_options;
void test_online_clone__initialize(void)
{
git_checkout_options dummy_opts = GIT_CHECKOUT_OPTIONS_INIT;
- git_remote_callbacks dummy_callbacks = GIT_REMOTE_CALLBACKS_INIT;
+ git_fetch_options dummy_fetch = GIT_FETCH_OPTIONS_INIT;
g_repo = NULL;
@@ -28,7 +28,7 @@ void test_online_clone__initialize(void)
g_options.version = GIT_CLONE_OPTIONS_VERSION;
g_options.checkout_opts = dummy_opts;
g_options.checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE;
- g_options.remote_callbacks = dummy_callbacks;
+ g_options.fetch_opts = dummy_fetch;
}
void test_online_clone__cleanup(void)
@@ -107,8 +107,8 @@ void test_online_clone__can_checkout_a_cloned_repo(void)
g_options.checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE;
g_options.checkout_opts.progress_cb = &checkout_progress;
g_options.checkout_opts.progress_payload = &checkout_progress_cb_was_called;
- g_options.remote_callbacks.transfer_progress = &fetch_progress;
- g_options.remote_callbacks.payload = &fetch_progress_cb_was_called;
+ g_options.fetch_opts.callbacks.transfer_progress = &fetch_progress;
+ g_options.fetch_opts.callbacks.payload = &fetch_progress_cb_was_called;
cl_git_pass(git_clone(&g_repo, LIVE_REPO_URL, "./foo", &g_options));
@@ -131,17 +131,12 @@ static int remote_mirror_cb(git_remote **out, git_repository *repo,
{
int error;
git_remote *remote;
- git_remote_callbacks *callbacks = (git_remote_callbacks *) payload;
+ GIT_UNUSED(payload);
if ((error = git_remote_create(&remote, repo, name, url)) < 0)
return error;
- if ((error = git_remote_set_callbacks(remote, callbacks)) < 0) {
- git_remote_free(remote);
- return error;
- }
-
git_remote_clear_refspecs(remote);
if ((error = git_remote_add_fetch(remote, "+refs/*:refs/*")) < 0) {
@@ -157,16 +152,14 @@ void test_online_clone__clone_mirror(void)
{
git_clone_options opts = GIT_CLONE_OPTIONS_INIT;
git_reference *head;
- git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;
bool fetch_progress_cb_was_called = false;
- callbacks.transfer_progress = &fetch_progress;
- callbacks.payload = &fetch_progress_cb_was_called;
+ opts.fetch_opts.callbacks.transfer_progress = &fetch_progress;
+ opts.fetch_opts.callbacks.payload = &fetch_progress_cb_was_called;
opts.bare = true;
opts.remote_cb = remote_mirror_cb;
- opts.remote_cb_payload = &callbacks;
cl_git_pass(git_clone(&g_repo, LIVE_REPO_URL, "./foo.git", &opts));
@@ -195,8 +188,8 @@ void test_online_clone__custom_remote_callbacks(void)
{
int callcount = 0;
- g_options.remote_callbacks.update_tips = update_tips;
- g_options.remote_callbacks.payload = &callcount;
+ g_options.fetch_opts.callbacks.update_tips = update_tips;
+ g_options.fetch_opts.callbacks.payload = &callcount;
cl_git_pass(git_clone(&g_repo, LIVE_REPO_URL, "./foo", &g_options));
cl_assert(callcount > 0);
@@ -222,7 +215,7 @@ void test_online_clone__cred_callback_failure_return_code_is_tunnelled(void)
if (!remote_url || !remote_user)
clar__skip();
- g_options.remote_callbacks.credentials = cred_failure_cb;
+ g_options.fetch_opts.callbacks.credentials = cred_failure_cb;
cl_git_fail_with(-172, git_clone(&g_repo, remote_url, "./foo", &g_options));
}
@@ -254,8 +247,8 @@ void test_online_clone__cred_callback_called_again_on_auth_failure(void)
if (!remote_url || !remote_user)
clar__skip();
- g_options.remote_callbacks.credentials = cred_count_calls_cb;
- g_options.remote_callbacks.payload = &counter;
+ g_options.fetch_opts.callbacks.credentials = cred_count_calls_cb;
+ g_options.fetch_opts.callbacks.payload = &counter;
cl_git_fail_with(GIT_EUSER, git_clone(&g_repo, remote_url, "./foo", &g_options));
cl_assert_equal_i(3, counter);
@@ -292,10 +285,10 @@ void test_online_clone__credentials(void)
if (!remote_url) return;
if (cl_getenv("GITTEST_REMOTE_DEFAULT")) {
- g_options.remote_callbacks.credentials = cred_default;
+ g_options.fetch_opts.callbacks.credentials = cred_default;
} else {
- g_options.remote_callbacks.credentials = git_cred_userpass;
- g_options.remote_callbacks.payload = &user_pass;
+ g_options.fetch_opts.callbacks.credentials = git_cred_userpass;
+ g_options.fetch_opts.callbacks.payload = &user_pass;
}
cl_git_pass(git_clone(&g_repo, remote_url, "./foo", &g_options));
@@ -309,8 +302,8 @@ void test_online_clone__bitbucket_style(void)
"libgit2", "libgit2"
};
- g_options.remote_callbacks.credentials = git_cred_userpass;
- g_options.remote_callbacks.payload = &user_pass;
+ g_options.fetch_opts.callbacks.credentials = git_cred_userpass;
+ g_options.fetch_opts.callbacks.payload = &user_pass;
cl_git_pass(git_clone(&g_repo, BB_REPO_URL, "./foo", &g_options));
git_repository_free(g_repo); g_repo = NULL;
@@ -340,7 +333,7 @@ static int cancel_at_half(const git_transfer_progress *stats, void *payload)
void test_online_clone__can_cancel(void)
{
- g_options.remote_callbacks.transfer_progress = cancel_at_half;
+ g_options.fetch_opts.callbacks.transfer_progress = cancel_at_half;
cl_git_fail_with(
git_clone(&g_repo, LIVE_REPO_URL, "./foo", &g_options), 4321);
@@ -387,8 +380,8 @@ void test_online_clone__ssh_auth_methods(void)
#ifndef GIT_SSH
clar__skip();
#endif
- g_options.remote_callbacks.credentials = check_ssh_auth_methods;
- g_options.remote_callbacks.payload = &with_user;
+ g_options.fetch_opts.callbacks.credentials = check_ssh_auth_methods;
+ g_options.fetch_opts.callbacks.payload = &with_user;
with_user = 0;
cl_git_fail_with(GIT_EUSER,
@@ -407,7 +400,6 @@ static int custom_remote_ssh_with_paths(
void *payload)
{
int error;
- git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;
if ((error = git_remote_create(out, repo, name, url)) < 0)
return error;
@@ -415,9 +407,6 @@ static int custom_remote_ssh_with_paths(
if ((error = git_remote_set_transport(*out, git_transport_ssh_with_paths, payload)) < 0)
return error;
- callbacks.credentials = cred_cb;
- git_remote_set_callbacks(*out, &callbacks);
-
return 0;
}
@@ -468,7 +457,7 @@ void test_online_clone__ssh_cannot_change_username(void)
#ifndef GIT_SSH
clar__skip();
#endif
- g_options.remote_callbacks.credentials = cred_foo_bar;
+ g_options.fetch_opts.callbacks.credentials = cred_foo_bar;
cl_git_fail(git_clone(&g_repo, "ssh://git@github.com/libgit2/TestGitRepository", "./foo", &g_options));
}
@@ -511,7 +500,7 @@ int ssh_certificate_check(git_cert *cert, int valid, const char *host, void *pay
void test_online_clone__ssh_cert(void)
{
- g_options.remote_callbacks.certificate_check = ssh_certificate_check;
+ g_options.fetch_opts.callbacks.certificate_check = ssh_certificate_check;
if (!cl_getenv("GITTEST_REMOTE_SSH_FINGERPRINT"))
cl_skip();
@@ -537,7 +526,7 @@ static int fail_certificate_check(git_cert *cert, int valid, const char *host, v
void test_online_clone__certificate_invalid(void)
{
- g_options.remote_callbacks.certificate_check = fail_certificate_check;
+ g_options.fetch_opts.callbacks.certificate_check = fail_certificate_check;
cl_git_fail_with(git_clone(&g_repo, "https://github.com/libgit2/TestGitRepository", "./foo", &g_options),
GIT_ECERTIFICATE);
@@ -561,14 +550,14 @@ static int succeed_certificate_check(git_cert *cert, int valid, const char *host
void test_online_clone__certificate_valid(void)
{
- g_options.remote_callbacks.certificate_check = succeed_certificate_check;
+ g_options.fetch_opts.callbacks.certificate_check = succeed_certificate_check;
cl_git_pass(git_clone(&g_repo, "https://github.com/libgit2/TestGitRepository", "./foo", &g_options));
}
void test_online_clone__start_with_http(void)
{
- g_options.remote_callbacks.certificate_check = succeed_certificate_check;
+ g_options.fetch_opts.callbacks.certificate_check = succeed_certificate_check;
cl_git_pass(git_clone(&g_repo, "http://github.com/libgit2/TestGitRepository", "./foo", &g_options));
}
diff --git a/tests/online/fetch.c b/tests/online/fetch.c
index 22f32ba1a..1a0f05039 100644
--- a/tests/online/fetch.c
+++ b/tests/online/fetch.c
@@ -35,21 +35,17 @@ static int progress(const git_transfer_progress *stats, void *payload)
static void do_fetch(const char *url, git_remote_autotag_option_t flag, int n)
{
git_remote *remote;
- git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;
+ git_fetch_options options = GIT_FETCH_OPTIONS_INIT;
size_t bytes_received = 0;
- callbacks.transfer_progress = progress;
- callbacks.update_tips = update_tips;
- callbacks.payload = &bytes_received;
+ options.callbacks.transfer_progress = progress;
+ options.callbacks.update_tips = update_tips;
+ options.callbacks.payload = &bytes_received;
counter = 0;
cl_git_pass(git_remote_create(&remote, _repo, "test", url));
- git_remote_set_callbacks(remote, &callbacks);
git_remote_set_autotag(remote, flag);
- cl_git_pass(git_remote_connect(remote, GIT_DIRECTION_FETCH));
- cl_git_pass(git_remote_download(remote, NULL));
- cl_git_pass(git_remote_update_tips(remote, NULL));
- git_remote_disconnect(remote);
+ cl_git_pass(git_remote_fetch(remote, NULL, &options, NULL));
cl_assert_equal_i(counter, n);
cl_assert(bytes_received > 0);
@@ -85,12 +81,12 @@ void test_online_fetch__fetch_twice(void)
{
git_remote *remote;
cl_git_pass(git_remote_create(&remote, _repo, "test", "git://github.com/libgit2/TestGitRepository.git"));
- cl_git_pass(git_remote_connect(remote, GIT_DIRECTION_FETCH));
- cl_git_pass(git_remote_download(remote, NULL));
+ cl_git_pass(git_remote_connect(remote, GIT_DIRECTION_FETCH, NULL));
+ cl_git_pass(git_remote_download(remote, NULL, NULL));
git_remote_disconnect(remote);
- git_remote_connect(remote, GIT_DIRECTION_FETCH);
- cl_git_pass(git_remote_download(remote, NULL));
+ git_remote_connect(remote, GIT_DIRECTION_FETCH, NULL);
+ cl_git_pass(git_remote_download(remote, NULL, NULL));
git_remote_disconnect(remote);
git_remote_free(remote);
@@ -110,7 +106,7 @@ void test_online_fetch__doesnt_retrieve_a_pack_when_the_repository_is_up_to_date
git_repository *_repository;
bool invoked = false;
git_remote *remote;
- git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;
+ git_fetch_options options = GIT_FETCH_OPTIONS_INIT;
git_clone_options opts = GIT_CLONE_OPTIONS_INIT;
opts.bare = true;
@@ -121,18 +117,17 @@ void test_online_fetch__doesnt_retrieve_a_pack_when_the_repository_is_up_to_date
cl_git_pass(git_repository_open(&_repository, "./fetch/lg2"));
cl_git_pass(git_remote_lookup(&remote, _repository, "origin"));
- cl_git_pass(git_remote_connect(remote, GIT_DIRECTION_FETCH));
+ cl_git_pass(git_remote_connect(remote, GIT_DIRECTION_FETCH, NULL));
cl_assert_equal_i(false, invoked);
- callbacks.transfer_progress = &transferProgressCallback;
- callbacks.payload = &invoked;
- git_remote_set_callbacks(remote, &callbacks);
- cl_git_pass(git_remote_download(remote, NULL));
+ options.callbacks.transfer_progress = &transferProgressCallback;
+ options.callbacks.payload = &invoked;
+ cl_git_pass(git_remote_download(remote, NULL, &options));
cl_assert_equal_i(false, invoked);
- cl_git_pass(git_remote_update_tips(remote, NULL));
+ cl_git_pass(git_remote_update_tips(remote, &options.callbacks, NULL));
git_remote_disconnect(remote);
git_remote_free(remote);
@@ -152,17 +147,16 @@ void test_online_fetch__can_cancel(void)
{
git_remote *remote;
size_t bytes_received = 0;
- git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;
+ git_fetch_options options = GIT_FETCH_OPTIONS_INIT;
cl_git_pass(git_remote_create(&remote, _repo, "test",
"http://github.com/libgit2/TestGitRepository.git"));
- callbacks.transfer_progress = cancel_at_half;
- callbacks.payload = &bytes_received;
- git_remote_set_callbacks(remote, &callbacks);
+ options.callbacks.transfer_progress = cancel_at_half;
+ options.callbacks.payload = &bytes_received;
- cl_git_pass(git_remote_connect(remote, GIT_DIRECTION_FETCH));
- cl_git_fail_with(git_remote_download(remote, NULL), -4321);
+ cl_git_pass(git_remote_connect(remote, GIT_DIRECTION_FETCH, NULL));
+ cl_git_fail_with(git_remote_download(remote, NULL, &options), -4321);
git_remote_disconnect(remote);
git_remote_free(remote);
}
@@ -175,7 +169,7 @@ void test_online_fetch__ls_disconnected(void)
cl_git_pass(git_remote_create(&remote, _repo, "test",
"http://github.com/libgit2/TestGitRepository.git"));
- cl_git_pass(git_remote_connect(remote, GIT_DIRECTION_FETCH));
+ cl_git_pass(git_remote_connect(remote, GIT_DIRECTION_FETCH, NULL));
cl_git_pass(git_remote_ls(&refs, &refs_len_before, remote));
git_remote_disconnect(remote);
cl_git_pass(git_remote_ls(&refs, &refs_len_after, remote));
@@ -193,7 +187,7 @@ void test_online_fetch__remote_symrefs(void)
cl_git_pass(git_remote_create(&remote, _repo, "test",
"http://github.com/libgit2/TestGitRepository.git"));
- cl_git_pass(git_remote_connect(remote, GIT_DIRECTION_FETCH));
+ cl_git_pass(git_remote_connect(remote, GIT_DIRECTION_FETCH, NULL));
git_remote_disconnect(remote);
cl_git_pass(git_remote_ls(&refs, &refs_len, remote));
@@ -208,8 +202,8 @@ void test_online_fetch__twice(void)
git_remote *remote;
cl_git_pass(git_remote_create(&remote, _repo, "test", "http://github.com/libgit2/TestGitRepository.git"));
- cl_git_pass(git_remote_fetch(remote, NULL, NULL));
- cl_git_pass(git_remote_fetch(remote, NULL, NULL));
+ cl_git_pass(git_remote_fetch(remote, NULL, NULL, NULL));
+ cl_git_pass(git_remote_fetch(remote, NULL, NULL, NULL));
git_remote_free(remote);
}
diff --git a/tests/online/fetchhead.c b/tests/online/fetchhead.c
index 9a97abef3..b24b1b511 100644
--- a/tests/online/fetchhead.c
+++ b/tests/online/fetchhead.c
@@ -12,12 +12,12 @@ static git_clone_options g_options;
void test_online_fetchhead__initialize(void)
{
- git_remote_callbacks dummy_callbacks = GIT_REMOTE_CALLBACKS_INIT;
+ git_fetch_options dummy_fetch = GIT_FETCH_OPTIONS_INIT;
g_repo = NULL;
memset(&g_options, 0, sizeof(git_clone_options));
g_options.version = GIT_CLONE_OPTIONS_VERSION;
- g_options.remote_callbacks = dummy_callbacks;
+ g_options.fetch_opts = dummy_fetch;
}
void test_online_fetchhead__cleanup(void)
@@ -51,10 +51,7 @@ static void fetchhead_test_fetch(const char *fetchspec, const char *expected_fet
active_refs = &array;
}
- cl_git_pass(git_remote_connect(remote, GIT_DIRECTION_FETCH));
- cl_git_pass(git_remote_download(remote, active_refs));
- cl_git_pass(git_remote_update_tips(remote, NULL));
- git_remote_disconnect(remote);
+ cl_git_pass(git_remote_fetch(remote, active_refs, NULL, NULL));
git_remote_free(remote);
cl_git_pass(git_futils_readbuffer(&fetchhead_buf, "./foo/.git/FETCH_HEAD"));
diff --git a/tests/online/push.c b/tests/online/push.c
index 9b98bc77a..b35632755 100644
--- a/tests/online/push.c
+++ b/tests/online/push.c
@@ -369,9 +369,8 @@ void test_online_push__initialize(void)
cl_git_pass(git_remote_create(&_remote, _repo, "test", _remote_url));
record_callbacks_data_clear(&_record_cbs_data);
- git_remote_set_callbacks(_remote, &_record_cbs);
- cl_git_pass(git_remote_connect(_remote, GIT_DIRECTION_PUSH));
+ cl_git_pass(git_remote_connect(_remote, GIT_DIRECTION_PUSH, NULL));
/* Clean up previously pushed branches. Fails if receive.denyDeletes is
* set on the remote. Also, on Git 1.7.0 and newer, you must run
@@ -394,10 +393,7 @@ void test_online_push__initialize(void)
git_vector_free(&delete_specs);
/* Now that we've deleted everything, fetch from the remote */
- cl_git_pass(git_remote_connect(_remote, GIT_DIRECTION_FETCH));
- cl_git_pass(git_remote_download(_remote, NULL));
- cl_git_pass(git_remote_update_tips(_remote, NULL));
- git_remote_disconnect(_remote);
+ cl_git_pass(git_remote_fetch(_remote, NULL, NULL, NULL));
}
void test_online_push__cleanup(void)
@@ -459,20 +455,18 @@ static void do_push(
size_t i;
int error;
git_strarray specs = {0};
- git_remote_callbacks callbacks;
record_callbacks_data *data;
if (_remote) {
/* Auto-detect the number of threads to use */
opts.pb_parallelism = 0;
- memcpy(&callbacks, git_remote_get_callbacks(_remote), sizeof(callbacks));
- data = callbacks.payload;
+ memcpy(&opts.callbacks, &_record_cbs, sizeof(git_remote_callbacks));
+ data = opts.callbacks.payload;
- callbacks.pack_progress = push_pack_progress_cb;
- callbacks.push_transfer_progress = push_transfer_progress_cb;
- callbacks.push_update_reference = record_push_status_cb;
- cl_git_pass(git_remote_set_callbacks(_remote, &callbacks));
+ opts.callbacks.pack_progress = push_pack_progress_cb;
+ opts.callbacks.push_transfer_progress = push_transfer_progress_cb;
+ opts.callbacks.push_update_reference = record_push_status_cb;
if (refspecs_len) {
specs.count = refspecs_len;
diff --git a/tests/submodule/update.c b/tests/submodule/update.c
index 533e64efc..e7f1b76b8 100644
--- a/tests/submodule/update.c
+++ b/tests/submodule/update.c
@@ -96,8 +96,8 @@ void test_submodule_update__update_submodule(void)
update_options.checkout_opts.progress_cb = checkout_progress_cb;
update_options.checkout_opts.progress_payload = &update_payload;
- update_options.remote_callbacks.update_tips = update_tips;
- update_options.remote_callbacks.payload = &update_payload;
+ update_options.fetch_opts.callbacks.update_tips = update_tips;
+ update_options.fetch_opts.callbacks.payload = &update_payload;
/* get the submodule */
cl_git_pass(git_submodule_lookup(&sm, g_repo, "testrepo"));