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>
Patrick Steinhardt committed
Nov 19, 2025 at 08:50 UTC
7c188a9e45405ff911b81a5dd9029f4e91fb338e
2 files changed
+40
-41
setup.c
+40
-40
@@ -1002,6 +1002,46 @@ cleanup_return:
1002
return error_code ? NULL : path;
1003
}
1004
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
+
1045
static const char *setup_explicit_git_dir(const char *gitdirenv,
1046
struct strbuf *cwd,
1047
struct repository_format *repo_fmt,
@@ -1663,46 +1703,6 @@ void setup_git_env(const char *git_dir)
1703
fetch_if_missing = 0;
1704
}
1705
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
-
1706
const char *enter_repo(const char *path, unsigned flags)
1707
{
1708
static struct strbuf validated_path = STRBUF_INIT;
setup.h
-1
@@ -94,7 +94,6 @@ static inline int discover_git_directory(struct strbuf *commondir,
94
return 0;
95
}
96
97
-void set_git_dir(const char *path, int make_realpath);
97
void set_git_work_tree(const char *tree);
98
99
/* Flags that can be passed to `enter_repo()`. */