This reverts commit e26f7f19b6c7485f04234946a59ab8f4fd21d6d1. The root problem, git clone not setting up the_hash_algo, has been fixed in the previous patch. Since this is a dangerous move and could potentially break stuff after release (and leads to workaround like the reverted commit), the workaround technically remains, but is hidden behind a new environment variable GIT_HASH_FIXUP. This should let the users continue to use git while we fix the problem. This variable can be deleted after one or two releases. test-dump-split-index.c needs to call setup_git_directory() after this to configure hash algorithm before parsing the index file. It's not the best way (i.e. check index file version) but it's a test tool, this is good enough. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@xxxxxxxxx> --- common-main.c | 10 ++++++++++ repository.c | 2 +- repository.h | 5 +++++ t/helper/test-dump-split-index.c | 2 ++ 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/common-main.c b/common-main.c index 6a689007e7..fbfa98c3b8 100644 --- a/common-main.c +++ b/common-main.c @@ -1,6 +1,7 @@ #include "cache.h" #include "exec_cmd.h" #include "attr.h" +#include "repository.h" /* * Many parts of Git have subprograms communicate via pipe, expect the @@ -40,5 +41,14 @@ int main(int argc, const char **argv) restore_sigpipe_to_default(); + /* + * Temporary recovery measure while hashing code is being + * refactored. This variable should be gone after everybody + * has used the_hash_algo in one or two releases and nobody + * complains anything. + */ + if (getenv("GIT_HASH_FIXUP")) + repo_set_hash_algo(the_repository, GIT_HASH_SHA1); + return cmd_main(argc, argv); } diff --git a/repository.c b/repository.c index 4ffbe9bc94..0d715f4fdb 100644 --- a/repository.c +++ b/repository.c @@ -5,7 +5,7 @@ /* The main repository */ static struct repository the_repo = { - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &the_index, &hash_algos[GIT_HASH_SHA1], 0, 0 + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &the_index, NULL, 0, 0 }; struct repository *the_repository = &the_repo; diff --git a/repository.h b/repository.h index 02c695bc74..40bd49611f 100644 --- a/repository.h +++ b/repository.h @@ -110,6 +110,11 @@ extern int repo_read_index(struct repository *repo); static inline const struct git_hash_algo *repo_get_hash_algo( const struct repository *repo) { + if (!repo->hash_algo) + die("BUG: hash_algo is not initialized!\n%s", + _("You can work around this by setting environment" + " variable GIT_HASH_FIXUP=1.\n" + "Please report this to git@xxxxxxxxxxxxxxx")); return repo->hash_algo; } diff --git a/t/helper/test-dump-split-index.c b/t/helper/test-dump-split-index.c index e44430b699..b759fe3fc1 100644 --- a/t/helper/test-dump-split-index.c +++ b/t/helper/test-dump-split-index.c @@ -12,6 +12,8 @@ int cmd_main(int ac, const char **av) struct split_index *si; int i; + setup_git_directory(); + do_read_index(&the_index, av[1], 1); printf("own %s\n", sha1_to_hex(the_index.sha1)); si = the_index.split_index; -- 2.16.1.435.g8f24da2e1a