summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@dwim.me>2015-04-22 16:11:10 +0200
committerCarlos Martín Nieto <cmn@dwim.me>2015-05-13 09:46:36 +0200
commit3eff2a57289ec19b1a805dd938299d1dcae47097 (patch)
tree3bd01239ee483c5a8d60768228d9968f2ff90611
parent058b753ceb8f6b25b77e57106b3a87997bc6362a (diff)
downloadlibgit2-3eff2a57289ec19b1a805dd938299d1dcae47097.tar.gz
remote: move the update_fetchhead setting to the options
While this will rarely be different from the default, having it in the remote adds yet another setting it has to keep around and can affect its behaviour. Move it to the options.
-rw-r--r--include/git2/remote.h27
-rw-r--r--src/clone.c6
-rw-r--r--src/remote.c28
-rw-r--r--src/remote.h1
-rw-r--r--tests/network/remote/local.c6
-rw-r--r--tests/online/fetch.c2
6 files changed, 26 insertions, 44 deletions
diff --git a/include/git2/remote.h b/include/git2/remote.h
index 22aad5ad4..5b42a9899 100644
--- a/include/git2/remote.h
+++ b/include/git2/remote.h
@@ -538,10 +538,16 @@ typedef struct {
* Whether to perform a prune after the fetch
*/
git_fetch_prune_t prune;
+
+ /**
+ * Whether to write the results to FETCH_HEAD. Defaults to
+ * on. Leave this default in order to behave like git.
+ */
+ int update_fetchhead;
} git_fetch_options;
#define GIT_FETCH_OPTIONS_VERSION 1
-#define GIT_FETCH_OPTIONS_INIT { GIT_FETCH_OPTIONS_VERSION, GIT_REMOTE_CALLBACKS_INIT }
+#define GIT_FETCH_OPTIONS_INIT { GIT_FETCH_OPTIONS_VERSION, GIT_REMOTE_CALLBACKS_INIT, 0, 1 }
/**
* Initializes a `git_fetch_options` with default values. Equivalent to
@@ -636,11 +642,13 @@ GIT_EXTERN(int) git_remote_upload(git_remote *remote, const git_strarray *refspe
* 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
+ * @param update_fetchhead whether to write to FETCH_HEAD. Pass 1 to behave like git.
* @return 0 or an error code
*/
GIT_EXTERN(int) git_remote_update_tips(
git_remote *remote,
const git_remote_callbacks *callbacks,
+ int update_fetchhead,
const char *reflog_message);
/**
@@ -755,23 +763,6 @@ GIT_EXTERN(int) git_remote_rename(
const char *new_name);
/**
- * Retrieve the update FETCH_HEAD setting.
- *
- * @param remote the remote to query
- * @return the update FETCH_HEAD setting
- */
-GIT_EXTERN(int) git_remote_update_fetchhead(git_remote *remote);
-
-/**
- * Sets the update FETCH_HEAD setting. By default, FETCH_HEAD will be
- * updated on every fetch. Set to 0 to disable.
- *
- * @param remote the remote to configure
- * @param value 0 to disable updating FETCH_HEAD
- */
-GIT_EXTERN(void) git_remote_set_update_fetchhead(git_remote *remote, int value);
-
-/**
* Ensure the remote name is well-formed.
*
* @param remote_name name to be checked.
diff --git a/src/clone.c b/src/clone.c
index 53cdae673..7dcbb8a1d 100644
--- a/src/clone.c
+++ b/src/clone.c
@@ -328,6 +328,7 @@ static int clone_into(git_repository *repo, git_remote *_remote, const git_fetch
{
int error;
git_buf reflog_message = GIT_BUF_INIT;
+ git_fetch_options fetch_opts;
git_remote *remote;
assert(repo && _remote);
@@ -343,10 +344,11 @@ static int clone_into(git_repository *repo, git_remote *_remote, const git_fetch
if ((error = git_remote_add_fetch(remote, "refs/tags/*:refs/tags/*")) < 0)
goto cleanup;
- git_remote_set_update_fetchhead(remote, 0);
+ memcpy(&fetch_opts, opts, sizeof(git_fetch_options));
+ fetch_opts.update_fetchhead = 0;
git_buf_printf(&reflog_message, "clone: from %s", git_remote_url(remote));
- if ((error = git_remote_fetch(remote, NULL, opts, 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/remote.c b/src/remote.c
index 95c316f54..c4f5e0ff9 100644
--- a/src/remote.c
+++ b/src/remote.c
@@ -159,7 +159,6 @@ static int create_internal(git_remote **out, git_repository *repo, const char *n
GITERR_CHECK_ALLOC(remote);
remote->repo = repo;
- remote->update_fetchhead = 1;
if (git_vector_init(&remote->refs, 32, NULL) < 0 ||
canonicalize_url(&canonical_url, url) < 0)
@@ -311,7 +310,6 @@ int git_remote_dup(git_remote **dest, git_remote *source)
remote->repo = source->repo;
remote->download_tags = source->download_tags;
- remote->update_fetchhead = source->update_fetchhead;
remote->prune_refs = source->prune_refs;
if (git_vector_init(&remote->refs, 32, NULL) < 0 ||
@@ -401,7 +399,6 @@ int git_remote_lookup(git_remote **out, git_repository *repo, const char *name)
remote = git__calloc(1, sizeof(git_remote));
GITERR_CHECK_ALLOC(remote);
- remote->update_fetchhead = 1;
remote->name = git__strdup(name);
GITERR_CHECK_ALLOC(remote->name);
@@ -972,7 +969,7 @@ int git_remote_fetch(
const git_fetch_options *opts,
const char *reflog_message)
{
- int error;
+ int error, update_fetchhead = 1;
bool prune = false;
git_buf reflog_msg_buf = GIT_BUF_INIT;
const git_remote_callbacks *cbs = NULL;
@@ -980,6 +977,7 @@ int git_remote_fetch(
if (opts) {
GITERR_CHECK_VERSION(&opts->callbacks, GIT_REMOTE_CALLBACKS_VERSION, "git_remote_callbacks");
cbs = &opts->callbacks;
+ update_fetchhead = opts->update_fetchhead;
}
/* Connect and download everything */
@@ -1004,7 +1002,7 @@ int git_remote_fetch(
}
/* Create "remote/foo" branches for all remote branches */
- error = git_remote_update_tips(remote, cbs, git_buf_cstr(&reflog_msg_buf));
+ error = git_remote_update_tips(remote, cbs, update_fetchhead, git_buf_cstr(&reflog_msg_buf));
git_buf_free(&reflog_msg_buf);
if (error < 0)
return error;
@@ -1320,6 +1318,7 @@ cleanup:
static int update_tips_for_spec(
git_remote *remote,
const git_remote_callbacks *callbacks,
+ int update_fetchhead,
git_refspec *spec,
git_vector *refs,
const char *log_message)
@@ -1408,7 +1407,7 @@ static int update_tips_for_spec(
}
}
- if (git_remote_update_fetchhead(remote) &&
+ if (update_fetchhead &&
(error = git_remote_write_fetchhead(remote, spec, &update_heads)) < 0)
goto on_error;
@@ -1519,6 +1518,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,
+ int update_fetchhead,
const char *reflog_message)
{
git_refspec *spec, tagspec;
@@ -1539,7 +1539,7 @@ int git_remote_update_tips(
goto out;
if (remote->download_tags == GIT_REMOTE_DOWNLOAD_TAGS_ALL) {
- if ((error = update_tips_for_spec(remote, callbacks, &tagspec, &refs, reflog_message)) < 0)
+ if ((error = update_tips_for_spec(remote, callbacks, update_fetchhead, &tagspec, &refs, reflog_message)) < 0)
goto out;
}
@@ -1547,7 +1547,7 @@ int git_remote_update_tips(
if (spec->push)
continue;
- if ((error = update_tips_for_spec(remote, callbacks, spec, &refs, reflog_message)) < 0)
+ if ((error = update_tips_for_spec(remote, callbacks, update_fetchhead, spec, &refs, reflog_message)) < 0)
goto out;
}
@@ -1948,16 +1948,6 @@ cleanup:
return error;
}
-int git_remote_update_fetchhead(git_remote *remote)
-{
- return (remote->update_fetchhead != 0);
-}
-
-void git_remote_set_update_fetchhead(git_remote *remote, int value)
-{
- remote->update_fetchhead = (value != 0);
-}
-
int git_remote_is_valid_name(
const char *remote_name)
{
@@ -2414,7 +2404,7 @@ int git_remote_push(git_remote *remote, const git_strarray *refspecs, const git_
if ((error = git_remote_upload(remote, refspecs, opts)) < 0)
return error;
- error = git_remote_update_tips(remote, cbs, NULL);
+ error = git_remote_update_tips(remote, cbs, 0, NULL);
git_remote_disconnect(remote);
return error;
diff --git a/src/remote.h b/src/remote.h
index 3a5c0dee4..e696997f4 100644
--- a/src/remote.h
+++ b/src/remote.h
@@ -30,7 +30,6 @@ struct git_remote {
git_transfer_progress stats;
unsigned int need_pack;
git_remote_autotag_option_t download_tags;
- int update_fetchhead;
int prune_refs;
int passed_refspecs;
};
diff --git a/tests/network/remote/local.c b/tests/network/remote/local.c
index 1e03371f0..9134b60b1 100644
--- a/tests/network/remote/local.c
+++ b/tests/network/remote/local.c
@@ -241,7 +241,7 @@ 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, NULL));
- cl_git_pass(git_remote_update_tips(remote, NULL, NULL));
+ cl_git_pass(git_remote_update_tips(remote, NULL, 1, NULL));
git_remote_disconnect(remote);
/* Set up an empty bare repo to push into */
@@ -282,7 +282,7 @@ 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, NULL));
- cl_git_pass(git_remote_update_tips(remote, NULL, NULL));
+ cl_git_pass(git_remote_update_tips(remote, NULL, 1, NULL));
git_remote_disconnect(remote);
/* Set up an empty non-bare repo to push into */
@@ -350,7 +350,7 @@ void test_network_remote_local__reflog(void)
connect_to_local_repository(cl_fixture("testrepo.git"));
cl_git_pass(git_remote_download(remote, &array, NULL));
- cl_git_pass(git_remote_update_tips(remote, NULL, "UPDAAAAAATE!!"));
+ cl_git_pass(git_remote_update_tips(remote, NULL, 1, "UPDAAAAAATE!!"));
cl_git_pass(git_reflog_read(&log, repo, "refs/remotes/sloppy/master"));
cl_assert_equal_i(1, git_reflog_entrycount(log));
diff --git a/tests/online/fetch.c b/tests/online/fetch.c
index 1a0f05039..da0df0ad5 100644
--- a/tests/online/fetch.c
+++ b/tests/online/fetch.c
@@ -127,7 +127,7 @@ void test_online_fetch__doesnt_retrieve_a_pack_when_the_repository_is_up_to_date
cl_assert_equal_i(false, invoked);
- cl_git_pass(git_remote_update_tips(remote, &options.callbacks, NULL));
+ cl_git_pass(git_remote_update_tips(remote, &options.callbacks, 1, NULL));
git_remote_disconnect(remote);
git_remote_free(remote);