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.
This commit is contained in:
Carlos Martín Nieto 2015-04-22 16:11:10 +02:00
parent 058b753ceb
commit 3eff2a5728
6 changed files with 26 additions and 44 deletions

View File

@ -538,10 +538,16 @@ typedef struct {
* Whether to perform a prune after the fetch * Whether to perform a prune after the fetch
*/ */
git_fetch_prune_t prune; 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; } git_fetch_options;
#define GIT_FETCH_OPTIONS_VERSION 1 #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 * 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 * the name of the remote (or its url, for in-memory remotes). This
* parameter is ignored when pushing. * parameter is ignored when pushing.
* @param callbacks pointer to the callback structure to use * @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 * @return 0 or an error code
*/ */
GIT_EXTERN(int) git_remote_update_tips( GIT_EXTERN(int) git_remote_update_tips(
git_remote *remote, git_remote *remote,
const git_remote_callbacks *callbacks, const git_remote_callbacks *callbacks,
int update_fetchhead,
const char *reflog_message); const char *reflog_message);
/** /**
@ -754,23 +762,6 @@ GIT_EXTERN(int) git_remote_rename(
const char *name, const char *name,
const char *new_name); 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. * Ensure the remote name is well-formed.
* *

View File

@ -328,6 +328,7 @@ static int clone_into(git_repository *repo, git_remote *_remote, const git_fetch
{ {
int error; int error;
git_buf reflog_message = GIT_BUF_INIT; git_buf reflog_message = GIT_BUF_INIT;
git_fetch_options fetch_opts;
git_remote *remote; git_remote *remote;
assert(repo && _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) if ((error = git_remote_add_fetch(remote, "refs/tags/*:refs/tags/*")) < 0)
goto cleanup; 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)); 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; goto cleanup;
error = checkout_branch(repo, remote, co_opts, branch, git_buf_cstr(&reflog_message)); error = checkout_branch(repo, remote, co_opts, branch, git_buf_cstr(&reflog_message));

View File

@ -159,7 +159,6 @@ static int create_internal(git_remote **out, git_repository *repo, const char *n
GITERR_CHECK_ALLOC(remote); GITERR_CHECK_ALLOC(remote);
remote->repo = repo; remote->repo = repo;
remote->update_fetchhead = 1;
if (git_vector_init(&remote->refs, 32, NULL) < 0 || if (git_vector_init(&remote->refs, 32, NULL) < 0 ||
canonicalize_url(&canonical_url, url) < 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->repo = source->repo;
remote->download_tags = source->download_tags; remote->download_tags = source->download_tags;
remote->update_fetchhead = source->update_fetchhead;
remote->prune_refs = source->prune_refs; remote->prune_refs = source->prune_refs;
if (git_vector_init(&remote->refs, 32, NULL) < 0 || 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)); remote = git__calloc(1, sizeof(git_remote));
GITERR_CHECK_ALLOC(remote); GITERR_CHECK_ALLOC(remote);
remote->update_fetchhead = 1;
remote->name = git__strdup(name); remote->name = git__strdup(name);
GITERR_CHECK_ALLOC(remote->name); GITERR_CHECK_ALLOC(remote->name);
@ -972,7 +969,7 @@ int git_remote_fetch(
const git_fetch_options *opts, const git_fetch_options *opts,
const char *reflog_message) const char *reflog_message)
{ {
int error; int error, update_fetchhead = 1;
bool prune = false; bool prune = false;
git_buf reflog_msg_buf = GIT_BUF_INIT; git_buf reflog_msg_buf = GIT_BUF_INIT;
const git_remote_callbacks *cbs = NULL; const git_remote_callbacks *cbs = NULL;
@ -980,6 +977,7 @@ int git_remote_fetch(
if (opts) { if (opts) {
GITERR_CHECK_VERSION(&opts->callbacks, GIT_REMOTE_CALLBACKS_VERSION, "git_remote_callbacks"); GITERR_CHECK_VERSION(&opts->callbacks, GIT_REMOTE_CALLBACKS_VERSION, "git_remote_callbacks");
cbs = &opts->callbacks; cbs = &opts->callbacks;
update_fetchhead = opts->update_fetchhead;
} }
/* Connect and download everything */ /* Connect and download everything */
@ -1004,7 +1002,7 @@ int git_remote_fetch(
} }
/* Create "remote/foo" branches for all remote branches */ /* 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); git_buf_free(&reflog_msg_buf);
if (error < 0) if (error < 0)
return error; return error;
@ -1320,6 +1318,7 @@ cleanup:
static int update_tips_for_spec( static int update_tips_for_spec(
git_remote *remote, git_remote *remote,
const git_remote_callbacks *callbacks, const git_remote_callbacks *callbacks,
int update_fetchhead,
git_refspec *spec, git_refspec *spec,
git_vector *refs, git_vector *refs,
const char *log_message) 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) (error = git_remote_write_fetchhead(remote, spec, &update_heads)) < 0)
goto on_error; goto on_error;
@ -1519,6 +1518,7 @@ static int opportunistic_updates(const git_remote *remote, git_vector *refs, con
int git_remote_update_tips( int git_remote_update_tips(
git_remote *remote, git_remote *remote,
const git_remote_callbacks *callbacks, const git_remote_callbacks *callbacks,
int update_fetchhead,
const char *reflog_message) const char *reflog_message)
{ {
git_refspec *spec, tagspec; git_refspec *spec, tagspec;
@ -1539,7 +1539,7 @@ int git_remote_update_tips(
goto out; goto out;
if (remote->download_tags == GIT_REMOTE_DOWNLOAD_TAGS_ALL) { 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; goto out;
} }
@ -1547,7 +1547,7 @@ int git_remote_update_tips(
if (spec->push) if (spec->push)
continue; 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; goto out;
} }
@ -1948,16 +1948,6 @@ cleanup:
return error; 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( int git_remote_is_valid_name(
const char *remote_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) if ((error = git_remote_upload(remote, refspecs, opts)) < 0)
return error; return error;
error = git_remote_update_tips(remote, cbs, NULL); error = git_remote_update_tips(remote, cbs, 0, NULL);
git_remote_disconnect(remote); git_remote_disconnect(remote);
return error; return error;

View File

@ -30,7 +30,6 @@ struct git_remote {
git_transfer_progress stats; git_transfer_progress stats;
unsigned int need_pack; unsigned int need_pack;
git_remote_autotag_option_t download_tags; git_remote_autotag_option_t download_tags;
int update_fetchhead;
int prune_refs; int prune_refs;
int passed_refspecs; int passed_refspecs;
}; };

View File

@ -241,7 +241,7 @@ void test_network_remote_local__push_to_bare_remote_with_file_url(void)
/* Get some commits */ /* Get some commits */
connect_to_local_repository(cl_fixture("testrepo.git")); connect_to_local_repository(cl_fixture("testrepo.git"));
cl_git_pass(git_remote_download(remote, &array, NULL)); 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); git_remote_disconnect(remote);
/* Set up an empty bare repo to push into */ /* 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 */ /* Get some commits */
connect_to_local_repository(cl_fixture("testrepo.git")); connect_to_local_repository(cl_fixture("testrepo.git"));
cl_git_pass(git_remote_download(remote, &array, NULL)); 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); git_remote_disconnect(remote);
/* Set up an empty non-bare repo to push into */ /* 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")); connect_to_local_repository(cl_fixture("testrepo.git"));
cl_git_pass(git_remote_download(remote, &array, NULL)); 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_git_pass(git_reflog_read(&log, repo, "refs/remotes/sloppy/master"));
cl_assert_equal_i(1, git_reflog_entrycount(log)); cl_assert_equal_i(1, git_reflog_entrycount(log));

View File

@ -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_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_disconnect(remote);
git_remote_free(remote); git_remote_free(remote);