diff options
author | yuangli <yuangli@mathworks.com> | 2022-08-02 13:15:22 +0100 |
---|---|---|
committer | yuangli <yuangli@mathworks.com> | 2022-08-02 13:15:22 +0100 |
commit | 2d33fe78858354c508afb77d80f32a5a747b801e (patch) | |
tree | 1391d47cfcf0f5798ab8705841db47680858a342 | |
parent | e7294e870398d72b79a436b628170ffcaaa1713c (diff) | |
download | libgit2-2d33fe78858354c508afb77d80f32a5a747b801e.tar.gz |
refactor git_fetch_option.depth and usage
-rw-r--r-- | include/git2/remote.h | 4 | ||||
-rw-r--r-- | src/libgit2/clone.c | 9 |
2 files changed, 11 insertions, 2 deletions
diff --git a/include/git2/remote.h b/include/git2/remote.h index 33f5103ce..f3415d843 100644 --- a/include/git2/remote.h +++ b/include/git2/remote.h @@ -744,7 +744,9 @@ typedef struct { git_proxy_options proxy_opts; /** - * Depth of the fetch to perform + * Depth of the fetch to perform, has to be a positive integer. + * + * The default is -1, which will fetch the full history. */ int depth; diff --git a/src/libgit2/clone.c b/src/libgit2/clone.c index ee1f2b892..95bddeae6 100644 --- a/src/libgit2/clone.c +++ b/src/libgit2/clone.c @@ -389,6 +389,11 @@ static int checkout_branch(git_repository *repo, git_remote *remote, const git_c return error; } +static int git_fetch_is_shallow(git_fetch_options *opts) +{ + return opts->depth > 0; +} + static int clone_into(git_repository *repo, git_remote *_remote, const git_fetch_options *opts, const git_checkout_options *co_opts, const char *branch) { int error; @@ -409,8 +414,10 @@ static int clone_into(git_repository *repo, git_remote *_remote, const git_fetch memcpy(&fetch_opts, opts, sizeof(git_fetch_options)); fetch_opts.update_fetchhead = 0; - if (fetch_opts.depth == -1) + + if (!git_fetch_is_shallow(opts)) fetch_opts.download_tags = GIT_REMOTE_DOWNLOAD_TAGS_ALL; + git_str_printf(&reflog_message, "clone: from %s", git_remote_url(remote)); if ((error = git_remote_fetch(remote, NULL, &fetch_opts, git_str_cstr(&reflog_message))) != 0) |