]> git.ipfire.org Git - thirdparty/git.git/commitdiff
setup: convert `set_git_dir()` to have file scope
authorPatrick Steinhardt <ps@pks.im>
Wed, 19 Nov 2025 07:50:50 +0000 (08:50 +0100)
committerJunio C Hamano <gitster@pobox.com>
Thu, 20 Nov 2025 01:41:03 +0000 (17:41 -0800)
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>
setup.c
setup.h

diff --git a/setup.c b/setup.c
index 98c6fd8ee4c02d542746a40e2c94dd90a8bb3e62..8bf52df71663a350071a79f2e3ac60f9e94d663c 100644 (file)
--- a/setup.c
+++ b/setup.c
@@ -1002,6 +1002,46 @@ cleanup_return:
        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,
                                          struct strbuf *cwd,
                                          struct repository_format *repo_fmt,
@@ -1663,46 +1703,6 @@ void setup_git_env(const char *git_dir)
                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)
 {
        static struct strbuf validated_path = STRBUF_INIT;
diff --git a/setup.h b/setup.h
index bfea199bcd8769658ffd6e7fcd4def894f667801..d55dcc66086308b31d86f28bcbb84f5d01e4453f 100644 (file)
--- a/setup.h
+++ b/setup.h
@@ -94,7 +94,6 @@ static inline int discover_git_directory(struct strbuf *commondir,
        return 0;
 }
 
-void set_git_dir(const char *path, int make_realpath);
 void set_git_work_tree(const char *tree);
 
 /* Flags that can be passed to `enter_repo()`. */