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" <ebiederm@xmission.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
brian m. carlson committed
Oct 1, 2023 at 21:40 UTC
9ae702faf151802f481e68db8d5cb5b536b31c2a
4 files changed
+35
-3
Documentation/config/extensions.txt
+12
@@ -7,6 +7,18 @@ Note that this setting should only be set by linkgit:git-init[1] or
7
linkgit:git-clone[1]. Trying to change it after initialization will not
8
work and will produce hard-to-diagnose issues.
9
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
+
22
extensions.worktreeConfig::
23
If enabled, then worktrees will load config settings from the
24
`$GIT_DIR/config.worktree` file in addition to the
repository.c
+1
-1
@@ -194,7 +194,7 @@ int repo_init(struct repository *repo,
194
goto error;
195
196
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);
198
repo->repository_format_worktree_config = format.worktree_config;
199
200
/* take ownership of format.partial_clone */
setup.c
+21
-2
@@ -590,6 +590,25 @@ static enum extension_result handle_extension(const char *var,
590
"extensions.objectformat", value);
591
data->hash_algo = format;
592
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;
612
}
613
return EXTENSION_UNKNOWN;
614
}
@@ -1565,7 +1584,7 @@ const char *setup_git_directory_gently(int *nongit_ok)
1584
if (startup_info->have_repository) {
1585
repo_set_hash_algo(the_repository, repo_fmt.hash_algo);
1586
repo_set_compat_hash_algo(the_repository,
1568
- GIT_HASH_UNKNOWN);
1587
+ repo_fmt.compat_hash_algo);
1588
the_repository->repository_format_worktree_config =
1589
repo_fmt.worktree_config;
1590
/* take ownership of repo_fmt.partial_clone */
@@ -1659,7 +1678,7 @@ void check_repository_format(struct repository_format *fmt)
1678
check_repository_format_gently(get_git_dir(), fmt, NULL);
1679
startup_info->have_repository = 1;
1680
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);
1682
the_repository->repository_format_worktree_config =
1683
fmt->worktree_config;
1684
the_repository->repository_format_partial_clone =
setup.h
+1
@@ -86,6 +86,7 @@ struct repository_format {
86
int worktree_config;
87
int is_bare;
88
int hash_algo;
89
+ int compat_hash_algo;
90
int sparse_index;
91
char *work_tree;
92
struct string_list unknown_extensions;