@@ -736,3 +736,9 @@ core.abbrev::
If set to "no", no abbreviation is made and the object names
are shown in their full length.
The minimum length is 4.
+
+core.compatMap::
+ Enables the use of a compat map to recored the hash in the
+ other object format. This allows repositories in different
+ objects formats to interoperate. It allows looking up old oids
+ in a repository that has been converted from sha1 to sha256.
@@ -104,6 +104,16 @@ void repo_set_hash_algo(struct repository *repo, int hash_algo)
repo->hash_algo = &hash_algos[hash_algo];
}
+void repo_enable_compat_map(struct repository *repo, int enable_compat)
+{
+ const struct git_hash_algo *other_algo =
+ &hash_algos[(hash_algo_by_ptr(repo->hash_algo) == GIT_HASH_SHA1) ?
+ GIT_HASH_SHA256 :
+ GIT_HASH_SHA1];
+
+ repo->compat_hash_algo = enable_compat ? other_algo : NULL;
+}
+
/*
* Attempt to resolve and set the provided 'gitdir' for repository 'repo'.
* Return 0 upon success and a non-zero value upon failure.
@@ -184,6 +194,7 @@ int repo_init(struct repository *repo,
goto error;
repo_set_hash_algo(repo, format.hash_algo);
+ repo_enable_compat_map(repo, format.use_compat_map);
repo->repository_format_worktree_config = format.worktree_config;
/* take ownership of format.partial_clone */
@@ -202,6 +202,7 @@ void repo_set_gitdir(struct repository *repo, const char *root,
const struct set_gitdir_args *extra_args);
void repo_set_worktree(struct repository *repo, const char *path);
void repo_set_hash_algo(struct repository *repo, int algo);
+void repo_enable_compat_map(struct repository *repo, int enable_compat);
void initialize_the_repository(void);
RESULT_MUST_BE_USED
int repo_init(struct repository *r, const char *gitdir, const char *worktree);
@@ -623,6 +623,8 @@ static int check_repo_format(const char *var, const char *value,
return 0;
}
}
+ else if (strcmp(var, "core.compatmap") == 0)
+ data->use_compat_map = git_config_bool(var, value);
return read_worktree_config(var, value, ctx, vdata);
}
@@ -1564,8 +1566,10 @@ const char *setup_git_directory_gently(int *nongit_ok)
}
if (startup_info->have_repository) {
repo_set_hash_algo(the_repository, repo_fmt.hash_algo);
+ repo_enable_compat_map(the_repository, repo_fmt.use_compat_map);
the_repository->repository_format_worktree_config =
repo_fmt.worktree_config;
+
/* take ownership of repo_fmt.partial_clone */
the_repository->repository_format_partial_clone =
repo_fmt.partial_clone;
@@ -1657,6 +1661,7 @@ void check_repository_format(struct repository_format *fmt)
check_repository_format_gently(get_git_dir(), fmt, NULL);
startup_info->have_repository = 1;
repo_set_hash_algo(the_repository, fmt->hash_algo);
+ repo_enable_compat_map(the_repository, fmt->use_compat_map);
the_repository->repository_format_worktree_config =
fmt->worktree_config;
the_repository->repository_format_partial_clone =
@@ -86,6 +86,7 @@ struct repository_format {
int worktree_config;
int is_bare;
int hash_algo;
+ int use_compat_map;
int sparse_index;
char *work_tree;
struct string_list unknown_extensions;