Skip to content

Commit 3eb6679

Browse files
committed
Merge branch 'ps/environ-wo-the-repository'
Code clean-up. * ps/environ-wo-the-repository: (21 commits) environment: stop storing "core.notesRef" globally environment: stop storing "core.warnAmbiguousRefs" globally environment: stop storing "core.preferSymlinkRefs" globally environment: stop storing "core.logAllRefUpdates" globally refs: stop modifying global `log_all_ref_updates` variable branch: stop modifying `log_all_ref_updates` variable repo-settings: track defaults close to `struct repo_settings` repo-settings: split out declarations into a standalone header environment: guard state depending on a repository environment: reorder header to split out `the_repository`-free section environment: move `set_git_dir()` and related into setup layer environment: make `get_git_namespace()` self-contained environment: move object database functions into object layer config: make dependency on repo in `read_early_config()` explicit config: document `read_early_config()` and `read_very_early_config()` environment: make `get_git_work_tree()` accept a repository environment: make `get_graft_file()` accept a repository environment: make `get_index_file()` accept a repository environment: make `get_object_directory()` accept a repository environment: make `get_git_common_dir()` accept a repository ...
2 parents 57155e7 + 1e7e4a1 commit 3eb6679

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+698
-560
lines changed

alias.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#define USE_THE_REPOSITORY_VARIABLE
2+
13
#include "git-compat-util.h"
24
#include "alias.h"
35
#include "config.h"
@@ -37,7 +39,7 @@ char *alias_lookup(const char *alias)
3739
{
3840
struct config_alias_data data = { alias, NULL };
3941

40-
read_early_config(config_alias_cb, &data);
42+
read_early_config(the_repository, config_alias_cb, &data);
4143

4244
return data.v;
4345
}
@@ -46,7 +48,7 @@ void list_aliases(struct string_list *list)
4648
{
4749
struct config_alias_data data = { NULL, NULL, list };
4850

49-
read_early_config(config_alias_cb, &data);
51+
read_early_config(the_repository, config_alias_cb, &data);
5052
}
5153

5254
void quote_cmdline(struct strbuf *buf, const char **argv)

apply.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "path.h"
3131
#include "quote.h"
3232
#include "read-cache.h"
33+
#include "repository.h"
3334
#include "rerere.h"
3435
#include "apply.h"
3536
#include "entry.h"
@@ -4113,7 +4114,7 @@ static int read_apply_cache(struct apply_state *state)
41134114
{
41144115
if (state->index_file)
41154116
return read_index_from(state->repo->index, state->index_file,
4116-
get_git_dir());
4117+
repo_get_git_dir(the_repository));
41174118
else
41184119
return repo_read_index(state->repo);
41194120
}

