Skip to content

Commit

Permalink
verify-pack: fall back to SHA-1 outside a repo
Browse files Browse the repository at this point in the history
In c8aed5e (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>
  • Loading branch information
gitster committed Sep 1, 2024
1 parent 39bf06a commit c5461ee
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions builtin/verify-pack.c
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions t/t5300-pack-object.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down

0 comments on commit c5461ee

Please sign in to comment.