]> git.ipfire.org Git - thirdparty/git.git/blobdiff - setup.c
Start the 2.46 cycle
[thirdparty/git.git] / setup.c
diff --git a/setup.c b/setup.c
index b2d9371ddc229f9999121f12d8cd9096a8d554d6..f4b32f76e3d86b46dbd7713195592906b73b9571 100644 (file)
--- a/setup.c
+++ b/setup.c
@@ -591,6 +591,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;
        } else if (!strcmp(ext, "refstorage")) {
                unsigned int format;
 
@@ -1243,6 +1262,32 @@ static const char *allowed_bare_repo_to_string(
        return NULL;
 }
 
+static int is_implicit_bare_repo(const char *path)
+{
+       /*
+        * what we found is a ".git" directory at the root of
+        * the working tree.
+        */
+       if (ends_with_path_components(path, ".git"))
+               return 1;
+
+       /*
+        * we are inside $GIT_DIR of a secondary worktree of a
+        * non-bare repository.
+        */
+       if (strstr(path, "/.git/worktrees/"))
+               return 1;
+
+       /*
+        * we are inside $GIT_DIR of a worktree of a non-embedded
+        * submodule, whose superproject is not a bare repository.
+        */
+       if (strstr(path, "/.git/modules/"))
+               return 1;
+
+       return 0;
+}
+
 /*
  * We cannot decide in this function whether we are in the work tree or
  * not, since the config can only be read _after_ this function was called.
@@ -1372,7 +1417,7 @@ static enum discovery_result setup_git_directory_gently_1(struct strbuf *dir,
                if (is_git_directory(dir->buf)) {
                        trace2_data_string("setup", NULL, "implicit-bare-repository", dir->buf);
                        if (get_allowed_bare_repo() == ALLOWED_BARE_REPO_EXPLICIT &&
-                           !ends_with_path_components(dir->buf, ".git"))
+                           !is_implicit_bare_repo(dir->buf))
                                return GIT_DIR_DISALLOWED_BARE;
                        if (!ensure_valid_ownership(NULL, NULL, dir->buf, report))
                                return GIT_DIR_INVALID_OWNERSHIP;
@@ -1577,6 +1622,8 @@ 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,
+                                                 repo_fmt.compat_hash_algo);
                        repo_set_ref_storage_format(the_repository,
                                                    repo_fmt.ref_storage_format);
                        the_repository->repository_format_worktree_config =
@@ -1672,6 +1719,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, fmt->compat_hash_algo);
        repo_set_ref_storage_format(the_repository,
                                    fmt->ref_storage_format);
        the_repository->repository_format_worktree_config =