]> git.ipfire.org Git - thirdparty/git.git/commitdiff
repository: implement extensions.compatObjectFormat
authorbrian m. carlson <sandals@crustytoothpaste.net>
Mon, 2 Oct 2023 02:40:25 +0000 (21:40 -0500)
committerJunio C Hamano <gitster@pobox.com>
Mon, 2 Oct 2023 21:57:40 +0000 (14:57 -0700)
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>
Documentation/config/extensions.txt
repository.c
setup.c
setup.h

index bccaec7a963679f8262d7c8d056fa4429b9586d1..9f72e6d9f4f17ec68a93c803e1dabfc98d3b61be 100644 (file)
@@ -7,6 +7,18 @@ Note that this setting should only be set by linkgit:git-init[1] or
 linkgit:git-clone[1].  Trying to change it after initialization will not
 work and will produce hard-to-diagnose issues.
 
+extensions.compatObjectFormat::
+
+       Specify a compatitbility hash algorithm to use.  The acceptable values
+       are `sha1` and `sha256`.  The value specified must be different from the
+       value of extensions.objectFormat.  This allows client level
+       interoperability between git repositories whose objectFormat matches
+       this compatObjectFormat.  In particular when fully implemented the
+       pushes and pulls from a repository in whose objectFormat matches
+       compatObjectFormat.  As well as being able to use oids encoded in
+       compatObjectFormat in addition to oids encoded with objectFormat to
+       locally specify objects.
+
 extensions.worktreeConfig::
        If enabled, then worktrees will load config settings from the
        `$GIT_DIR/config.worktree` file in addition to the
index 6214f61cf4e79559cfdb554329eb78d4a153537c..9d91536b613bca2734f9e90fa41d3178b93ecfe9 100644 (file)
@@ -194,7 +194,7 @@ int repo_init(struct repository *repo,
                goto error;
 
        repo_set_hash_algo(repo, format.hash_algo);
-       repo_set_compat_hash_algo(repo, GIT_HASH_UNKNOWN);
+       repo_set_compat_hash_algo(repo, format.compat_hash_algo);
        repo->repository_format_worktree_config = format.worktree_config;
 
        /* take ownership of format.partial_clone */
diff --git a/setup.c b/setup.c
index aa8bf5da5226b7394771e6cc953dc96b7da637ac..85259a259be33e289d8c6ab464d0e1930431f448 100644 (file)
--- a/setup.c
+++ b/setup.c
@@ -590,6 +590,25 @@ static enum extension_result handle_extension(const char *var,
                                     "extensions.objectformat", value);
                data->hash_algo = format;
                return EXTENSION_OK;
+       } else if (!strcmp(ext, "compatobjectformat")) {
+               struct string_list_item *item;
+               int format;
+
+               if (!value)
+                       return config_error_nonbool(var);
+               format = hash_algo_by_name(value);
+               if (format == GIT_HASH_UNKNOWN)
+                       return error(_("invalid value for '%s': '%s'"),
+                                    "extensions.compatobjectformat", value);
+               /* For now only support compatObjectFormat being specified once. */
+               for_each_string_list_item(item, &data->v1_only_extensions) {
+                       if (!strcmp(item->string, "compatobjectformat"))
+                               return error(_("'%s' already specified as '%s'"),
+                                       "extensions.compatobjectformat",
+                                       hash_algos[data->compat_hash_algo].name);
+               }
+               data->compat_hash_algo = format;
+               return EXTENSION_OK;
        }
        return EXTENSION_UNKNOWN;
 }
@@ -1565,7 +1584,7 @@ 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_set_compat_hash_algo(the_repository,
-                                                 GIT_HASH_UNKNOWN);
+                                                 repo_fmt.compat_hash_algo);
                        the_repository->repository_format_worktree_config =
                                repo_fmt.worktree_config;
                        /* take ownership of repo_fmt.partial_clone */
@@ -1659,7 +1678,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_set_compat_hash_algo(the_repository, GIT_HASH_UNKNOWN);
+       repo_set_compat_hash_algo(the_repository, fmt->compat_hash_algo);
        the_repository->repository_format_worktree_config =
                fmt->worktree_config;
        the_repository->repository_format_partial_clone =
diff --git a/setup.h b/setup.h
index 58fd2605dd2697a1c82e1bc81b98a1f783c63d18..5d678ceb8caae89e23823e632ac53ea71d4eb915 100644 (file)
--- a/setup.h
+++ b/setup.h
@@ -86,6 +86,7 @@ struct repository_format {
        int worktree_config;
        int is_bare;
        int hash_algo;
+       int compat_hash_algo;
        int sparse_index;
        char *work_tree;
        struct string_list unknown_extensions;