2020#include "netops.h"
2121#include "repository.h"
2222#include "refs.h"
23+ #include "transports/smart.h"
2324
2425static int maybe_want (git_remote * remote , git_remote_head * head , git_refspec * tagspec , git_remote_autotag_option_t tagopt )
2526{
@@ -59,8 +60,10 @@ static int mark_local(git_remote *remote)
5960 return -1 ;
6061
6162 git_vector_foreach (& remote -> refs , i , head ) {
62- /* If we have the object, mark it so we don't ask for it */
63- if (git_odb_exists (odb , & head -> oid ))
63+ /* If we have the object, mark it so we don't ask for it.
64+ However if we are unshallowing, we need to ask for it
65+ even though the head exists locally. */
66+ if (remote -> nego .depth != INT_MAX && git_odb_exists (odb , & head -> oid ))
6467 head -> local = 1 ;
6568 else
6669 remote -> need_pack = 1 ;
@@ -166,9 +169,15 @@ static int filter_wants(git_remote *remote, const git_fetch_options *opts)
166169int git_fetch_negotiate (git_remote * remote , const git_fetch_options * opts )
167170{
168171 git_transport * t = remote -> transport ;
172+ int error ;
169173
170174 remote -> need_pack = 0 ;
171175
176+ if (opts ) {
177+ GIT_ASSERT_ARG (opts -> depth >= 0 );
178+ remote -> nego .depth = opts -> depth ;
179+ }
180+
172181 if (filter_wants (remote , opts ) < 0 )
173182 return -1 ;
174183
@@ -180,20 +189,40 @@ int git_fetch_negotiate(git_remote *remote, const git_fetch_options *opts)
180189 * Now we have everything set up so we can start tell the
181190 * server what we want and what we have.
182191 */
183- return t -> negotiate_fetch (t ,
192+ remote -> nego .refs = (const git_remote_head * const * )remote -> refs .contents ;
193+ remote -> nego .refs_len = remote -> refs .length ;
194+
195+ if (git_repository__shallow_roots (& remote -> nego .shallow_roots ,
196+ & remote -> nego .shallow_roots_len ,
197+ remote -> repo ) < 0 )
198+ return -1 ;
199+
200+ error = t -> negotiate_fetch (t ,
184201 remote -> repo ,
185- (const git_remote_head * const * )remote -> refs .contents ,
186- remote -> refs .length );
202+ & remote -> nego );
203+
204+ git__free (remote -> nego .shallow_roots );
205+
206+ return error ;
187207}
188208
189209int git_fetch_download_pack (git_remote * remote )
190210{
211+ git_oidarray shallow_roots = { NULL };
191212 git_transport * t = remote -> transport ;
213+ int error ;
192214
193215 if (!remote -> need_pack )
194216 return 0 ;
195217
196- return t -> download_pack (t , remote -> repo , & remote -> stats );
218+ if ((error = t -> download_pack (t , remote -> repo , & remote -> stats )) != 0 ||
219+ (error = t -> shallow_roots (& shallow_roots , t )) != 0 )
220+ return error ;
221+
222+ error = git_repository__shallow_roots_write (remote -> repo , & shallow_roots );
223+
224+ git_oidarray_dispose (& shallow_roots );
225+ return error ;
197226}
198227
199228int git_fetch_options_init (git_fetch_options * opts , unsigned int version )
0 commit comments