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

Re: git 2.46.0 crashes when trying to verify-pack outside of a repo

From
Junio C Hamano <gitster@pobox.com>
Date
Sep 1, 2024, 15:26 UTC
Message-ID
<xmqq7cbvpf8v.fsf@gitster.g>
In-Reply-To
<14ec9394-a7ea-456c-800a-6a84c52e5cda@0upti.me>
Ilya K <me@0upti.me> writes:
Show 5 quoted lines
> We've updated to Git 2.46.0 in NixOS, and encountered an issue
> with Dulwich (a Python Git implementation) tests failing[0]
> because it attempts to call `git verify-pack` on a bare pack, with
> no surrounding repo. This used to work in Git 2.45.x, but in 2.46
> it simply prints "error: index-pack died of signal 11".

Thanks. This is a fallout from code-wide clean-up in 2.46.0 where we do not assume that everybody runs SHA-1.

------- >8 -------
Subject: verify-pack: fall back to SHA-1 outside a repo

In c8aed5e8da (repository: stop setting SHA1 as the default object hash, 2024-05-07), we have stopped setting the default hash algorithm for `the_repository`. Consequently, code that relies on `the_hash_algo` will now crash when it hasn't explicitly been initialized, which may be the case when running outside of a Git repository.

As the verify-pack command ought to be able to infer what algorithm is used in the input file (and if the input file does not have such an information, that by itself is a problem), and the command allows an option to explicitly tell what algorithm to use in case it cannot be guessed from the input file, in theory we shouldn't have to use the default algorithm anywhere in the operation of the command, but we fail fairly early in the process when run outside a repository without any default algorithm set.

Resurrect the setting of the default algorithm just like we used to do before 2.46.0

Reported-by: Ilya K <me@0upti.me>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 builtin/verify-pack.c  | 4 ++++
 t/t5300-pack-object.sh | 4 ++++
 2 files changed, 8 insertions(+)
diff --git c/builtin/verify-pack.c w/builtin/verify-pack.c
index 011dddd2dc..5b663905ae 100644
--- c/builtin/verify-pack.c
+++ w/builtin/verify-pack.c
@@ -1,6 +1,7 @@
 #include "builtin.h"
 #include "config.h"
 #include "gettext.h"
+#include "hash.h"
 #include "run-command.h"
 #include "parse-options.h"
 #include "strbuf.h"
@@ -77,6 +78,9 @@ int cmd_verify_pack(int argc, const char **argv, const char *prefix)
 		OPT_END()
 	};
 
+	if (!the_hash_algo)
+		repo_set_hash_algo(the_repository, GIT_HASH_SHA1);
+
 	git_config(git_default_config, NULL);
 	argc = parse_options(argc, argv, prefix, verify_pack_options,
 			     verify_pack_usage, 0);
diff --git c/t/t5300-pack-object.sh w/t/t5300-pack-object.sh
index 4ad023c846..d6f45d8923 100755
--- c/t/t5300-pack-object.sh
+++ w/t/t5300-pack-object.sh
@@ -322,6 +322,10 @@ test_expect_success 'verify-pack catches a corrupted sum of the index file itsel
 	fi
 '
 
+test_expect_success 'verify-pack outside a repository' '
+	nongit git verify-pack -v "$(pwd)/test-1-${packname_1}.idx"
+'
+
 test_expect_success 'build pack index for an existing pack' '
 	cat test-1-${packname_1}.pack >test-3.pack &&
 	git index-pack -o tmp.idx test-3.pack &&
Previous: Ilya KNext: Patrick Steinhardt
Message 2 of 7 in “git 2.46.0 crashes when trying to verify-pack outside of a repo”
  1. Ilya KAug 31, 2024
  2. Junio C HamanoSep 1, 2024
  3. Patrick SteinhardtSep 1, 2024
  4. brian m. carlsonSep 2, 2024
  5. Patrick SteinhardtSep 2, 2024
  6. Junio C HamanoSep 3, 2024
  7. builtin/index-pack: fix segfaults when running outside of a repoPatrick Steinhardt, Sep 4, 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.