Skip to content

Commit 15a1ca1

Browse files
ebiedermgitster
authored andcommitted
repository: add a compatibility hash algorithm
We currently have support for using a full stage 4 SHA-256 implementation. However, we'd like to support interoperability with SHA-1 repositories as well. The transition plan anticipates a compatibility hash algorithm configuration option that we can use to implement support for this. Let's add an element to the repository structure that indicates the compatibility hash algorithm so we can use it when we need to consider interoperability between algorithms. Add a helper function repo_set_compat_hash_algo that takes a compatibility hash algorithm and sets "repo->compat_hash_algo". If GIT_HASH_UNKNOWN is passed as the compatibility hash algorithm "repo->compat_hash_algo" is set to NULL. For now, the code results in "repo->compat_hash_algo" always being set to NULL, but that will change once a configuration option is added. Inspired-by: brian m. carlson <[email protected]> Signed-off-by: Eric W. Biederman <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 52fca06 commit 15a1ca1

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

repository.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,13 @@ void repo_set_hash_algo(struct repository *repo, int hash_algo)
104104
repo->hash_algo = &hash_algos[hash_algo];
105105
}
106106

107+
void repo_set_compat_hash_algo(struct repository *repo, int algo)
108+
{
109+
if (hash_algo_by_ptr(repo->hash_algo) == algo)
110+
BUG("hash_algo and compat_hash_algo match");
111+
repo->compat_hash_algo = algo ? &hash_algos[algo] : NULL;
112+
}
113+
107114
/*
108115
* Attempt to resolve and set the provided 'gitdir' for repository 'repo'.
109116
* Return 0 upon success and a non-zero value upon failure.
@@ -184,6 +191,7 @@ int repo_init(struct repository *repo,
184191
goto error;
185192

186193
repo_set_hash_algo(repo, format.hash_algo);
194+
repo_set_compat_hash_algo(repo, GIT_HASH_UNKNOWN);
187195
repo->repository_format_worktree_config = format.worktree_config;
188196

189197
/* take ownership of format.partial_clone */

repository.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@ struct repository {
160160
/* Repository's current hash algorithm, as serialized on disk. */
161161
const struct git_hash_algo *hash_algo;
162162

163+
/* Repository's compatibility hash algorithm. */
164+
const struct git_hash_algo *compat_hash_algo;
165+
163166
/* A unique-id for tracing purposes. */
164167
int trace2_repo_id;
165168

@@ -199,6 +202,7 @@ void repo_set_gitdir(struct repository *repo, const char *root,
199202
const struct set_gitdir_args *extra_args);
200203
void repo_set_worktree(struct repository *repo, const char *path);
201204
void repo_set_hash_algo(struct repository *repo, int algo);
205+
void repo_set_compat_hash_algo(struct repository *repo, int compat_algo);
202206
void initialize_the_repository(void);
203207
RESULT_MUST_BE_USED
204208
int repo_init(struct repository *r, const char *gitdir, const char *worktree);

setup.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1564,6 +1564,8 @@ const char *setup_git_directory_gently(int *nongit_ok)
15641564
}
15651565
if (startup_info->have_repository) {
15661566
repo_set_hash_algo(the_repository, repo_fmt.hash_algo);
1567+
repo_set_compat_hash_algo(the_repository,
1568+
GIT_HASH_UNKNOWN);
15671569
the_repository->repository_format_worktree_config =
15681570
repo_fmt.worktree_config;
15691571
/* take ownership of repo_fmt.partial_clone */
@@ -1657,6 +1659,7 @@ void check_repository_format(struct repository_format *fmt)
16571659
check_repository_format_gently(get_git_dir(), fmt, NULL);
16581660
startup_info->have_repository = 1;
16591661
repo_set_hash_algo(the_repository, fmt->hash_algo);
1662+
repo_set_compat_hash_algo(the_repository, GIT_HASH_UNKNOWN);
16601663
the_repository->repository_format_worktree_config =
16611664
fmt->worktree_config;
16621665
the_repository->repository_format_partial_clone =

0 commit comments

Comments
 (0)