environment: stop using `the_repository` in `is_bare_repository()`
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>
Patrick Steinhardt committed
Jun 11, 2026 at 08:44 UTC
2e1d55626f06be7b9374c0a6f579959d750f0cfb
19 files changed
+24
-24
attr.c
+2
-2
@@ -681,7 +681,7 @@ static enum git_attr_direction direction;
681
682
void git_attr_set_direction(enum git_attr_direction new_direction)
683
{
684
- if (is_bare_repository() && new_direction != GIT_ATTR_INDEX)
684
+ if (is_bare_repository(the_repository) && new_direction != GIT_ATTR_INDEX)
685
BUG("non-INDEX attr direction in a bare repo");
686
687
if (new_direction != direction)
@@ -848,7 +848,7 @@ static struct attr_stack *read_attr(struct index_state *istate,
848
res = read_attr_from_index(istate, path, flags);
849
} else if (tree_oid) {
850
res = read_attr_from_blob(istate, tree_oid, path, flags);
851
- } else if (!is_bare_repository()) {
851
+ } else if (!is_bare_repository(the_repository)) {
852
if (direction == GIT_ATTR_CHECKOUT) {
853
res = read_attr_from_index(istate, path, flags);
854
if (!res)
builtin/bisect.c
+1
-1
@@ -724,7 +724,7 @@ static enum bisect_error bisect_start(struct bisect_terms *terms, int argc,
724
struct object_id oid;
725
const char *head;
726
727
- if (is_bare_repository())
727
+ if (is_bare_repository(the_repository))
728
no_checkout = 1;
729
730
/*
builtin/blame.c
+1
-1
@@ -1163,7 +1163,7 @@ parse_done:
1163
1164
revs.disable_stdin = 1;
1165
setup_revisions(argc, argv, &revs, NULL);
1166
- if (!revs.pending.nr && is_bare_repository()) {
1166
+ if (!revs.pending.nr && is_bare_repository(the_repository)) {
1167
struct commit *head_commit;
1168
struct object_id head_oid;
1169
builtin/check-attr.c
+1
-1
@@ -116,7 +116,7 @@ int cmd_check_attr(int argc,
116
struct object_id initialized_oid;
117
int cnt, i, doubledash, filei;
118
119
- if (!is_bare_repository())
119
+ if (!is_bare_repository(the_repository))
120
setup_work_tree(the_repository);
121
122
repo_config(the_repository, git_default_config, NULL);
builtin/fetch.c
+1
-1
@@ -1764,7 +1764,7 @@ static int set_head(const struct ref *remote_refs, struct remote *remote)
1764
1765
if (!head_name)
1766
goto cleanup;
1767
- baremirror = is_bare_repository() && remote->mirror;
1767
+ baremirror = is_bare_repository(the_repository) && remote->mirror;
1768
create_only = follow_remote_head == FOLLOW_REMOTE_ALWAYS ? 0 : !baremirror;
1769
if (baremirror) {
1770
strbuf_addstr(&b_head, "HEAD");
builtin/gc.c
+1
-1
@@ -902,7 +902,7 @@ int cmd_gc(int argc,
902
die(_("failed to parse gc.logExpiry value %s"), cfg.gc_log_expire);
903
904
if (cfg.pack_refs < 0)
905
- cfg.pack_refs = !is_bare_repository();
905
+ cfg.pack_refs = !is_bare_repository(the_repository);
906
907
argc = parse_options(argc, argv, prefix, builtin_gc_options,
908
builtin_gc_usage, 0);
builtin/history.c
+1
-1
@@ -525,7 +525,7 @@ static int cmd_history_fixup(int argc,
525
if (action == REF_ACTION_DEFAULT)
526
action = REF_ACTION_BRANCHES;
527
528
- if (is_bare_repository()) {
528
+ if (is_bare_repository(repo)) {
529
ret = error(_("cannot run fixup in a bare repository"));
530
goto out;
531
}
builtin/repack.c
+1
-1
@@ -265,7 +265,7 @@ int cmd_repack(int argc,
265
266
if (write_bitmaps < 0) {
267
if (write_midx == REPACK_WRITE_MIDX_NONE &&
268
- (!(pack_everything & ALL_INTO_ONE) || !is_bare_repository()))
268
+ (!(pack_everything & ALL_INTO_ONE) || !is_bare_repository(the_repository)))
269
write_bitmaps = 0;
270
}
271
if (po_args.pack_kept_objects < 0)
builtin/repo.c
+1
-1
@@ -58,7 +58,7 @@ struct repo_info_field {
58
59
static int get_layout_bare(struct repository *repo UNUSED, struct strbuf *buf)
60
{
61
- strbuf_addstr(buf, is_bare_repository() ? "true" : "false");
61
+ strbuf_addstr(buf, is_bare_repository(the_repository) ? "true" : "false");
62
return 0;
63
}
64
builtin/reset.c
+1
-1
@@ -470,7 +470,7 @@ int cmd_reset(int argc,
470
if (reset_type != SOFT && (reset_type != MIXED || repo_get_work_tree(the_repository)))
471
setup_work_tree(the_repository);
472
473
- if (reset_type == MIXED && is_bare_repository())
473
+ if (reset_type == MIXED && is_bare_repository(the_repository))
474
die(_("%s reset is not allowed in a bare repository"),
475
_(reset_type_names[reset_type]));
476
builtin/rev-parse.c
+1
-1
@@ -1084,7 +1084,7 @@ int cmd_rev_parse(int argc,
1084
continue;
1085
}
1086
if (!strcmp(arg, "--is-bare-repository")) {
1087
- printf("%s\n", is_bare_repository() ? "true"
1087
+ printf("%s\n", is_bare_repository(the_repository) ? "true"
1088
: "false");
1089
continue;
1090
}
environment.c
+2
-2
@@ -132,10 +132,10 @@ const char *getenv_safe(struct strvec *argv, const char *name)
132
return argv->v[argv->nr - 1];
133
}
134
135
-int is_bare_repository(void)
135
+int is_bare_repository(struct repository *repo)
136
{
137
/* if core.bare is not 'false', let's see if there is a work tree */
138
- return the_repository->bare_cfg && !repo_get_work_tree(the_repository);
138
+ return repo->bare_cfg && !repo_get_work_tree(repo);
139
}
140
141
int have_git_dir(void)
environment.h
+2
-2
@@ -125,6 +125,8 @@ int git_default_core_config(const char *var, const char *value,
125
126
void repo_config_values_init(struct repo_config_values *cfg);
127
128
+int is_bare_repository(struct repository *repo);
129
+
130
/*
131
* TODO: All the below state either explicitly or implicitly relies on
132
* `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);
149
*/
150
int have_git_dir(void);
151
150
-int is_bare_repository(void);
151
-
152
/* Environment bits from configuration mechanism */
153
extern int trust_executable_bit;
154
extern int trust_ctime;
mailmap.c
+2
-2
@@ -219,10 +219,10 @@ int read_mailmap(struct repository *repo, struct string_list *map)
219
map->strdup_strings = 1;
220
map->cmp = namemap_cmp;
221
222
- if (!mailmap_blob && is_bare_repository())
222
+ if (!mailmap_blob && is_bare_repository(the_repository))
223
mailmap_blob = xstrdup("HEAD:.mailmap");
224
225
- if (!startup_info->have_repository || !is_bare_repository())
225
+ if (!startup_info->have_repository || !is_bare_repository(the_repository))
226
err |= read_mailmap_file(map, ".mailmap",
227
startup_info->have_repository ?
228
MAILMAP_NOFOLLOW : 0);
refs/files-backend.c
+1
-1
@@ -1865,7 +1865,7 @@ static int log_ref_setup(struct files_ref_store *refs,
1865
char *logfile;
1866
1867
if (log_refs_cfg == LOG_REFS_UNSET)
1868
- log_refs_cfg = is_bare_repository() ? LOG_REFS_NONE : LOG_REFS_NORMAL;
1868
+ log_refs_cfg = is_bare_repository(the_repository) ? LOG_REFS_NONE : LOG_REFS_NORMAL;
1869
1870
files_reflog_path(refs, &logfile_sb, refname);
1871
logfile = strbuf_detach(&logfile_sb, NULL);
refs/reftable-backend.c
+1
-1
@@ -288,7 +288,7 @@ static int should_write_log(struct reftable_ref_store *refs, const char *refname
288
{
289
enum log_refs_config log_refs_cfg = refs->log_all_ref_updates;
290
if (log_refs_cfg == LOG_REFS_UNSET)
291
- log_refs_cfg = is_bare_repository() ? LOG_REFS_NONE : LOG_REFS_NORMAL;
291
+ log_refs_cfg = is_bare_repository(the_repository) ? LOG_REFS_NONE : LOG_REFS_NORMAL;
292
293
switch (log_refs_cfg) {
294
case LOG_REFS_NONE:
setup.c
+1
-1
@@ -2610,7 +2610,7 @@ static int create_default_files(struct repository *repo,
2610
}
2611
repo_config_set(repo, "core.filemode", filemode ? "true" : "false");
2612
2613
- if (is_bare_repository())
2613
+ if (is_bare_repository(the_repository))
2614
repo_config_set(repo, "core.bare", "true");
2615
else {
2616
repo_config_set(repo, "core.bare", "false");
transport.c
+2
-2
@@ -1482,7 +1482,7 @@ int transport_push(struct repository *r,
1482
1483
if ((flags & (TRANSPORT_RECURSE_SUBMODULES_ON_DEMAND |
1484
TRANSPORT_RECURSE_SUBMODULES_ONLY)) &&
1485
- !is_bare_repository()) {
1485
+ !is_bare_repository(the_repository)) {
1486
struct ref *ref = remote_refs;
1487
struct oid_array commits = OID_ARRAY_INIT;
1488
@@ -1509,7 +1509,7 @@ int transport_push(struct repository *r,
1509
if (((flags & TRANSPORT_RECURSE_SUBMODULES_CHECK) ||
1510
((flags & (TRANSPORT_RECURSE_SUBMODULES_ON_DEMAND |
1511
TRANSPORT_RECURSE_SUBMODULES_ONLY)) &&
1512
- !pretend)) && !is_bare_repository()) {
1512
+ !pretend)) && !is_bare_repository(the_repository)) {
1513
struct ref *ref = remote_refs;
1514
struct string_list needs_pushing = STRING_LIST_INIT_DUP;
1515
struct oid_array commits = OID_ARRAY_INIT;
worktree.c
+1
-1
@@ -124,7 +124,7 @@ static struct worktree *get_main_worktree(int skip_reading_head)
124
worktree->path = strbuf_detach(&worktree_path, NULL);
125
worktree->is_current = is_current_worktree(worktree);
126
worktree->is_bare = (the_repository->bare_cfg == 1) ||
127
- is_bare_repository() ||
127
+ is_bare_repository(the_repository) ||
128
/*
129
* When in a secondary worktree we have to also verify if the main
130
* worktree is bare in $commondir/config.worktree.