git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Jonathan Tan <jonathantanmy@google.com>
To: git@vger.kernel.org
Cc: Jonathan Tan <jonathantanmy@google.com>
Subject: [PATCH] diff: skip GITLINK when lazy fetching missing objs
Date: Tue, 20 Aug 2019 13:53:20 -0700	[thread overview]
Message-ID: <20190820205320.139006-1-jonathantanmy@google.com> (raw)

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.)
---
One of my colleagues noticed this when switching branches in a
superproject with a dirty working tree (hence triggering the diff
mechanism). The test I included in this commit tests a simpler use case,
but I've verified that this solves my colleague's case too.
---
 diff.c                        |  1 +
 t/t4067-diff-partial-clone.sh | 31 +++++++++++++++++++++++++++++++
 2 files changed, 32 insertions(+)

diff --git a/diff.c b/diff.c
index efe42b341a..e28b463f57 100644
--- a/diff.c
+++ b/diff.c
@@ -6512,6 +6512,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);
diff --git a/t/t4067-diff-partial-clone.sh b/t/t4067-diff-partial-clone.sh
index 90c8fb2901..4831ad35e6 100755
--- a/t/t4067-diff-partial-clone.sh
+++ b/t/t4067-diff-partial-clone.sh
@@ -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" &&
 
-- 
2.23.0.rc1.153.gdeed80330f-goog


             reply	other threads:[~2019-08-20 20:53 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-20 20:53 Jonathan Tan [this message]
2019-08-20 21:18 ` [PATCH] diff: skip GITLINK when lazy fetching missing objs Junio C Hamano
2019-08-20 21:39   ` Jonathan Tan
2019-08-22  4:15     ` Jeff King
2019-08-22 16:25       ` Jonathan Tan
2019-08-22 17:10         ` Jeff King

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190820205320.139006-1-jonathantanmy@google.com \
    --to=jonathantanmy@google.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).