Skip to content

Commit a63694f

Browse files
jonathantanmygitster
authored andcommitted
diff: skip GITLINK when lazy fetching missing objs
In 7fbbcb2 ("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 <[email protected]>
1 parent 75b2f01 commit a63694f

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

diff.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6487,6 +6487,7 @@ static void add_if_missing(struct repository *r,
64876487
const struct diff_filespec *filespec)
64886488
{
64896489
if (filespec && filespec->oid_valid &&
6490+
!S_ISGITLINK(filespec->mode) &&
64906491
oid_object_info_extended(r, &filespec->oid, NULL,
64916492
OBJECT_INFO_FOR_PREFETCH))
64926493
oid_array_append(to_fetch, &filespec->oid);

t/t4067-diff-partial-clone.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,37 @@ test_expect_success 'diff skips same-OID blobs' '
7575
! grep "want $(cat hash-b)" trace
7676
'
7777

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+
78109
test_expect_success 'diff with rename detection batches blobs' '
79110
test_when_finished "rm -rf server client trace" &&
80111

0 commit comments

Comments
 (0)