Skip to content

Commit 9ae702f

Browse files
bk2204gitster
authored andcommitted
repository: implement extensions.compatObjectFormat
Add a configuration option to enable updating and reading from compatibility hash maps when git accesses the reposotiry. Call the helper function repo_set_compat_hash_algo with the value that compatObjectFormat is set to. Signed-off-by: "Eric W. Biederman" <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2328eba commit 9ae702f

File tree

4 files changed

+35
-3
lines changed

4 files changed

+35
-3
lines changed

Documentation/config/extensions.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,18 @@ Note that this setting should only be set by linkgit:git-init[1] or
77
linkgit:git-clone[1]. Trying to change it after initialization will not
88
work and will produce hard-to-diagnose issues.
99

10+
extensions.compatObjectFormat::
11+
12+
Specify a compatitbility hash algorithm to use. The acceptable values
13+
are `sha1` and `sha256`. The value specified must be different from the
14+
value of extensions.objectFormat. This allows client level
15+
interoperability between git repositories whose objectFormat matches
16+
this compatObjectFormat. In particular when fully implemented the
17+
pushes and pulls from a repository in whose objectFormat matches
18+
compatObjectFormat. As well as being able to use oids encoded in
19+
compatObjectFormat in addition to oids encoded with objectFormat to
20+
locally specify objects.
21+
1022
extensions.worktreeConfig::
1123
If enabled, then worktrees will load config settings from the
1224
`$GIT_DIR/config.worktree` file in addition to the

repository.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ int repo_init(struct repository *repo,
194194
goto error;
195195

196196
repo_set_hash_algo(repo, format.hash_algo);
197-
repo_set_compat_hash_algo(repo, GIT_HASH_UNKNOWN);
197+
repo_set_compat_hash_algo(repo, format.compat_hash_algo);
198198
repo->repository_format_worktree_config = format.worktree_config;
199199

200200
/* take ownership of format.partial_clone */

setup.c

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,25 @@ static enum extension_result handle_extension(const char *var,
590590
"extensions.objectformat", value);
591591
data->hash_algo = format;
592592
return EXTENSION_OK;
593+
} else if (!strcmp(ext, "compatobjectformat")) {
594+
struct string_list_item *item;
595+
int format;
596+
597+
if (!value)
598+
return config_error_nonbool(var);
599+
format = hash_algo_by_name(value);
600+
if (format == GIT_HASH_UNKNOWN)
601+
return error(_("invalid value for '%s': '%s'"),
602+
"extensions.compatobjectformat", value);
603+
/* For now only support compatObjectFormat being specified once. */
604+
for_each_string_list_item(item, &data->v1_only_extensions) {
605+
if (!strcmp(item->string, "compatobjectformat"))
606+
return error(_("'%s' already specified as '%s'"),
607+
"extensions.compatobjectformat",
608+
hash_algos[data->compat_hash_algo].name);
609+
}
610+
data->compat_hash_algo = format;
611+
return EXTENSION_OK;
593612
}
594613
return EXTENSION_UNKNOWN;
595614
}
@@ -1565,7 +1584,7 @@ const char *setup_git_directory_gently(int *nongit_ok)
15651584
if (startup_info->have_repository) {
15661585
repo_set_hash_algo(the_repository, repo_fmt.hash_algo);
15671586
repo_set_compat_hash_algo(the_repository,
1568-
GIT_HASH_UNKNOWN);
1587+
repo_fmt.compat_hash_algo);
15691588
the_repository->repository_format_worktree_config =
15701589
repo_fmt.worktree_config;
15711590
/* take ownership of repo_fmt.partial_clone */
@@ -1659,7 +1678,7 @@ void check_repository_format(struct repository_format *fmt)
16591678
check_repository_format_gently(get_git_dir(), fmt, NULL);
16601679
startup_info->have_repository = 1;
16611680
repo_set_hash_algo(the_repository, fmt->hash_algo);
1662-
repo_set_compat_hash_algo(the_repository, GIT_HASH_UNKNOWN);
1681+
repo_set_compat_hash_algo(the_repository, fmt->compat_hash_algo);
16631682
the_repository->repository_format_worktree_config =
16641683
fmt->worktree_config;
16651684
the_repository->repository_format_partial_clone =

setup.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ struct repository_format {
8686
int worktree_config;
8787
int is_bare;
8888
int hash_algo;
89+
int compat_hash_algo;
8990
int sparse_index;
9091
char *work_tree;
9192
struct string_list unknown_extensions;

0 commit comments

Comments
 (0)