Skip to content

Commit 7c188a9

Browse files
pks-tgitster
authored andcommitted
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>
1 parent 831e023 commit 7c188a9

2 files changed

Lines changed: 40 additions & 41 deletions

File tree

setup.c

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,6 +1002,46 @@ const char *read_gitfile_gently(const char *path, int *return_error_code)
10021002
return error_code ? NULL : path;
10031003
}
10041004

1005+
static void set_git_dir_1(const char *path)
1006+
{
1007+
xsetenv(GIT_DIR_ENVIRONMENT, path, 1);
1008+
setup_git_env(path);
1009+
}
1010+
1011+
static void update_relative_gitdir(const char *name UNUSED,
1012+
const char *old_cwd,
1013+
const char *new_cwd,
1014+
void *data UNUSED)
1015+
{
1016+
char *path = reparent_relative_path(old_cwd, new_cwd,
1017+
repo_get_git_dir(the_repository));
1018+
struct tmp_objdir *tmp_objdir = tmp_objdir_unapply_primary_odb();
1019+
1020+
trace_printf_key(&trace_setup_key,
1021+
"setup: move $GIT_DIR to '%s'",
1022+
path);
1023+
set_git_dir_1(path);
1024+
if (tmp_objdir)
1025+
tmp_objdir_reapply_primary_odb(tmp_objdir, old_cwd, new_cwd);
1026+
free(path);
1027+
}
1028+
1029+
static void set_git_dir(const char *path, int make_realpath)
1030+
{
1031+
struct strbuf realpath = STRBUF_INIT;
1032+
1033+
if (make_realpath) {
1034+
strbuf_realpath(&realpath, path, 1);
1035+
path = realpath.buf;
1036+
}
1037+
1038+
set_git_dir_1(path);
1039+
if (!is_absolute_path(path))
1040+
chdir_notify_register(NULL, update_relative_gitdir, NULL);
1041+
1042+
strbuf_release(&realpath);
1043+
}
1044+
10051045
static const char *setup_explicit_git_dir(const char *gitdirenv,
10061046
struct strbuf *cwd,
10071047
struct repository_format *repo_fmt,
@@ -1663,46 +1703,6 @@ void setup_git_env(const char *git_dir)
16631703
fetch_if_missing = 0;
16641704
}
16651705

1666-
static void set_git_dir_1(const char *path)
1667-
{
1668-
xsetenv(GIT_DIR_ENVIRONMENT, path, 1);
1669-
setup_git_env(path);
1670-
}
1671-
1672-
static void update_relative_gitdir(const char *name UNUSED,
1673-
const char *old_cwd,
1674-
const char *new_cwd,
1675-
void *data UNUSED)
1676-
{
1677-
char *path = reparent_relative_path(old_cwd, new_cwd,
1678-
repo_get_git_dir(the_repository));
1679-
struct tmp_objdir *tmp_objdir = tmp_objdir_unapply_primary_odb();
1680-
1681-
trace_printf_key(&trace_setup_key,
1682-
"setup: move $GIT_DIR to '%s'",
1683-
path);
1684-
set_git_dir_1(path);
1685-
if (tmp_objdir)
1686-
tmp_objdir_reapply_primary_odb(tmp_objdir, old_cwd, new_cwd);
1687-
free(path);
1688-
}
1689-
1690-
void set_git_dir(const char *path, int make_realpath)
1691-
{
1692-
struct strbuf realpath = STRBUF_INIT;
1693-
1694-
if (make_realpath) {
1695-
strbuf_realpath(&realpath, path, 1);
1696-
path = realpath.buf;
1697-
}
1698-
1699-
set_git_dir_1(path);
1700-
if (!is_absolute_path(path))
1701-
chdir_notify_register(NULL, update_relative_gitdir, NULL);
1702-
1703-
strbuf_release(&realpath);
1704-
}
1705-
17061706
const char *enter_repo(const char *path, unsigned flags)
17071707
{
17081708
static struct strbuf validated_path = STRBUF_INIT;

setup.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ static inline int discover_git_directory(struct strbuf *commondir,
9494
return 0;
9595
}
9696

97-
void set_git_dir(const char *path, int make_realpath);
9897
void set_git_work_tree(const char *tree);
9998

10099
/* Flags that can be passed to `enter_repo()`. */

0 commit comments

Comments
 (0)