mirror of
https://github.com/git/git.git
synced 2025-12-12 20:36:24 +01:00
setup: convert set_git_dir() to have file scope
We don't have any external callers of `set_git_dir()` anymore now that `enter_repo()` has been moved into "setup.c". Remove the declaration and mark the function as static. Note that this change requires us to move the implementation around so that we can avoid adding any new forward declarations. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
831e02340b
commit
7c188a9e45
80
setup.c
80
setup.c
@@ -1002,6 +1002,46 @@ cleanup_return:
|
|||||||
return error_code ? NULL : path;
|
return error_code ? NULL : path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void set_git_dir_1(const char *path)
|
||||||
|
{
|
||||||
|
xsetenv(GIT_DIR_ENVIRONMENT, path, 1);
|
||||||
|
setup_git_env(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void update_relative_gitdir(const char *name UNUSED,
|
||||||
|
const char *old_cwd,
|
||||||
|
const char *new_cwd,
|
||||||
|
void *data UNUSED)
|
||||||
|
{
|
||||||
|
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,
|
||||||
|
"setup: move $GIT_DIR to '%s'",
|
||||||
|
path);
|
||||||
|
set_git_dir_1(path);
|
||||||
|
if (tmp_objdir)
|
||||||
|
tmp_objdir_reapply_primary_odb(tmp_objdir, old_cwd, new_cwd);
|
||||||
|
free(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void set_git_dir(const char *path, int make_realpath)
|
||||||
|
{
|
||||||
|
struct strbuf realpath = STRBUF_INIT;
|
||||||
|
|
||||||
|
if (make_realpath) {
|
||||||
|
strbuf_realpath(&realpath, path, 1);
|
||||||
|
path = realpath.buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
set_git_dir_1(path);
|
||||||
|
if (!is_absolute_path(path))
|
||||||
|
chdir_notify_register(NULL, update_relative_gitdir, NULL);
|
||||||
|
|
||||||
|
strbuf_release(&realpath);
|
||||||
|
}
|
||||||
|
|
||||||
static const char *setup_explicit_git_dir(const char *gitdirenv,
|
static const char *setup_explicit_git_dir(const char *gitdirenv,
|
||||||
struct strbuf *cwd,
|
struct strbuf *cwd,
|
||||||
struct repository_format *repo_fmt,
|
struct repository_format *repo_fmt,
|
||||||
@@ -1663,46 +1703,6 @@ void setup_git_env(const char *git_dir)
|
|||||||
fetch_if_missing = 0;
|
fetch_if_missing = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void set_git_dir_1(const char *path)
|
|
||||||
{
|
|
||||||
xsetenv(GIT_DIR_ENVIRONMENT, path, 1);
|
|
||||||
setup_git_env(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void update_relative_gitdir(const char *name UNUSED,
|
|
||||||
const char *old_cwd,
|
|
||||||
const char *new_cwd,
|
|
||||||
void *data UNUSED)
|
|
||||||
{
|
|
||||||
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,
|
|
||||||
"setup: move $GIT_DIR to '%s'",
|
|
||||||
path);
|
|
||||||
set_git_dir_1(path);
|
|
||||||
if (tmp_objdir)
|
|
||||||
tmp_objdir_reapply_primary_odb(tmp_objdir, old_cwd, new_cwd);
|
|
||||||
free(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
void set_git_dir(const char *path, int make_realpath)
|
|
||||||
{
|
|
||||||
struct strbuf realpath = STRBUF_INIT;
|
|
||||||
|
|
||||||
if (make_realpath) {
|
|
||||||
strbuf_realpath(&realpath, path, 1);
|
|
||||||
path = realpath.buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
set_git_dir_1(path);
|
|
||||||
if (!is_absolute_path(path))
|
|
||||||
chdir_notify_register(NULL, update_relative_gitdir, NULL);
|
|
||||||
|
|
||||||
strbuf_release(&realpath);
|
|
||||||
}
|
|
||||||
|
|
||||||
const char *enter_repo(const char *path, unsigned flags)
|
const char *enter_repo(const char *path, unsigned flags)
|
||||||
{
|
{
|
||||||
static struct strbuf validated_path = STRBUF_INIT;
|
static struct strbuf validated_path = STRBUF_INIT;
|
||||||
|
|||||||
1
setup.h
1
setup.h
@@ -94,7 +94,6 @@ static inline int discover_git_directory(struct strbuf *commondir,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_git_dir(const char *path, int make_realpath);
|
|
||||||
void set_git_work_tree(const char *tree);
|
void set_git_work_tree(const char *tree);
|
||||||
|
|
||||||
/* Flags that can be passed to `enter_repo()`. */
|
/* Flags that can be passed to `enter_repo()`. */
|
||||||
|
|||||||
Reference in New Issue
Block a user