All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Alessio Attilio via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Alessio Attilio <attilio.alessio@protonmail.com>,
	Alessio Attilio <attilio.alessio@protonmail.com>
Subject: [PATCH v2] pack-objects: handle missing promisor objects
Date: Wed, 25 Nov 2026 19:49:30 +0000	[thread overview]
Message-ID: <pull.2333.v2.git.1795636170423.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.2333.git.1795635624820.gitgitgadget@gmail.com>

From: Alessio Attilio <attilio.alessio@protonmail.com>

Objects missing from a partial clone are expected to be absent.
When checking whether an object is in a promisor pack, do not BUG()
if its object info cannot be read. Such an object cannot be included
in the pack, so skip it.

Pass OBJECT_INFO_SKIP_FETCH_OBJECT explicitly so the lookup does not
trigger a lazy fetch.

Test filtered --unshallow and --deepen fetches, as well as a subsequent
fetch that repacks links to promisor commits with missing trees.

Signed-off-by: Alessio Attilio <attilio.alessio@protonmail.com>
---
    pack-objects: handle missing promisor objects
    
    Changes since v1:
    
     * Pass OBJECT_INFO_SKIP_FETCH_OBJECT explicitly to avoid lazy fetching
       during the lookup.
     * Cover both filtered --unshallow and --deepen fetches, and a later
       fetch after unshallowing a filtered clone.

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-2333%2Fkairosci%2Fattilio%2Fpack-objects-missing-promisor-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2333/kairosci/attilio/pack-objects-missing-promisor-v2
Pull-Request: https://github.com/gitgitgadget/git/pull/2333

