Skip to content

Commit eff45da

Browse files
bk2204gitster
authored andcommitted
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 <[email protected]> Reviewed-by: Eric Sunshine <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b5b46d7 commit eff45da

File tree

4 files changed

+33
-11
lines changed

4 files changed

+33
-11
lines changed

builtin/init-db.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,11 +183,6 @@ void initialize_repository_version(int hash_algo)
183183
char repo_version_string[10];
184184
int repo_version = GIT_REPO_VERSION;
185185

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-
191186
if (hash_algo != GIT_HASH_SHA1)
192187
repo_version = GIT_REPO_VERSION_READ;
193188

config.mak.dev

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ DEVELOPER_CFLAGS += -Wstrict-prototypes
1616
DEVELOPER_CFLAGS += -Wunused
1717
DEVELOPER_CFLAGS += -Wvla
1818

19-
DEVELOPER_CFLAGS += -DENABLE_SHA256
20-
2119
ifndef COMPILER_FEATURES
2220
COMPILER_FEATURES := $(shell ./detect-compiler $(CC))
2321
endif

repository.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,6 @@ void repo_set_gitdir(struct repository *repo,
8989
void repo_set_hash_algo(struct repository *repo, int hash_algo)
9090
{
9191
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
9692
}
9793

9894
/*

t/t0001-init.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,39 @@ test_expect_success 're-init from a linked worktree' '
441441
)
442442
'
443443

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+
444477
test_expect_success MINGW 'core.hidedotfiles = false' '
445478
git config --global core.hidedotfiles false &&
446479
rm -rf newdir &&

0 commit comments

Comments
 (0)