repository: enable SHA-256 support by default
Now that we have a complete SHA-256 implementation in Git, let's enable it so people can use it. Remove the ENABLE_SHA256 define constant everywhere it's used. Add tests for initializing a repository with SHA-256. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Reviewed-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
brian m. carlson committed
Jul 29, 2020 at 23:14 UTC
eff45daab8a5414f38bda6d83c6669f1bf95e570
4 files changed
+33
-11
builtin/init-db.c
-5
@@ -183,11 +183,6 @@ void initialize_repository_version(int hash_algo)
183
char repo_version_string[10];
184
int repo_version = GIT_REPO_VERSION;
185
186
-#ifndef ENABLE_SHA256
187
- if (hash_algo != GIT_HASH_SHA1)
188
- die(_("The hash algorithm %s is not supported in this build."), hash_algos[hash_algo].name);
189
-#endif
190
-
186
if (hash_algo != GIT_HASH_SHA1)
187
repo_version = GIT_REPO_VERSION_READ;
188
config.mak.dev
-2
@@ -16,8 +16,6 @@ DEVELOPER_CFLAGS += -Wstrict-prototypes
16
DEVELOPER_CFLAGS += -Wunused
17
DEVELOPER_CFLAGS += -Wvla
18
19
-DEVELOPER_CFLAGS += -DENABLE_SHA256
20
-
19
ifndef COMPILER_FEATURES
20
COMPILER_FEATURES := $(shell ./detect-compiler $(CC))
21
endif
repository.c
-4
@@ -89,10 +89,6 @@ void repo_set_gitdir(struct repository *repo,
89
void repo_set_hash_algo(struct repository *repo, int hash_algo)
90
{
91
repo->hash_algo = &hash_algos[hash_algo];
92
-#ifndef ENABLE_SHA256
93
- if (hash_algo != GIT_HASH_SHA1)
94
- die(_("The hash algorithm %s is not supported in this build."), repo->hash_algo->name);
95
-#endif
92
}
93
94
/*
t/t0001-init.sh
+33
@@ -441,6 +441,39 @@ test_expect_success 're-init from a linked worktree' '
441
)
442
'
443
444
+test_expect_success 'init honors GIT_DEFAULT_HASH' '
445
+ GIT_DEFAULT_HASH=sha1 git init sha1 &&
446
+ git -C sha1 rev-parse --show-object-format >actual &&
447
+ echo sha1 >expected &&
448
+ test_cmp expected actual &&
449
+ GIT_DEFAULT_HASH=sha256 git init sha256 &&
450
+ git -C sha256 rev-parse --show-object-format >actual &&
451
+ echo sha256 >expected &&
452
+ test_cmp expected actual
453
+'
454
+
455
+test_expect_success 'init honors --object-format' '
456
+ git init --object-format=sha1 explicit-sha1 &&
457
+ git -C explicit-sha1 rev-parse --show-object-format >actual &&
458
+ echo sha1 >expected &&
459
+ test_cmp expected actual &&
460
+ git init --object-format=sha256 explicit-sha256 &&
461
+ git -C explicit-sha256 rev-parse --show-object-format >actual &&
462
+ echo sha256 >expected &&
463
+ test_cmp expected actual
464
+'
465
+
466
+test_expect_success 'extensions.objectFormat is not allowed with repo version 0' '
467
+ git init --object-format=sha256 explicit-v0 &&
468
+ git -C explicit-v0 config core.repositoryformatversion 0 &&
469
+ test_must_fail git -C explicit-v0 rev-parse --show-object-format
470
+'
471
+
472
+test_expect_success 'init rejects attempts to initialize with different hash' '
473
+ test_must_fail git -C sha1 init --object-format=sha256 &&
474
+ test_must_fail git -C sha256 init --object-format=sha1
475
+'
476
+
477
test_expect_success MINGW 'core.hidedotfiles = false' '
478
git config --global core.hidedotfiles false &&
479
rm -rf newdir &&