]> git.ipfire.org Git - thirdparty/git.git/commitdiff
environment: stop using `the_repository` in `is_bare_repository()`
authorPatrick Steinhardt <ps@pks.im>
Thu, 11 Jun 2026 06:44:44 +0000 (08:44 +0200)
committerJunio C Hamano <gitster@pobox.com>
Thu, 11 Jun 2026 12:05:54 +0000 (05:05 -0700)
Refactor `is_bare_repository()` to take in a repository parameter so
that we no longer depend on `the_repository`. Adjust callers
accordingly.

Furthermore, move the function outside of the declarations that are only
available when `USE_THE_REPOSITORY_VARIABLE` is set, as it no longer
depends on that variable.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
19 files changed:
attr.c
builtin/bisect.c
builtin/blame.c
builtin/check-attr.c
builtin/fetch.c
builtin/gc.c
builtin/history.c
builtin/repack.c
builtin/repo.c
builtin/reset.c
builtin/rev-parse.c
environment.c
environment.h
mailmap.c
refs/files-backend.c
refs/reftable-backend.c
setup.c
transport.c
worktree.c

diff --git a/attr.c b/attr.c
index 75369547b306d6ee838ca81d844e47e9b9894d70..04cb2849541d6f912a65eaf033435f436466da5f 100644 (file)
--- a/attr.c
+++ b/attr.c
@@ -681,7 +681,7 @@ static enum git_attr_direction direction;
 
 void git_attr_set_direction(enum git_attr_direction new_direction)
 {
-       if (is_bare_repository() && new_direction != GIT_ATTR_INDEX)
+       if (is_bare_repository(the_repository) && new_direction != GIT_ATTR_INDEX)
                BUG("non-INDEX attr direction in a bare repo");
 
        if (new_direction != direction)
@@ -848,7 +848,7 @@ static struct attr_stack *read_attr(struct index_state *istate,
                res = read_attr_from_index(istate, path, flags);
        } else if (tree_oid) {
                res = read_attr_from_blob(istate, tree_oid, path, flags);
-       } else if (!is_bare_repository()) {
+       } else if (!is_bare_repository(the_repository)) {
                if (direction == GIT_ATTR_CHECKOUT) {
                        res = read_attr_from_index(istate, path, flags);
                        if (!res)
index e7c2d2f3bb0f4a8be165a11521214a3c3f8a0c7c..798e28f5012d31bf76cd85be3737b450439fd092 100644 (file)
@@ -724,7 +724,7 @@ static enum bisect_error bisect_start(struct bisect_terms *terms, int argc,
        struct object_id oid;
        const char *head;
 
-       if (is_bare_repository())
+       if (is_bare_repository(the_repository))
                no_checkout = 1;
 
        /*
index ffbd3ce5c5a2e39a6140baf7db2129baf38cc4d9..553f4cb78055ebc8dcc1be06a657d61f72fd58c9 100644 (file)
@@ -1163,7 +1163,7 @@ parse_done:
 
        revs.disable_stdin = 1;
        setup_revisions(argc, argv, &revs, NULL);
-       if (!revs.pending.nr && is_bare_repository()) {
+       if (!revs.pending.nr && is_bare_repository(the_repository)) {
                struct commit *head_commit;
                struct object_id head_oid;
 
index 98f64d5b922e6cccfd9e982488783b103843c098..217d83ea7d5de0a996746ef45fb6a622b1ce3f0c 100644 (file)
@@ -116,7 +116,7 @@ int cmd_check_attr(int argc,
        struct object_id initialized_oid;
        int cnt, i, doubledash, filei;
 
-       if (!is_bare_repository())
+       if (!is_bare_repository(the_repository))
                setup_work_tree(the_repository);
 
        repo_config(the_repository, git_default_config, NULL);
index c1d7c672f4e0d87d78d2c981828fff328ec2ca89..44b8c70da1bdbbcc7ab316c46cf8405d49772c17 100644 (file)
@@ -1764,7 +1764,7 @@ static int set_head(const struct ref *remote_refs, struct remote *remote)
 
        if (!head_name)
                goto cleanup;
-       baremirror = is_bare_repository() && remote->mirror;
+       baremirror = is_bare_repository(the_repository) && remote->mirror;
        create_only = follow_remote_head == FOLLOW_REMOTE_ALWAYS ? 0 : !baremirror;
        if (baremirror) {
                strbuf_addstr(&b_head, "HEAD");
index 84a66d32404e4dbdba5e554d63a8cae55cce5f97..61da30de9f3c8f7d7be0aa4e71a5076dfa2d072e 100644 (file)
@@ -902,7 +902,7 @@ int cmd_gc(int argc,
                die(_("failed to parse gc.logExpiry value %s"), cfg.gc_log_expire);
 
        if (cfg.pack_refs < 0)
-               cfg.pack_refs = !is_bare_repository();
+               cfg.pack_refs = !is_bare_repository(the_repository);
 
        argc = parse_options(argc, argv, prefix, builtin_gc_options,
                             builtin_gc_usage, 0);
index 091465a59e2f962c001228e907bf93698acc11b8..fd83de8265e817137fa0a86dd8f92cdf86198ed4 100644 (file)
@@ -525,7 +525,7 @@ static int cmd_history_fixup(int argc,
        if (action == REF_ACTION_DEFAULT)
                action = REF_ACTION_BRANCHES;
 
-       if (is_bare_repository()) {
+       if (is_bare_repository(repo)) {
                ret = error(_("cannot run fixup in a bare repository"));
                goto out;
        }
index 1524a9c13ad5b87e97adc7b5b5a710f22cadbe4c..bbc6f51639d89c47ad0143e00d50a26db1a86332 100644 (file)
@@ -265,7 +265,7 @@ int cmd_repack(int argc,
 
        if (write_bitmaps < 0) {
                if (write_midx == REPACK_WRITE_MIDX_NONE &&
-                   (!(pack_everything & ALL_INTO_ONE) || !is_bare_repository()))
+                   (!(pack_everything & ALL_INTO_ONE) || !is_bare_repository(the_repository)))
                        write_bitmaps = 0;
        }
        if (po_args.pack_kept_objects < 0)
index 71a5c1c29c05fe4b285abe9cf313e20f555247ef..34e96514bc2b77b5adaf38dbefa4fa395af19539 100644 (file)
@@ -58,7 +58,7 @@ struct repo_info_field {
 
 static int get_layout_bare(struct repository *repo UNUSED, struct strbuf *buf)
 {
-       strbuf_addstr(buf, is_bare_repository() ? "true" : "false");
+       strbuf_addstr(buf, is_bare_repository(the_repository) ? "true" : "false");
        return 0;
 }
 
index 3be6bd0121afe5094c8e7e7b011ef589391452f8..78e69bd84ba2c3dc1c47cc1116b7ade059b0bc7f 100644 (file)
@@ -470,7 +470,7 @@ int cmd_reset(int argc,
        if (reset_type != SOFT && (reset_type != MIXED || repo_get_work_tree(the_repository)))
                setup_work_tree(the_repository);
 
-       if (reset_type == MIXED && is_bare_repository())
+       if (reset_type == MIXED && is_bare_repository(the_repository))
                die(_("%s reset is not allowed in a bare repository"),
                    _(reset_type_names[reset_type]));
 
index bb882678fe2a9e3caf538f3cd99015323c79702f..090e5cfbb0b165e7649ee9c08584ca34012718a5 100644 (file)
@@ -1084,7 +1084,7 @@ int cmd_rev_parse(int argc,
                                continue;
                        }
                        if (!strcmp(arg, "--is-bare-repository")) {
-                               printf("%s\n", is_bare_repository() ? "true"
+                               printf("%s\n", is_bare_repository(the_repository) ? "true"
                                                : "false");
                                continue;
                        }
index 9d7c908c55012a4c5500734c3c58a1bb7364fc51..bf209534153b2b7ba57aa0034ca8f2721e0b5d87 100644 (file)
@@ -132,10 +132,10 @@ const char *getenv_safe(struct strvec *argv, const char *name)
        return argv->v[argv->nr - 1];
 }
 
-int is_bare_repository(void)
+int is_bare_repository(struct repository *repo)
 {
        /* if core.bare is not 'false', let's see if there is a work tree */
-       return the_repository->bare_cfg && !repo_get_work_tree(the_repository);
+       return repo->bare_cfg && !repo_get_work_tree(repo);
 }
 
 int have_git_dir(void)
index afb5bcf197d6746ecd0a85a7511e755bad32f5a5..164a55df2ca225c50b1759d33d822a8cc20fe96f 100644 (file)
@@ -125,6 +125,8 @@ int git_default_core_config(const char *var, const char *value,
 
 void repo_config_values_init(struct repo_config_values *cfg);
 
+int is_bare_repository(struct repository *repo);
+
 /*
  * TODO: All the below state either explicitly or implicitly relies on
  * `the_repository`. We should eventually get rid of these and make the
@@ -147,8 +149,6 @@ void repo_config_values_init(struct repo_config_values *cfg);
  */
 int have_git_dir(void);
 
-int is_bare_repository(void);
-
 /* Environment bits from configuration mechanism */
 extern int trust_executable_bit;
 extern int trust_ctime;
index 3b2691781d8ff1131bf6d2a66d15ff6c3d3ce709..7d8590cdd613fb673e8d5eab53c038f872fa91ce 100644 (file)
--- a/mailmap.c
+++ b/mailmap.c
@@ -219,10 +219,10 @@ int read_mailmap(struct repository *repo, struct string_list *map)
        map->strdup_strings = 1;
        map->cmp = namemap_cmp;
 
-       if (!mailmap_blob && is_bare_repository())
+       if (!mailmap_blob && is_bare_repository(the_repository))
                mailmap_blob = xstrdup("HEAD:.mailmap");
 
-       if (!startup_info->have_repository || !is_bare_repository())
+       if (!startup_info->have_repository || !is_bare_repository(the_repository))
                err |= read_mailmap_file(map, ".mailmap",
                                         startup_info->have_repository ?
                                         MAILMAP_NOFOLLOW : 0);
index a4c7858787127d1ffd76d6b898ab928a68d33afc..2b270914840582766d95215a6e8e58dab73f2afa 100644 (file)
@@ -1865,7 +1865,7 @@ static int log_ref_setup(struct files_ref_store *refs,
        char *logfile;
 
        if (log_refs_cfg == LOG_REFS_UNSET)
-               log_refs_cfg = is_bare_repository() ? LOG_REFS_NONE : LOG_REFS_NORMAL;
+               log_refs_cfg = is_bare_repository(the_repository) ? LOG_REFS_NONE : LOG_REFS_NORMAL;
 
        files_reflog_path(refs, &logfile_sb, refname);
        logfile = strbuf_detach(&logfile_sb, NULL);
index 4ae22922de558b184d3627511d74c23d3ee9ce00..101ef29ac868d54a3bf0949128f03a045746c628 100644 (file)
@@ -288,7 +288,7 @@ static int should_write_log(struct reftable_ref_store *refs, const char *refname
 {
        enum log_refs_config log_refs_cfg = refs->log_all_ref_updates;
        if (log_refs_cfg == LOG_REFS_UNSET)
-               log_refs_cfg = is_bare_repository() ? LOG_REFS_NONE : LOG_REFS_NORMAL;
+               log_refs_cfg = is_bare_repository(the_repository) ? LOG_REFS_NONE : LOG_REFS_NORMAL;
 
        switch (log_refs_cfg) {
        case LOG_REFS_NONE:
diff --git a/setup.c b/setup.c
index 32f14a868860eacb982de2cad5151f7d7fe9b8cc..e6db80ab0728e65bcae64dc2b5dcafd2e72a5e2b 100644 (file)
--- a/setup.c
+++ b/setup.c
@@ -2610,7 +2610,7 @@ static int create_default_files(struct repository *repo,
        }
        repo_config_set(repo, "core.filemode", filemode ? "true" : "false");
 
-       if (is_bare_repository())
+       if (is_bare_repository(the_repository))
                repo_config_set(repo, "core.bare", "true");
        else {
                repo_config_set(repo, "core.bare", "false");
index 0f5ec302472d5377d37da2e082fe26cc77fca3e2..fc144f0aedabd9f685f201ce0227e0154421ea3e 100644 (file)
@@ -1482,7 +1482,7 @@ int transport_push(struct repository *r,
 
        if ((flags & (TRANSPORT_RECURSE_SUBMODULES_ON_DEMAND |
                      TRANSPORT_RECURSE_SUBMODULES_ONLY)) &&
-           !is_bare_repository()) {
+           !is_bare_repository(the_repository)) {
                struct ref *ref = remote_refs;
                struct oid_array commits = OID_ARRAY_INIT;
 
@@ -1509,7 +1509,7 @@ int transport_push(struct repository *r,
        if (((flags & TRANSPORT_RECURSE_SUBMODULES_CHECK) ||
             ((flags & (TRANSPORT_RECURSE_SUBMODULES_ON_DEMAND |
                        TRANSPORT_RECURSE_SUBMODULES_ONLY)) &&
-             !pretend)) && !is_bare_repository()) {
+             !pretend)) && !is_bare_repository(the_repository)) {
                struct ref *ref = remote_refs;
                struct string_list needs_pushing = STRING_LIST_INIT_DUP;
                struct oid_array commits = OID_ARRAY_INIT;
index 7d70f2c1dab15f9f790ab77b5d0ff2d2df15509d..30125827fd39ed88b6a8419a2f98a03c643eddb6 100644 (file)
@@ -124,7 +124,7 @@ static struct worktree *get_main_worktree(int skip_reading_head)
        worktree->path = strbuf_detach(&worktree_path, NULL);
        worktree->is_current = is_current_worktree(worktree);
        worktree->is_bare = (the_repository->bare_cfg == 1) ||
-               is_bare_repository() ||
+               is_bare_repository(the_repository) ||
                /*
                 * When in a secondary worktree we have to also verify if the main
                 * worktree is bare in $commondir/config.worktree.