#include "path.h"
#include "quote.h"
#include "read-cache.h"
+#include "repository.h"
#include "rerere.h"
#include "apply.h"
#include "entry.h"
{
if (state->index_file)
return read_index_from(state->repo->index, state->index_file,
- get_git_dir());
+ repo_get_git_dir(the_repository));
else
return repo_read_index(state->repo);
}
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;
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."));
#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"
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"));
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);
*/
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"));
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);
}
}
#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"
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,
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");
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;
}
#include "object-name.h"
#include "parse-options.h"
#include "lockfile.h"
+#include "repository.h"
#include "run-command.h"
#include "hook.h"
#include "diff.h"
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");
#include "entry.h"
#include "preload-index.h"
#include "read-cache.h"
+#include "repository.h"
#include "rerere.h"
#include "revision.h"
#include "setup.h"
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);
}
#define USE_THE_REPOSITORY_VARIABLE
#include "git-compat-util.h"
-#include "environment.h"
#include "hex.h"
#include "lockfile.h"
#include "tree.h"
#include "object-store-ll.h"
#include "read-cache-ll.h"
#include "replace-object.h"
+#include "repository.h"
#include "promisor-remote.h"
#include "trace.h"
#include "trace2.h"
hold_lock_file_for_update(&lock_file, index_path, LOCK_DIE_ON_ERROR);
- entries = read_index_from(index_state, index_path, get_git_dir());
+ entries = read_index_from(index_state, index_path,
+ repo_get_git_dir(the_repository));
if (entries < 0) {
ret = WRITE_TREE_UNREADABLE_INDEX;
goto out;
*
*/
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "abspath.h"
#include "advice.h"
if (have_git_dir()) {
opts.commondir = get_git_common_dir();
- opts.git_dir = get_git_dir();
+ opts.git_dir = repo_get_git_dir(the_repository);
/*
* When setup_git_directory() was not yet asked to discover the
* GIT_DIR, we ask discover_git_directory() to figure out whether there
|| the_repository->gitdir;
}
-const char *get_git_dir(void)
-{
- if (!the_repository->gitdir)
- BUG("git environment hasn't been setup");
- return the_repository->gitdir;
-}
-
const char *get_git_common_dir(void)
{
if (!the_repository->commondir)
const char *new_cwd,
void *data UNUSED)
{
- char *path = reparent_relative_path(old_cwd, new_cwd, get_git_dir());
+ char *path = reparent_relative_path(old_cwd, new_cwd,
+ repo_get_git_dir(the_repository));
struct tmp_objdir *tmp_objdir = tmp_objdir_unapply_primary_odb();
trace_printf_key(&trace_setup_key,
extern int is_bare_repository_cfg;
int is_bare_repository(void);
extern char *git_work_tree_cfg;
-const char *get_git_dir(void);
const char *get_git_common_dir(void);
const char *get_object_directory(void);
char *get_index_file(void);
copyfrom);
hint_path = get_git_work_tree();
if (!hint_path)
- hint_path = get_git_dir();
+ hint_path = repo_get_git_dir(the_repository);
die(_("%s: '%s' is outside repository at '%s'"), elt,
copyfrom, absolute_path(hint_path));
}
#include "path.h"
#include "preload-index.h"
#include "read-cache.h"
+#include "repository.h"
#include "resolve-undo.h"
#include "revision.h"
#include "strbuf.h"
static int clean_shared_index_files(const char *current_hex)
{
struct dirent *de;
- DIR *dir = opendir(get_git_dir());
+ DIR *dir = opendir(repo_get_git_dir(the_repository));
if (!dir)
- return error_errno(_("unable to open git dir: %s"), get_git_dir());
+ return error_errno(_("unable to open git dir: %s"),
+ repo_get_git_dir(the_repository));
while ((de = readdir(dir)) != NULL) {
const char *sha1_hex;
*out = xstrfmt("%s/%s", base_dir, def_in);
}
+const char *repo_get_git_dir(struct repository *repo)
+{
+ if (!repo->gitdir)
+ BUG("repository hasn't been set up");
+ return repo->gitdir;
+}
+
static void repo_set_commondir(struct repository *repo,
const char *commondir)
{
extern struct repository *the_repository;
#endif
+const char *repo_get_git_dir(struct repository *repo);
+
/*
* Define a custom repository layout. Any field can be NULL, which
* will default back to the path according to the default layout.
if (!r) {
const char *hint_path = get_git_work_tree();
if (!hint_path)
- hint_path = get_git_dir();
+ hint_path = repo_get_git_dir(the_repository);
die(_("'%s' is outside repository at '%s'"), path,
absolute_path(hint_path));
}
int is_inside_git_dir(void)
{
if (inside_git_dir < 0)
- inside_git_dir = is_inside_dir(get_git_dir());
+ inside_git_dir = is_inside_dir(repo_get_git_dir(the_repository));
return inside_git_dir;
}
struct repository_format repo_fmt = REPOSITORY_FORMAT_INIT;
if (!fmt)
fmt = &repo_fmt;
- check_repository_format_gently(get_git_dir(), fmt, NULL);
+ check_repository_format_gently(repo_get_git_dir(the_repository), 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);
* shared-repository settings, we would need to fix them up.
*/
if (get_shared_repository()) {
- adjust_shared_perm(get_git_dir());
+ adjust_shared_perm(repo_get_git_dir(the_repository));
}
initialize_repository_version(fmt->hash_algo, fmt->ref_storage_format, 0);
die(_("%s already exists"), real_git_dir);
set_git_dir(real_git_dir, 1);
- git_dir = get_git_dir();
+ git_dir = repo_get_git_dir(the_repository);
separate_git_dir(git_dir, original_git_dir);
}
else {
set_git_dir(git_dir, 1);
- git_dir = get_git_dir();
+ git_dir = repo_get_git_dir(the_repository);
}
startup_info->have_repository = 1;
struct strbuf *err);
/*
- * Check the repository format version in the path found in get_git_dir(),
+ * Check the repository format version in the path found in repo_get_git_dir(the_repository),
* and die if it is a version we don't understand. Generally one would
* set_git_dir() before calling this, and use it only for "are we in a valid
* repo?".
* along with this program; if not, see <https://www.gnu.org/licenses/>.
*/
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "git-compat-util.h"
#include "abspath.h"
#include "environment.h"
+#include "repository.h"
#include "quote.h"
#include "setup.h"
#include "trace.h"
if (!startup_info->prefix)
prefix = "(null)";
- trace_printf_key(&trace_setup_key, "setup: git_dir: %s\n", quote_crnl(get_git_dir()));
+ trace_printf_key(&trace_setup_key, "setup: git_dir: %s\n", quote_crnl(repo_get_git_dir(the_repository)));
trace_printf_key(&trace_setup_key, "setup: git_common_dir: %s\n", quote_crnl(get_git_common_dir()));
trace_printf_key(&trace_setup_key, "setup: worktree: %s\n", quote_crnl(git_work_tree));
trace_printf_key(&trace_setup_key, "setup: cwd: %s\n", quote_crnl(cwd));
if (have_git_dir())
strvec_pushf(&helper->env, "%s=%s",
- GIT_DIR_ENVIRONMENT, get_git_dir());
+ GIT_DIR_ENVIRONMENT, repo_get_git_dir(the_repository));
helper->trace2_child_class = helper->args.v[0]; /* "remote-<name>" */
static int is_current_worktree(struct worktree *wt)
{
- char *git_dir = absolute_pathdup(get_git_dir());
+ char *git_dir = absolute_pathdup(repo_get_git_dir(the_repository));
const char *wt_git_dir = get_worktree_git_dir(wt);
int is_current = !fspathcmp(git_dir, absolute_path(wt_git_dir));
free(git_dir);
const char *get_worktree_git_dir(const struct worktree *wt)
{
if (!wt)
- return get_git_dir();
+ return repo_get_git_dir(the_repository);
else if (!wt->id)
return get_git_common_dir();
else