Skip to content

Commit 3388f5b

Browse files
committed
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.
1 parent 7d7f305 commit 3388f5b

File tree

3 files changed

+9
-12
lines changed

3 files changed

+9
-12
lines changed

include/git2/remote.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -744,9 +744,9 @@ typedef struct {
744744
git_proxy_options proxy_opts;
745745

746746
/**
747-
* Depth of the fetch to perform. Depth <= 0 fetches the full history.
747+
* Depth of the fetch to perform, or 0 for full history.
748748
*
749-
* The default is -1.
749+
* The default is 0.
750750
*/
751751
int depth;
752752

@@ -772,7 +772,7 @@ typedef struct {
772772

773773
#define GIT_FETCH_OPTIONS_VERSION 1
774774
#define GIT_FETCH_OPTIONS_INIT { GIT_FETCH_OPTIONS_VERSION, GIT_REMOTE_CALLBACKS_INIT, GIT_FETCH_PRUNE_UNSPECIFIED, 1, \
775-
GIT_REMOTE_DOWNLOAD_TAGS_UNSPECIFIED, GIT_PROXY_OPTIONS_INIT, -1, 0 }
775+
GIT_REMOTE_DOWNLOAD_TAGS_UNSPECIFIED, GIT_PROXY_OPTIONS_INIT }
776776

777777
/**
778778
* Initialize git_fetch_options structure

src/libgit2/clone.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ static int clone_into(
421421
memcpy(&fetch_opts, opts, sizeof(git_fetch_options));
422422
fetch_opts.update_fetchhead = 0;
423423

424-
if (opts->depth <= 0)
424+
if (!opts->depth)
425425
fetch_opts.download_tags = GIT_REMOTE_DOWNLOAD_TAGS_ALL;
426426

427427
if ((error = git_remote_connect_options__from_fetch_opts(&connect_opts, remote, &fetch_opts)) < 0)

src/libgit2/fetch.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,12 @@ int git_fetch_negotiate(git_remote *remote, const git_fetch_options *opts)
172172

173173
remote->need_pack = 0;
174174

175-
if (!opts)
176-
remote->nego.depth = -1;
177-
else
175+
if (opts) {
176+
GIT_ASSERT_ARG(opts->unshallow == 0 || opts->depth == 0);
177+
GIT_ASSERT_ARG(opts->depth >= 0);
178+
178179
remote->nego.depth = opts->unshallow ? INT_MAX : opts->depth;
180+
}
179181

180182
if (filter_wants(remote, opts) < 0)
181183
return -1;
@@ -184,11 +186,6 @@ int git_fetch_negotiate(git_remote *remote, const git_fetch_options *opts)
184186
if (!remote->need_pack)
185187
return 0;
186188

187-
if (opts && opts->unshallow && opts->depth > 0) {
188-
git_error_set(GIT_ERROR_INVALID, "options '--depth' and '--unshallow' cannot be used together");
189-
return -1;
190-
}
191-
192189
/*
193190
* Now we have everything set up so we can start tell the
194191
* server what we want and what we have.

0 commit comments

Comments
 (0)