Range-diff vs v1:

 1:  16a9cac809 ! 1:  a7e378ca3d pack-objects: handle missing promisor objects
     @@ Commit message
          if its object info cannot be read. Such an object cannot be included
          in the pack, so skip it.
      
     +    Pass OBJECT_INFO_SKIP_FETCH_OBJECT explicitly so the lookup does not
     +    trigger a lazy fetch.
     +
     +    Test filtered --unshallow and --deepen fetches, as well as a subsequent
     +    fetch that repacks links to promisor commits with missing trees.
     +
          Signed-off-by: Alessio Attilio <attilio.alessio@protonmail.com>
      
       ## builtin/pack-objects.c ##
      @@ builtin/pack-objects.c: static int is_not_in_promisor_pack_obj(struct object *obj, void *data UNUSED)
     + 		.source_infop = &source_info,
       	};
       
     - 	if (odb_read_object_info_extended(the_repository->objects, &obj->oid, &info, 0))
     +-	if (odb_read_object_info_extended(the_repository->objects, &obj->oid, &info, 0))
      -		BUG("should_include_obj should only be called on existing objects");
     ++	if (odb_read_object_info_extended(the_repository->objects, &obj->oid, &info,
     ++					  OBJECT_INFO_SKIP_FETCH_OBJECT)) {
     ++		/* Missing; assume it is a promisor object. */
      +		return 0;
     ++	}
       	return source_info.source->type != ODB_SOURCE_PACKED || !source_info.u.packed.pack->pack_promisor;
       }
       
      
     - ## t/t0410-partial-clone.sh ##
     -@@ t/t0410-partial-clone.sh: promise_and_delete () {
     - 	delete_object repo "$HASH"
     - }
     + ## t/t5616-partial-clone.sh ##
     +@@ t/t5616-partial-clone.sh: test_expect_success 'after fetching descendants of non-promisor commits, gc work
     + 	git -C partial gc --prune=now
     + '
       
     -+test_expect_success 'fetch --unshallow with tree filter when remote has advanced' '
     -+	rm -rf server server.bare client &&
     -+	test_create_repo server &&
     -+	test_commit -C server c1 &&
     -+	test_commit -C server c2 &&
     -+	test_commit -C server c3 &&
     -+	test_commit -C server c4 &&
     -+	git clone --bare server server.bare &&
     -+	git -C server.bare config uploadpack.allowfilter true &&
     -+	git -C server.bare config uploadpack.allowanysha1inwant true &&
     -+	git init client &&
     -+	git -C client remote add origin "file://$(pwd)/server.bare" &&
     -+	tip=$(git -C server rev-parse HEAD~1) &&
     -+	git -C client fetch --no-tags --depth=1 origin "+$tip:refs/remotes/origin/master" &&
     -+	git -C client checkout -b master refs/remotes/origin/master &&
     -+	git -C client fetch --no-tags --filter=tree:0 --unshallow origin \
     -+		+refs/heads/master:refs/remotes/origin/master &&
     -+	rm -rf server server.bare client
     ++for opt in --unshallow --deepen=1
     ++do
     ++	test_expect_success "filtered fetch $opt of a moved ref repacks local links" '
     ++		test_when_finished "rm -rf source target" &&
     ++
     ++		git init source &&
     ++		test_commit_bulk -C source 4 &&
     ++		git -C source config uploadpack.allowFilter true &&
     ++		git -C source config uploadpack.allowAnySHA1InWant true &&
     ++		COMMIT=$(git -C source rev-parse main~1) &&
     ++
     ++		git init target &&
     ++		git -C target remote add origin "file://$(pwd)/source" &&
     ++		git -C target fetch --no-tags --depth=1 origin "+$COMMIT:refs/remotes/origin/main" &&
     ++
     ++		# The fetched pack has the new tip whose parent is the local shallow
     ++		# tip, so index-pack repacks it into a promisor pack. That process
     ++		# inherits the shallow file and walks into promisor commits whose
     ++		# trees do not exist.
     ++		git -C target fetch --no-tags --filter=tree:0 "$opt" origin \
     ++			+refs/heads/main:refs/remotes/origin/main &&
     ++		git -C target rev-parse --verify refs/remotes/origin/main >actual &&
     ++		git -C source rev-parse --verify refs/heads/main >expect &&
     ++		test_cmp expect actual &&
     ++		git -C target fsck
     ++	'
     ++done
     ++
     ++test_expect_success 'repacking local links tolerates missing trees of promisor commits' '
     ++	test_when_finished "rm -rf source target" &&
     ++
     ++	git init source &&
     ++	test_commit_bulk -C source 4 &&
     ++	git -C source config uploadpack.allowFilter true &&
     ++	git -C source config uploadpack.allowAnySHA1InWant true &&
     ++	COMMIT=$(git -C source rev-parse main~1) &&
     ++
     ++	# Fetch a single commit as a non-promisor object, then unshallow it
     ++	# with a filter that omits trees. The commits below the former
     ++	# shallow boundary are now promisor objects whose trees are missing.
     ++	git init target &&
     ++	git -C target remote add origin "file://$(pwd)/source" &&
     ++	git -C target fetch --no-tags --depth=1 origin "+$COMMIT:refs/remotes/origin/main" &&
     ++	git -C target fetch --no-tags --filter=tree:0 --unshallow origin \
     ++		"+$COMMIT:refs/remotes/origin/main" &&
     ++	test_path_is_missing target/.git/shallow &&
     ++
     ++	# Fetching a descendant of the local non-promisor commit causes
     ++	# index-pack to repack that commit into a promisor pack. The revision
     ++	# walk must not die when it reaches the missing trees of promisor commits.
     ++	git -C target fetch --no-tags --filter=tree:0 origin \
     ++		+refs/heads/main:refs/remotes/origin/main &&
     ++	git -C target rev-parse --verify refs/remotes/origin/main &&
     ++	git -C target fsck
      +'
      +
     - test_expect_success 'extensions.partialclone without filter' '
     - 	test_create_repo server &&
     - 	git clone --filter="blob:none" "file://$(pwd)/server" client &&
     + 
     + . "$TEST_DIRECTORY"/lib-httpd.sh
     + start_httpd


 builtin/pack-objects.c   |  7 +++--
 t/t5616-partial-clone.sh | 56 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 61 insertions(+), 2 deletions(-)

diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index 65c2ad9a86..0b40b23b33 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -5091,8 +5091,11 @@ static int is_not_in_promisor_pack_obj(struct object *obj, void *data UNUSED)
 		.source_infop = &source_info,
 	};
 
-	if (odb_read_object_info_extended(the_repository->objects, &obj->oid, &info, 0))
-		BUG("should_include_obj should only be called on existing objects");
+	if (odb_read_object_info_extended(the_repository->objects, &obj->oid, &info,
+					  OBJECT_INFO_SKIP_FETCH_OBJECT)) {
+		/* Missing; assume it is a promisor object. */
+		return 0;
+	}
 	return source_info.source->type != ODB_SOURCE_PACKED || !source_info.u.packed.pack->pack_promisor;
 }
 
