git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] midx: disable replace objects

From
BGblanet via GitGitGadget <gitgitgadget@gmail.com>
Date
Apr 7, 2024, 13:11 UTC
Message-ID
<pull.1711.git.1712495507815.gitgitgadget@gmail.com>
From: Xing Xin <xingxin.xx@bytedance.com>

We observed a series of clone failures arose in a specific set of repositories after we fully enabled the MIDX bitmap feature within our Codebase service. These failures were accompanied with error messages such as:

  fatal: did not receive expected object ...
  fatal: fetch-pack: invalid index-pack output

Temporarily disabling the MIDX feature eliminated the reported issues. After some investigation we found that all repositories experiencing failures contain replace references, which seem to be improperly acknowledged by the MIDX bitmap generation logic. During cloning or fetching, git-pack-objects, which may make use of MIDX bitmap to find objects to pack, would give wrong objects even if we explicitly specified not to enable replace refs by GIT_NO_REPLACE_OBJECTS=1. Indeed, this issue appears to have persisted since the introduction of MIDX.

This patch updates the MIDX logic to disable replace objects during operations, mirroring the handling seen in single pack index scenarios, i.e. git-index-pack and git-pack-objects. The added test uses git-rev-list to give a more intuitive check.

Signed-off-by: Xing Xin <xingxin.xx@bytedance.com>
---
    midx: disable replace objects
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1711%2Fblanet%2Fxx%2Fmidx-ignore-replace-objects-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1711/blanet/xx/midx-ignore-replace-objects-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/1711
 builtin/multi-pack-index.c    |  3 +++
 t/t5326-multi-pack-bitmaps.sh | 24 ++++++++++++++++++++++++
 2 files changed, 27 insertions(+)
diff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c
index a72aebecaa2..8360932d2e7 100644
--- a/builtin/multi-pack-index.c
+++ b/builtin/multi-pack-index.c
@@ -8,6 +8,7 @@
 #include "strbuf.h"
 #include "trace2.h"
 #include "object-store-ll.h"
+#include "replace-object.h"
 
 #define BUILTIN_MIDX_WRITE_USAGE \
 	N_("git multi-pack-index [<options>] write [--preferred-pack=<pack>]" \
@@ -273,6 +274,8 @@ int cmd_multi_pack_index(int argc, const char **argv,
 	};
 	struct option *options = parse_options_concat(builtin_multi_pack_index_options, common_opts);
 
+	disable_replace_refs();
+
 	git_config(git_default_config, NULL);
 
 	if (the_repository &&
diff --git a/t/t5326-multi-pack-bitmaps.sh b/t/t5326-multi-pack-bitmaps.sh
index 70d1b58709a..5e4cdef6a8b 100755
--- a/t/t5326-multi-pack-bitmaps.sh
+++ b/t/t5326-multi-pack-bitmaps.sh
@@ -434,6 +434,30 @@ test_expect_success 'tagged commits are selected for bitmapping' '
 	)
 '
 
+test_expect_success 'do not follow replace objects for MIDX bitmap' '
+	rm -fr repo &&
+	git init repo &&
+	test_when_finished "rm -fr repo" &&
+	(
+		cd repo &&
+
+		test_commit A &&
+		A=$(git rev-parse HEAD) &&
+		test_commit B &&
+		B=$(git rev-parse HEAD) &&
+		git checkout --orphan=orphan $A &&
+		test_commit orphan &&
+		C=$(git rev-parse HEAD) &&
+		git rev-list --objects --no-object-names $B |sort >expected &&
+
+		git replace $A $C &&
+		git repack -ad &&
+		git multi-pack-index write --bitmap &&
+		git rev-list --objects --no-object-names --use-bitmap-index $B |sort >actual &&
+		test_cmp expected actual
+	)
+'
+
 corrupt_file () {
 	chmod a+w "$1" &&
 	printf "bogus" | dd of="$1" bs=1 seek="12" conv=notrunc

base-commit: 3c2a3fdc388747b9eaf4a4a4f2035c1c9ddb26d0
-- 
gitgitgadget
Next: Taylor Blau
Message 1 of 9 in “midx: disable replace objects”
  1. midx: disable replace objectsblanet via GitGitGadget, Apr 7, 2024
  2. Taylor BlauApr 7, 2024
  3. Taylor BlauApr 7, 2024
  4. Taylor BlauApr 7, 2024
  5. 鑫邢Apr 8, 2024
  6. midx: disable replace objectsblanet via GitGitGadget, Apr 8, 2024
  7. Junio C HamanoApr 17, 2024
  8. Taylor BlauApr 18, 2024
  9. Junio C HamanoApr 18, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.