branch.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,7 @@ void create_branch(struct repository *r,
601601
int forcing = 0;
602602
struct ref_transaction *transaction;
603603
struct strbuf err = STRBUF_INIT;
604+
int flags = 0;
604605
char *msg;
605606

606607
if (track == BRANCH_TRACK_OVERRIDE)
@@ -619,7 +620,7 @@ void create_branch(struct repository *r,
619620
goto cleanup;
620621

621622
if (reflog)
622-
log_all_ref_updates = LOG_REFS_NORMAL;
623+
flags |= REF_FORCE_CREATE_REFLOG;
623624

624625
if (forcing)
625626
msg = xstrfmt("branch: Reset to %s", start_name);
@@ -630,7 +631,7 @@ void create_branch(struct repository *r,
630631
if (!transaction ||
631632
ref_transaction_update(transaction, ref.buf,
632633
&oid, forcing ? NULL : null_oid(),
633-
NULL, NULL, 0, msg, &err) ||
634+
NULL, NULL, flags, msg, &err) ||
634635
ref_transaction_commit(transaction, &err))
635636
die("%s", err.buf);
636637
ref_transaction_free(transaction);

builtin/am.c

+9-4
Original file line numberDiff line numberDiff line change
@@ -1544,7 +1544,8 @@ static int run_apply(const struct am_state *state, const char *index_file)
15441544
if (index_file) {
15451545
/* Reload index as apply_all_patches() will have modified it. */
15461546
discard_index(the_repository->index);
1547-
read_index_from(the_repository->index, index_file, get_git_dir());
1547+
read_index_from(the_repository->index, index_file,
1548+
repo_get_git_dir(the_repository));
15481549
}
15491550

15501551
return 0;
@@ -1587,7 +1588,7 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pa
15871588
return error("could not build fake ancestor");
15881589

15891590
discard_index(the_repository->index);
1590-
read_index_from(the_repository->index, index_path, get_git_dir());
1591+
read_index_from(the_repository->index, index_path, repo_get_git_dir(the_repository));
15911592

15921593
if (write_index_as_tree(&bases[0], the_repository->index, index_path, 0, NULL))
15931594
return error(_("Repository lacks necessary blobs to fall back on 3-way merge."));
@@ -1667,7 +1668,9 @@ static void do_commit(const struct am_state *state)
16671668
if (!state->no_verify && run_hooks(the_repository, "pre-applypatch"))
16681669
exit(1);
16691670

1670-
if (write_index_as_tree(&tree, the_repository->index, get_index_file(), 0, NULL))
1671+
if (write_index_as_tree(&tree, the_repository->index,
1672+
repo_get_index_file(the_repository),
1673+
0, NULL))
16711674
die(_("git write-tree failed to write a tree"));
16721675

16731676
if (!repo_get_oid_commit(the_repository, "HEAD", &parent)) {
@@ -2077,7 +2080,9 @@ static int clean_index(const struct object_id *head, const struct object_id *rem
20772080
if (fast_forward_to(head_tree, head_tree, 1))
20782081
return -1;
20792082

2080-
if (write_index_as_tree(&index, the_repository->index, get_index_file(), 0, NULL))
2083+
if (write_index_as_tree(&index, the_repository->index,
2084+
repo_get_index_file(the_repository),
2085+
0, NULL))
20812086
return -1;
20822087

20832088
index_tree = parse_tree_indirect(&index);

builtin/blame.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1081,7 +1081,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
10811081
path = add_prefix(prefix, argv[1]);
10821082
argv[1] = argv[2];
10831083
} else { /* (2a) */
1084-
if (argc == 2 && is_a_rev(argv[1]) && !get_git_work_tree())
1084+
if (argc == 2 && is_a_rev(argv[1]) && !repo_get_work_tree(the_repository))
10851085
die("missing <path> to blame");
10861086
path = add_prefix(prefix, argv[argc - 1]);
10871087
}

builtin/checkout.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "read-cache.h"
2424
#include "refs.h"
2525
#include "remote.h"
26+
#include "repo-settings.h"
2627
#include "resolve-undo.h"
2728
#include "revision.h"
2829
#include "setup.h"
@@ -950,11 +951,13 @@ static void update_refs_for_switch(const struct checkout_opts *opts,
950951
const char *old_desc, *reflog_msg;
951952
if (opts->new_branch) {
952953
if (opts->new_orphan_branch) {
954+
enum log_refs_config log_all_ref_updates =
955+
repo_settings_get_log_all_ref_updates(the_repository);
953956
char *refname;
954957

955958
refname = mkpathdup("refs/heads/%s", opts->new_orphan_branch);
956959
if (opts->new_branch_log &&
957-
!should_autocreate_reflog(refname)) {
960+
!should_autocreate_reflog(log_all_ref_updates, refname)) {
958961
int ret;
959962
struct strbuf err = STRBUF_INIT;
960963

builtin/commit-graph.c

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#include "builtin.h"
22
#include "commit.h"
33
#include "config.h"
4-
#include "environment.h"
54
#include "gettext.h"
65
#include "hex.h"
76
#include "parse-options.h"
@@ -95,7 +94,7 @@ static int graph_verify(int argc, const char **argv, const char *prefix)
9594
usage_with_options(builtin_commit_graph_verify_usage, options);
9695

9796
if (!opts.obj_dir)
98-
opts.obj_dir = get_object_directory();
97+
opts.obj_dir = repo_get_object_directory(the_repository);
9998
if (opts.shallow)
10099
flags |= COMMIT_GRAPH_VERIFY_SHALLOW;
101100
if (opts.progress)
@@ -275,7 +274,7 @@ static int graph_write(int argc, const char **argv, const char *prefix)
275274
if (opts.reachable + opts.stdin_packs + opts.stdin_commits > 1)
276275
die(_("use at most one of --reachable, --stdin-commits, or --stdin-packs"));
277276
if (!opts.obj_dir)
278-
opts.obj_dir = get_object_directory();
277+
opts.obj_dir = repo_get_object_directory(the_repository);
279278
if (opts.append)
280279
flags |= COMMIT_GRAPH_WRITE_APPEND;
281280
if (opts.split)

builtin/commit.c

+7-6
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "path.h"
2727
#include "preload-index.h"
2828
#include "read-cache.h"
29+
#include "repository.h"
2930
#include "string-list.h"
3031
#include "rerere.h"
3132
#include "unpack-trees.h"
@@ -407,7 +408,7 @@ static const char *prepare_index(const char **argv, const char *prefix,
407408

408409
discard_index(the_repository->index);
409410
read_index_from(the_repository->index, get_lock_file_path(&index_lock),
410-
get_git_dir());
411+
repo_get_git_dir(the_repository));
411412
if (cache_tree_update(the_repository->index, WRITE_TREE_SILENT) == 0) {
412413
if (reopen_lock_file(&index_lock) < 0)
413414
die(_("unable to write index file"));
@@ -472,7 +473,7 @@ static const char *prepare_index(const char **argv, const char *prefix,
472473
COMMIT_LOCK | SKIP_IF_UNCHANGED))
473474
die(_("unable to write new index file"));
474475
commit_style = COMMIT_AS_IS;
475-
ret = get_index_file();
476+
ret = repo_get_index_file(the_repository);
476477
goto out;
477478
}
478479

@@ -534,7 +535,7 @@ static const char *prepare_index(const char **argv, const char *prefix,
534535

535536
discard_index(the_repository->index);
536537
ret = get_lock_file_path(&false_lock);
537-
read_index_from(the_repository->index, ret, get_git_dir());
538+
read_index_from(the_repository->index, ret, repo_get_git_dir(the_repository));
538539
out:
539540
string_list_clear(&partial, 0);
540541
clear_pathspec(&pathspec);
@@ -1072,7 +1073,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
10721073
*/
10731074
discard_index(the_repository->index);
10741075
}
1075-
read_index_from(the_repository->index, index_file, get_git_dir());
1076+
read_index_from(the_repository->index, index_file, repo_get_git_dir(the_repository));
10761077

10771078
if (cache_tree_update(the_repository->index, 0)) {
10781079
error(_("Error building trees"));
@@ -1873,8 +1874,8 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
18731874

18741875
repo_rerere(the_repository, 0);
18751876
run_auto_maintenance(quiet);
1876-
run_commit_hook(use_editor, get_index_file(), NULL, "post-commit",
1877-
NULL);
1877+
run_commit_hook(use_editor, repo_get_index_file(the_repository),
1878+
NULL, "post-commit", NULL);
18781879
if (amend && !no_post_rewrite) {
18791880
commit_post_rewrite(the_repository, current_head, &oid);
18801881
}

builtin/config.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -807,8 +807,8 @@ static void location_options_init(struct config_location_options *opts,
807807
else
808808
opts->options.respect_includes = opts->respect_includes_opt;
809809
if (startup_info->have_repository) {
810-
opts->options.commondir = get_git_common_dir();
811-
opts->options.git_dir = get_git_dir();
810+
opts->options.commondir = repo_get_common_dir(the_repository);
811+
opts->options.git_dir = repo_get_git_dir(the_repository);
812812
}
813813
}
814814

builtin/count-objects.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#include "builtin.h"
88
#include "config.h"
99
#include "dir.h"
10-
#include "environment.h"
1110
#include "gettext.h"
1211
#include "path.h"
1312
#include "repository.h"
@@ -116,7 +115,7 @@ int cmd_count_objects(int argc, const char **argv, const char *prefix)
116115
report_linked_checkout_garbage(the_repository);
117116
}
118117

119-
for_each_loose_file_in_objdir(get_object_directory(),
118+
for_each_loose_file_in_objdir(repo_get_object_directory(the_repository),
120119
count_loose, count_cruft, NULL, NULL);
121120

122121
if (verbose) {

builtin/difftool.c

+5-4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "hex.h"
2323
#include "parse-options.h"
2424
#include "read-cache-ll.h"
25+
#include "repository.h"
2526
#include "sparse-index.h"
2627
#include "strvec.h"
2728
#include "strbuf.h"
@@ -214,7 +215,7 @@ static void changed_files(struct hashmap *result, const char *index_path,
214215
struct child_process update_index = CHILD_PROCESS_INIT;
215216
struct child_process diff_files = CHILD_PROCESS_INIT;
216217
struct strbuf buf = STRBUF_INIT;
217-
const char *git_dir = absolute_path(get_git_dir());
218+
const char *git_dir = absolute_path(repo_get_git_dir(the_repository));
218219
FILE *fp;
219220

220221
strvec_pushl(&update_index.args,
@@ -377,7 +378,7 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix,
377378
struct hashmap wt_modified, tmp_modified;
378379
int indices_loaded = 0;
379380

380-
workdir = get_git_work_tree();
381+
workdir = repo_get_work_tree(the_repository);
381382

382383
/* Setup temp directories */
383384
tmp = getenv("TMPDIR");
@@ -737,8 +738,8 @@ int cmd_difftool(int argc, const char **argv, const char *prefix)
737738

738739
if (!no_index){
739740
setup_work_tree();
740-
setenv(GIT_DIR_ENVIRONMENT, absolute_path(get_git_dir()), 1);
741-
setenv(GIT_WORK_TREE_ENVIRONMENT, absolute_path(get_git_work_tree()), 1);
741+
setenv(GIT_DIR_ENVIRONMENT, absolute_path(repo_get_git_dir(the_repository)), 1);
742+
setenv(GIT_WORK_TREE_ENVIRONMENT, absolute_path(repo_get_work_tree(the_repository)), 1);
742743
} else if (dir_diff)
743744
die(_("options '%s' and '%s' cannot be used together"), "--dir-diff", "--no-index");
744745

builtin/fsmonitor--daemon.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#include "abspath.h"
33
#include "config.h"
44
#include "dir.h"
5-
#include "environment.h"
65
#include "gettext.h"
76
#include "parse-options.h"
87
#include "fsmonitor-ll.h"
@@ -1291,7 +1290,8 @@ static int fsmonitor_run_daemon(void)
12911290

12921291
/* Prepare to (recursively) watch the <worktree-root> directory. */
12931292
strbuf_init(&state.path_worktree_watch, 0);
1294-
strbuf_addstr(&state.path_worktree_watch, absolute_path(get_git_work_tree()));
1293+
strbuf_addstr(&state.path_worktree_watch,
1294+
absolute_path(repo_get_work_tree(the_repository)));
12951295
state.nr_paths_watching = 1;
12961296

12971297
strbuf_init(&state.alias.alias, 0);
@@ -1311,7 +1311,8 @@ static int fsmonitor_run_daemon(void)
13111311
strbuf_addstr(&state.path_gitdir_watch, "/.git");
13121312
if (!is_directory(state.path_gitdir_watch.buf)) {
13131313
strbuf_reset(&state.path_gitdir_watch);
1314-
strbuf_addstr(&state.path_gitdir_watch, absolute_path(get_git_dir()));
1314+
strbuf_addstr(&state.path_gitdir_watch,
1315+
absolute_path(repo_get_git_dir(the_repository)));
13151316
state.nr_paths_watching = 2;
13161317
}
13171318

builtin/gc.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -2132,7 +2132,7 @@ static int schtasks_schedule_task(const char *exec_path, enum schedule_priority
21322132
get_schedule_cmd(&cmd, NULL);
21332133

21342134
strbuf_addf(&tfilename, "%s/schedule_%s_XXXXXX",
2135-
get_git_common_dir(), frequency);
2135+
repo_get_common_dir(the_repository), frequency);
21362136
tfile = xmks_tempfile(tfilename.buf);
21372137
strbuf_release(&tfilename);
21382138

builtin/init-db.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,9 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
231231
set_git_work_tree(work_tree);
232232
else
233233
set_git_work_tree(git_work_tree_cfg);
234-
if (access(get_git_work_tree(), X_OK))
234+
if (access(repo_get_work_tree(the_repository), X_OK))
235235
die_errno (_("Cannot access work tree '%s'"),
236-
get_git_work_tree());
236+
repo_get_work_tree(the_repository));
237237
}
238238
else {
239239
if (real_git_dir)

0 commit comments

Comments
 (0)