diff: skip GITLINK when lazy fetching missing objs
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>
Jonathan Tan committed
Aug 20, 2019 at 13:53 UTC
a63694f52355b412b65515961401cd2359fed544
2 files changed
+32
diff.c
+1
@@ -6487,6 +6487,7 @@ static void add_if_missing(struct repository *r,
6487
const struct diff_filespec *filespec)
6488
{
6489
if (filespec && filespec->oid_valid &&
6490
+ !S_ISGITLINK(filespec->mode) &&
6491
oid_object_info_extended(r, &filespec->oid, NULL,
6492
OBJECT_INFO_FOR_PREFETCH))
6493
oid_array_append(to_fetch, &filespec->oid);
t/t4067-diff-partial-clone.sh
+31
@@ -75,6 +75,37 @@ test_expect_success 'diff skips same-OID blobs' '
75
! grep "want $(cat hash-b)" trace
76
'
77
78
+test_expect_success 'when fetching missing objects, diff skips GITLINKs' '
79
+ test_when_finished "rm -rf sub server client trace" &&
80
+
81
+ test_create_repo sub &&
82
+ test_commit -C sub first &&
83
+
84
+ test_create_repo server &&
85
+ echo a >server/a &&
86
+ git -C server add a &&
87
+ git -C server submodule add "file://$(pwd)/sub" &&
88
+ git -C server commit -m x &&
89
+
90
+ test_commit -C server/sub second &&
91
+ echo another-a >server/a &&
92
+ git -C server add a sub &&
93
+ git -C server commit -m x &&
94
+
95
+ test_config -C server uploadpack.allowfilter 1 &&
96
+ test_config -C server uploadpack.allowanysha1inwant 1 &&
97
+ git clone --bare --filter=blob:limit=0 "file://$(pwd)/server" client &&
98
+
99
+ echo a | git hash-object --stdin >hash-old-a &&
100
+ echo another-a | git hash-object --stdin >hash-new-a &&
101
+
102
+ # Ensure that a and another-a are fetched, and check (by successful
103
+ # execution of the diff) that no invalid OIDs are sent.
104
+ GIT_TRACE_PACKET="$(pwd)/trace" git -C client diff HEAD^ HEAD &&
105
+ grep "want $(cat hash-old-a)" trace &&
106
+ grep "want $(cat hash-new-a)" trace
107
+'
108
+
109
test_expect_success 'diff with rename detection batches blobs' '
110
test_when_finished "rm -rf server client trace" &&
111