diff options
Diffstat (limited to 'src/libgit2/fetch.c')
-rw-r--r-- | src/libgit2/fetch.c | 41 |
1 files changed, 35 insertions, 6 deletions
diff --git a/src/libgit2/fetch.c b/src/libgit2/fetch.c index ff10bde02..5bbef87f4 100644 --- a/src/libgit2/fetch.c +++ b/src/libgit2/fetch.c @@ -20,6 +20,7 @@ #include "netops.h" #include "repository.h" #include "refs.h" +#include "transports/smart.h" static int maybe_want(git_remote *remote, git_remote_head *head, git_refspec *tagspec, git_remote_autotag_option_t tagopt) { @@ -59,8 +60,10 @@ static int mark_local(git_remote *remote) return -1; git_vector_foreach(&remote->refs, i, head) { - /* If we have the object, mark it so we don't ask for it */ - if (git_odb_exists(odb, &head->oid)) + /* If we have the object, mark it so we don't ask for it. + However if we are unshallowing, we need to ask for it + even though the head exists locally. */ + if (remote->nego.depth != INT_MAX && git_odb_exists(odb, &head->oid)) head->local = 1; else remote->need_pack = 1; @@ -166,9 +169,15 @@ cleanup: int git_fetch_negotiate(git_remote *remote, const git_fetch_options *opts) { git_transport *t = remote->transport; + int error; remote->need_pack = 0; + if (opts) { + GIT_ASSERT_ARG(opts->depth >= 0); + remote->nego.depth = opts->depth; + } + if (filter_wants(remote, opts) < 0) return -1; @@ -180,20 +189,40 @@ int git_fetch_negotiate(git_remote *remote, const git_fetch_options *opts) * Now we have everything set up so we can start tell the * server what we want and what we have. */ - return t->negotiate_fetch(t, + remote->nego.refs = (const git_remote_head * const *)remote->refs.contents; + remote->nego.refs_len = remote->refs.length; + + if (git_repository__shallow_roots(&remote->nego.shallow_roots, + &remote->nego.shallow_roots_len, + remote->repo) < 0) + return -1; + + error = t->negotiate_fetch(t, remote->repo, - (const git_remote_head * const *)remote->refs.contents, - remote->refs.length); + &remote->nego); + + git__free(remote->nego.shallow_roots); + + return error; } int git_fetch_download_pack(git_remote *remote) { + git_oidarray shallow_roots = { NULL }; git_transport *t = remote->transport; + int error; if (!remote->need_pack) return 0; - return t->download_pack(t, remote->repo, &remote->stats); + if ((error = t->download_pack(t, remote->repo, &remote->stats)) != 0 || + (error = t->shallow_roots(&shallow_roots, t)) != 0) + return error; + + error = git_repository__shallow_roots_write(remote->repo, &shallow_roots); + + git_oidarray_dispose(&shallow_roots); + return error; } int git_fetch_options_init(git_fetch_options *opts, unsigned int version) |