diff --git a/t/t5616-partial-clone.sh b/t/t5616-partial-clone.sh
index 7cc6f58a31..bee6261411 100755
--- a/t/t5616-partial-clone.sh
+++ b/t/t5616-partial-clone.sh
@@ -747,6 +747,62 @@ test_expect_success 'after fetching descendants of non-promisor commits, gc work
 	git -C partial gc --prune=now
 '
 
+for opt in --unshallow --deepen=1
+do
+	test_expect_success "filtered fetch $opt of a moved ref repacks local links" '
+		test_when_finished "rm -rf source target" &&
+
+		git init source &&
+		test_commit_bulk -C source 4 &&
+		git -C source config uploadpack.allowFilter true &&
+		git -C source config uploadpack.allowAnySHA1InWant true &&
+		COMMIT=$(git -C source rev-parse main~1) &&
+
+		git init target &&
+		git -C target remote add origin "file://$(pwd)/source" &&
+		git -C target fetch --no-tags --depth=1 origin "+$COMMIT:refs/remotes/origin/main" &&
+
+		# The fetched pack has the new tip whose parent is the local shallow
+		# tip, so index-pack repacks it into a promisor pack. That process
+		# inherits the shallow file and walks into promisor commits whose
+		# trees do not exist.
+		git -C target fetch --no-tags --filter=tree:0 "$opt" origin \
+			+refs/heads/main:refs/remotes/origin/main &&
+		git -C target rev-parse --verify refs/remotes/origin/main >actual &&
+		git -C source rev-parse --verify refs/heads/main >expect &&
+		test_cmp expect actual &&
+		git -C target fsck
+	'
+done
+
+test_expect_success 'repacking local links tolerates missing trees of promisor commits' '
+	test_when_finished "rm -rf source target" &&
+
+	git init source &&
+	test_commit_bulk -C source 4 &&
+	git -C source config uploadpack.allowFilter true &&
+	git -C source config uploadpack.allowAnySHA1InWant true &&
+	COMMIT=$(git -C source rev-parse main~1) &&
+
+	# Fetch a single commit as a non-promisor object, then unshallow it
+	# with a filter that omits trees. The commits below the former
+	# shallow boundary are now promisor objects whose trees are missing.
+	git init target &&
+	git -C target remote add origin "file://$(pwd)/source" &&
+	git -C target fetch --no-tags --depth=1 origin "+$COMMIT:refs/remotes/origin/main" &&
+	git -C target fetch --no-tags --filter=tree:0 --unshallow origin \
+		"+$COMMIT:refs/remotes/origin/main" &&
+	test_path_is_missing target/.git/shallow &&
+
+	# Fetching a descendant of the local non-promisor commit causes
+	# index-pack to repack that commit into a promisor pack. The revision
+	# walk must not die when it reaches the missing trees of promisor commits.
+	git -C target fetch --no-tags --filter=tree:0 origin \
+		+refs/heads/main:refs/remotes/origin/main &&
+	git -C target rev-parse --verify refs/remotes/origin/main &&
+	git -C target fsck
+'
+
 
 . "$TEST_DIRECTORY"/lib-httpd.sh
 start_httpd

base-commit: 1630431f326e15fcde608827b5ff38422528eb59
-- 
gitgitgadget

  reply	other threads:[~2026-11-25 19:49 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25 19:40 [PATCH] pack-objects: handle missing promisor objects Alessio Attilio via GitGitGadget
2026-11-25 19:49 ` Alessio Attilio via GitGitGadget [this message]
2026-11-25 22:47   ` [PATCH v2] " Junio C Hamano
2026-11-25 23:11 ` [PATCH v3] " Alessio Attilio via GitGitGadget
2026-11-26  1:10   ` Junio C Hamano
2026-11-26 10:48     ` ATTILIO ALESSIO
2026-11-25 23:22 ` [PATCH v4] " Alessio Attilio via GitGitGadget
2026-11-25 23:42 ` [PATCH v5] " Alessio Attilio via GitGitGadget

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

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

  git send-email \
    --in-reply-to=pull.2333.v2.git.1795636170423.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=attilio.alessio@protonmail.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.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.