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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265
diff --git a/include/git2/remote.h b/include/git2/remote.h
index 22aad5a..5b42a98 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 53cdae6..7dcbb8a 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 95c316f..c4f5e0f 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 3a5c0de..e696997 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 1e03371..9134b60 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 1a0f050..da0df0a 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);