diff options
author | Edward Thomson <ethomson@edwardthomson.com> | 2023-04-25 09:31:34 +0100 |
---|---|---|
committer | Edward Thomson <ethomson@edwardthomson.com> | 2023-05-08 15:06:41 +0100 |
commit | 3388f5ba1b821e9683d21ca41c34ed752d2db222 (patch) | |
tree | 4657ecd30c87c40b66a8be7339e9507e627f58af | |
parent | 7d7f3059decbd6b4730bfd09da54726c1b3ed8ea (diff) | |
download | libgit2-3388f5ba1b821e9683d21ca41c34ed752d2db222.tar.gz |
shallow: don't default to -1 for depth
Depth of `0` should indicate full depth. Disallow negative values (they
may have a future meaning) and use `0` as the default.
-rw-r--r-- | include/git2/remote.h | 6 | ||||
-rw-r--r-- | src/libgit2/clone.c | 2 | ||||
-rw-r--r-- | src/libgit2/fetch.c | 13 |
3 files changed, 9 insertions, 12 deletions
diff --git a/include/git2/remote.h b/include/git2/remote.h index 9e4043f87..8d6127014 100644 --- a/include/git2/remote.h +++ b/include/git2/remote.h @@ -744,9 +744,9 @@ typedef struct { git_proxy_options proxy_opts; /** - * Depth of the fetch to perform. Depth <= 0 fetches the full history. + * Depth of the fetch to perform, or 0 for full history. * - * The default is -1. + * The default is 0. */ int depth; @@ -772,7 +772,7 @@ typedef struct { #define GIT_FETCH_OPTIONS_VERSION 1 #define GIT_FETCH_OPTIONS_INIT { GIT_FETCH_OPTIONS_VERSION, GIT_REMOTE_CALLBACKS_INIT, GIT_FETCH_PRUNE_UNSPECIFIED, 1, \ - GIT_REMOTE_DOWNLOAD_TAGS_UNSPECIFIED, GIT_PROXY_OPTIONS_INIT, -1, 0 } + GIT_REMOTE_DOWNLOAD_TAGS_UNSPECIFIED, GIT_PROXY_OPTIONS_INIT } /** * Initialize git_fetch_options structure diff --git a/src/libgit2/clone.c b/src/libgit2/clone.c index 43341a493..fca0ca0cc 100644 --- a/src/libgit2/clone.c +++ b/src/libgit2/clone.c @@ -421,7 +421,7 @@ static int clone_into( memcpy(&fetch_opts, opts, sizeof(git_fetch_options)); fetch_opts.update_fetchhead = 0; - if (opts->depth <= 0) + if (!opts->depth) fetch_opts.download_tags = GIT_REMOTE_DOWNLOAD_TAGS_ALL; if ((error = git_remote_connect_options__from_fetch_opts(&connect_opts, remote, &fetch_opts)) < 0) diff --git a/src/libgit2/fetch.c b/src/libgit2/fetch.c index d66892ca0..86b650a60 100644 --- a/src/libgit2/fetch.c +++ b/src/libgit2/fetch.c @@ -172,10 +172,12 @@ int git_fetch_negotiate(git_remote *remote, const git_fetch_options *opts) remote->need_pack = 0; - if (!opts) - remote->nego.depth = -1; - else + if (opts) { + GIT_ASSERT_ARG(opts->unshallow == 0 || opts->depth == 0); + GIT_ASSERT_ARG(opts->depth >= 0); + remote->nego.depth = opts->unshallow ? INT_MAX : opts->depth; + } if (filter_wants(remote, opts) < 0) return -1; @@ -184,11 +186,6 @@ int git_fetch_negotiate(git_remote *remote, const git_fetch_options *opts) if (!remote->need_pack) return 0; - if (opts && opts->unshallow && opts->depth > 0) { - git_error_set(GIT_ERROR_INVALID, "options '--depth' and '--unshallow' cannot be used together"); - return -1; - } - /* * Now we have everything set up so we can start tell the * server what we want and what we have. |