@matheusbsbs / matheus-bagliano / commits / 6462d5eb9a
Fork 0

fetch: remove fetch_if_missing=0

In fetch_pack() (and all functions it calls), pass OBJECT_INFO_SKIP_FETCH_OBJECT whenever we query an object that could be a tree or blob that we do not want to be lazy-fetched even if it is absent. Thus, the only lazy-fetches occurring for trees and blobs are when resolving deltas. Thus, we can remove fetch_if_missing=0 from builtin/fetch.c. Remove this, and also add a test ensuring that such objects are not lazy-fetched. (We might be able to remove fetch_if_missing=0 from other places too, but I have limited myself to builtin/fetch.c in this commit because I have not written tests for the other commands yet.) Note that commits and tags may still be lazy-fetched. I limited myself to objects that could be trees or blobs here because Git does not support creating such commit- and tag-excluding clones yet, and even if such a clone were manually created, Git does not have good support for fetching a single commit (when fetching a commit, it and all its ancestors would be sent). Signed-off-by: Jonathan Tan <jonathantanmy@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jonathan Tan committed Nov 5, 2019 at 10:56 UTC 6462d5eb9a5b23ab9cff4e3c92ff930600562d8f
3 files changed +74 -4
builtin/fetch.c
+2 -3
@@ -1074,7 +1074,8 @@ static int check_exist_and_connected(struct ref *ref_map)
1074 * we need all direct targets to exist.
1075 */
1076 for (r = rm; r; r = r->next) {
1077 - if (!has_object_file(&r->old_oid))
1077 + if (!has_object_file_with_flags(&r->old_oid,
1078 + OBJECT_INFO_SKIP_FETCH_OBJECT))
1079 return -1;
1080 }
1081
@@ -1822,8 +1823,6 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
1823 }
1824 }
1825
1825 - fetch_if_missing = 0;
1826 -
1826 if (remote) {
1827 if (filter_options.choice || has_promisor_remote())
1828 fetch_one_setup_partial(remote);
fetch-pack.c
+2 -1
@@ -673,7 +673,8 @@ static void mark_complete_and_common_ref(struct fetch_negotiator *negotiator,
673 struct object *o;
674
675 if (!has_object_file_with_flags(&ref->old_oid,
676 - OBJECT_INFO_QUICK))
676 + OBJECT_INFO_QUICK |
677 + OBJECT_INFO_SKIP_FETCH_OBJECT))
678 continue;
679 o = parse_object(the_repository, &ref->old_oid);
680 if (!o)
t/t5616-partial-clone.sh
+70
@@ -296,6 +296,76 @@ test_expect_success 'partial clone with unresolvable sparse filter fails cleanly
296 test_i18ngrep "unable to parse sparse filter data in" err
297 '
298
299 +setup_triangle () {
300 + rm -rf big-blob.txt server client promisor-remote &&
301 +
302 + printf "line %d\n" $(test_seq 1 100) >big-blob.txt &&
303 +
304 + # Create a server with 2 commits: a commit with a big blob and a child
305 + # commit with an incremental change. Also, create a partial clone
306 + # client that only contains the first commit.
307 + git init server &&
308 + git -C server config --local uploadpack.allowfilter 1 &&
309 + cp big-blob.txt server &&
310 + git -C server add big-blob.txt &&
311 + git -C server commit -m "initial" &&
312 + git clone --bare --filter=tree:0 "file://$(pwd)/server" client &&
313 + echo another line >>server/big-blob.txt &&
314 + git -C server commit -am "append line to big blob" &&
315 +
316 + # Create a promisor remote that only contains the blob from the first
317 + # commit, and set it as the promisor remote of client. Thus, whenever
318 + # the client lazy fetches, the lazy fetch will succeed only if it is
319 + # for this blob.
320 + git init promisor-remote &&
321 + test_commit -C promisor-remote one && # so that ref advertisement is not empty
322 + git -C promisor-remote config --local uploadpack.allowanysha1inwant 1 &&
323 + git -C promisor-remote hash-object -w --stdin <big-blob.txt &&
324 + git -C client remote set-url origin "file://$(pwd)/promisor-remote"
325 +}
326 +
327 +# NEEDSWORK: The tests beginning with "fetch lazy-fetches" below only
328 +# test that "fetch" avoid fetching trees and blobs, but not commits or
329 +# tags. Revisit this if Git is ever taught to support partial clones
330 +# with commits and/or tags filtered out.
331 +
332 +test_expect_success 'fetch lazy-fetches only to resolve deltas' '
333 + setup_triangle &&
334 +
335 + # Exercise to make sure it works. Git will not fetch anything from the
336 + # promisor remote other than for the big blob (because it needs to
337 + # resolve the delta).
338 + GIT_TRACE_PACKET="$(pwd)/trace" git -C client \
339 + fetch "file://$(pwd)/server" master &&
340 +
341 + # Verify the assumption that the client needed to fetch the delta base
342 + # to resolve the delta.
343 + git hash-object big-blob.txt >hash &&
344 + grep "want $(cat hash)" trace
345 +'
346 +
347 +test_expect_success 'fetch lazy-fetches only to resolve deltas, protocol v2' '
348 + setup_triangle &&
349 +
350 + git -C server config --local protocol.version 2 &&
351 + git -C client config --local protocol.version 2 &&
352 + git -C promisor-remote config --local protocol.version 2 &&
353 +
354 + # Exercise to make sure it works. Git will not fetch anything from the
355 + # promisor remote other than for the big blob (because it needs to
356 + # resolve the delta).
357 + GIT_TRACE_PACKET="$(pwd)/trace" git -C client \
358 + fetch "file://$(pwd)/server" master &&
359 +
360 + # Verify that protocol version 2 was used.
361 + grep "fetch< version 2" trace &&
362 +
363 + # Verify the assumption that the client needed to fetch the delta base
364 + # to resolve the delta.
365 + git hash-object big-blob.txt >hash &&
366 + grep "want $(cat hash)" trace
367 +'
368 +
369 . "$TEST_DIRECTORY"/lib-httpd.sh
370 start_httpd
371