Commit 2d33fe78 by yuangli

refactor git_fetch_option.depth and usage

parent e7294e87
...@@ -744,7 +744,9 @@ typedef struct { ...@@ -744,7 +744,9 @@ typedef struct {
git_proxy_options proxy_opts; 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; int depth;
......
...@@ -389,6 +389,11 @@ static int checkout_branch(git_repository *repo, git_remote *remote, const git_c ...@@ -389,6 +389,11 @@ static int checkout_branch(git_repository *repo, git_remote *remote, const git_c
return error; 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) 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; int error;
...@@ -409,8 +414,10 @@ static int clone_into(git_repository *repo, git_remote *_remote, const git_fetch ...@@ -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)); memcpy(&fetch_opts, opts, sizeof(git_fetch_options));
fetch_opts.update_fetchhead = 0; 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; fetch_opts.download_tags = GIT_REMOTE_DOWNLOAD_TAGS_ALL;
git_str_printf(&reflog_message, "clone: from %s", git_remote_url(remote)); 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) if ((error = git_remote_fetch(remote, NULL, &fetch_opts, git_str_cstr(&reflog_message))) != 0)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment