diff: skip GITLINK when lazy fetching missing objs
authorJonathan Tan <jonathantanmy@google.com>
Tue, 20 Aug 2019 20:53:20 +0000 (13:53 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 20 Aug 2019 22:04:26 +0000 (15:04 -0700)
In 7fbbcb21b1 ("diff: batch fetching of missing blobs", 2019-04-08),
diff was taught to batch the fetching of missing objects when operating
on a partial clone, but was not taught to refrain from fetching
GITLINKs. Teach diff to check if an object is a GITLINK before including
it in the set to be fetched.

(As stated in the commit message of that commit, unpack-trees was also
taught a similar thing prior, but unpack-trees correctly checks for
GITLINK before including objects in the set to be fetched.)

Signed-off-by: Junio C Hamano <gitster@pobox.com>
diff.c
t/t4067-diff-partial-clone.sh
diff --git a/diff.c b/diff.c
index 1ccd96bbfde23a0f6d42104e81f78e0953c1bc93..9a2aa07a0e87b8e5e0ffe086c1605d6d893e9bf0 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -6487,6 +6487,7 @@ static void add_if_missing(struct repository *r,
                           const struct diff_filespec *filespec)
 {
        if (filespec && filespec->oid_valid &&
+           !S_ISGITLINK(filespec->mode) &&
            oid_object_info_extended(r, &filespec->oid, NULL,
                                     OBJECT_INFO_FOR_PREFETCH))
                oid_array_append(to_fetch, &filespec->oid);
index 90c8fb29017562d5341a61a4bb872d323b8f8340..4831ad35e61436fdc400533fb0e7f88e6d27027c 100755 (executable)
@@ -75,6 +75,37 @@ test_expect_success 'diff skips same-OID blobs' '
        ! grep "want $(cat hash-b)" trace
 '
 
+test_expect_success 'when fetching missing objects, diff skips GITLINKs' '
+       test_when_finished "rm -rf sub server client trace" &&
+
+       test_create_repo sub &&
+       test_commit -C sub first &&
+
+       test_create_repo server &&
+       echo a >server/a &&
+       git -C server add a &&
+       git -C server submodule add "file://$(pwd)/sub" &&
+       git -C server commit -m x &&
+
+       test_commit -C server/sub second &&
+       echo another-a >server/a &&
+       git -C server add a sub &&
+       git -C server commit -m x &&
+
+       test_config -C server uploadpack.allowfilter 1 &&
+       test_config -C server uploadpack.allowanysha1inwant 1 &&
+       git clone --bare --filter=blob:limit=0 "file://$(pwd)/server" client &&
+
+       echo a | git hash-object --stdin >hash-old-a &&
+       echo another-a | git hash-object --stdin >hash-new-a &&
+
+       # Ensure that a and another-a are fetched, and check (by successful
+       # execution of the diff) that no invalid OIDs are sent.
+       GIT_TRACE_PACKET="$(pwd)/trace" git -C client diff HEAD^ HEAD &&
+       grep "want $(cat hash-old-a)" trace &&
+       grep "want $(cat hash-new-a)" trace
+'
+
 test_expect_success 'diff with rename detection batches blobs' '
        test_when_finished "rm -rf server client trace" &&