aboutsummaryrefslogtreecommitdiffstats
path: root/builtin
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2024-09-12 13:29:24 +0200
committerJunio C Hamano <gitster@pobox.com>2024-09-12 10:15:39 -0700
commit246deeac9517d6daba89bfcf6de6d290e39af585 (patch)
treed604806493140d8f3f9e26f705c749b4a0535311 /builtin
parentThe tenth batch (diff)
downloadgit-246deeac9517d6daba89bfcf6de6d290e39af585.tar.gz
git-246deeac9517d6daba89bfcf6de6d290e39af585.zip
environment: make `get_git_dir()` accept a repository
The `get_git_dir()` function retrieves the path to the Git directory for `the_repository`. Make it accept a `struct repository` such that it can work on arbitrary repositories and make it part of the repository subsystem. This reduces our reliance on `the_repository` and clarifies scope. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin')
-rw-r--r--builtin/am.c5
-rw-r--r--builtin/commit.c7
-rw-r--r--builtin/config.c2
-rw-r--r--builtin/difftool.c5
-rw-r--r--builtin/fsmonitor--daemon.c3
-rw-r--r--builtin/merge.c4
-rw-r--r--builtin/stash.c3
7 files changed, 18 insertions, 11 deletions
diff --git a/builtin/am.c b/builtin/am.c
index d8875ad402..405214e242 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -1544,7 +1544,8 @@ static int run_apply(const struct am_state *state, const char *index_file)
if (index_file) {
/* Reload index as apply_all_patches() will have modified it. */
discard_index(the_repository->index);
- read_index_from(the_repository->index, index_file, get_git_dir());
+ read_index_from(the_repository->index, index_file,
+ repo_get_git_dir(the_repository));
}
return 0;
@@ -1587,7 +1588,7 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pa
return error("could not build fake ancestor");
discard_index(the_repository->index);
- read_index_from(the_repository->index, index_path, get_git_dir());
+ read_index_from(the_repository->index, index_path, repo_get_git_dir(the_repository));
if (write_index_as_tree(&bases[0], the_repository->index, index_path, 0, NULL))
return error(_("Repository lacks necessary blobs to fall back on 3-way merge."));
diff --git a/builtin/commit.c b/builtin/commit.c
index b2033c4887..a1c1d16a09 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -26,6 +26,7 @@
#include "path.h"
#include "preload-index.h"
#include "read-cache.h"
+#include "repository.h"
#include "string-list.h"
#include "rerere.h"
#include "unpack-trees.h"
@@ -407,7 +408,7 @@ static const char *prepare_index(const char **argv, const char *prefix,
discard_index(the_repository->index);
read_index_from(the_repository->index, get_lock_file_path(&index_lock),
- get_git_dir());
+ repo_get_git_dir(the_repository));
if (cache_tree_update(the_repository->index, WRITE_TREE_SILENT) == 0) {
if (reopen_lock_file(&index_lock) < 0)
die(_("unable to write index file"));
@@ -534,7 +535,7 @@ static const char *prepare_index(const char **argv, const char *prefix,
discard_index(the_repository->index);
ret = get_lock_file_path(&false_lock);
- read_index_from(the_repository->index, ret, get_git_dir());
+ read_index_from(the_repository->index, ret, repo_get_git_dir(the_repository));
out:
string_list_clear(&partial, 0);
clear_pathspec(&pathspec);
@@ -1072,7 +1073,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
*/
discard_index(the_repository->index);
}
- read_index_from(the_repository->index, index_file, get_git_dir());
+ read_index_from(the_repository->index, index_file, repo_get_git_dir(the_repository));
if (cache_tree_update(the_repository->index, 0)) {
error(_("Error building trees"));
diff --git a/builtin/config.c b/builtin/config.c
index e00d983596..c10697a2ef 100644
--- a/builtin/config.c
+++ b/builtin/config.c
@@ -808,7 +808,7 @@ static void location_options_init(struct config_location_options *opts,
opts->options.respect_includes = opts->respect_includes_opt;
if (startup_info->have_repository) {
opts->options.commondir = get_git_common_dir();
- opts->options.git_dir = get_git_dir();
+ opts->options.git_dir = repo_get_git_dir(the_repository);
}
}
diff --git a/builtin/difftool.c b/builtin/difftool.c
index dcc68e190c..8c59411e6e 100644
--- a/builtin/difftool.c
+++ b/builtin/difftool.c
@@ -22,6 +22,7 @@
#include "hex.h"
#include "parse-options.h"
#include "read-cache-ll.h"
+#include "repository.h"
#include "sparse-index.h"
#include "strvec.h"
#include "strbuf.h"
@@ -214,7 +215,7 @@ static void changed_files(struct hashmap *result, const char *index_path,
struct child_process update_index = CHILD_PROCESS_INIT;
struct child_process diff_files = CHILD_PROCESS_INIT;
struct strbuf buf = STRBUF_INIT;
- const char *git_dir = absolute_path(get_git_dir());
+ const char *git_dir = absolute_path(repo_get_git_dir(the_repository));
FILE *fp;
strvec_pushl(&update_index.args,
@@ -737,7 +738,7 @@ int cmd_difftool(int argc, const char **argv, const char *prefix)
if (!no_index){
setup_work_tree();
- setenv(GIT_DIR_ENVIRONMENT, absolute_path(get_git_dir()), 1);
+ setenv(GIT_DIR_ENVIRONMENT, absolute_path(repo_get_git_dir(the_repository)), 1);
setenv(GIT_WORK_TREE_ENVIRONMENT, absolute_path(get_git_work_tree()), 1);
} else if (dir_diff)
die(_("options '%s' and '%s' cannot be used together"), "--dir-diff", "--no-index");
diff --git a/builtin/fsmonitor--daemon.c b/builtin/fsmonitor--daemon.c
index 1593713f4c..c54e736716 100644
--- a/builtin/fsmonitor--daemon.c
+++ b/builtin/fsmonitor--daemon.c
@@ -1311,7 +1311,8 @@ static int fsmonitor_run_daemon(void)
strbuf_addstr(&state.path_gitdir_watch, "/.git");
if (!is_directory(state.path_gitdir_watch.buf)) {
strbuf_reset(&state.path_gitdir_watch);
- strbuf_addstr(&state.path_gitdir_watch, absolute_path(get_git_dir()));
+ strbuf_addstr(&state.path_gitdir_watch,
+ absolute_path(repo_get_git_dir(the_repository)));
state.nr_paths_watching = 2;
}
diff --git a/builtin/merge.c b/builtin/merge.c
index 662a49a0e8..a2bae0700b 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -17,6 +17,7 @@
#include "object-name.h"
#include "parse-options.h"
#include "lockfile.h"
+#include "repository.h"
#include "run-command.h"
#include "hook.h"
#include "diff.h"
@@ -855,7 +856,8 @@ static void prepare_to_commit(struct commit_list *remoteheads)
if (invoked_hook)
discard_index(the_repository->index);
}
- read_index_from(the_repository->index, index_file, get_git_dir());
+ read_index_from(the_repository->index, index_file,
+ repo_get_git_dir(the_repository));
strbuf_addbuf(&msg, &merge_msg);
if (squash)
BUG("the control must not reach here under --squash");
diff --git a/builtin/stash.c b/builtin/stash.c
index fcfd97972a..ad6bcefb77 100644
--- a/builtin/stash.c
+++ b/builtin/stash.c
@@ -19,6 +19,7 @@
#include "entry.h"
#include "preload-index.h"
#include "read-cache.h"
+#include "repository.h"
#include "rerere.h"
#include "revision.h"
#include "setup.h"
@@ -642,7 +643,7 @@ restore_untracked:
strvec_pushf(&cp.env, GIT_WORK_TREE_ENVIRONMENT"=%s",
absolute_path(get_git_work_tree()));
strvec_pushf(&cp.env, GIT_DIR_ENVIRONMENT"=%s",
- absolute_path(get_git_dir()));
+ absolute_path(repo_get_git_dir(the_repository)));
strvec_push(&cp.args, "status");
run_command(&cp);
}