git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 02/13] setup: convert `set_git_dir()` to have file scope

From
Patrick Steinhardt <ps@pks.im>
Date
Nov 19, 2025, 07:50 UTC
Message-ID
<20251119-b4-pks-odb-creation-v1-2-2b2ed2612cb6@pks.im>
In-Reply-To
<20251119-b4-pks-odb-creation-v1-0-2b2ed2612cb6@pks.im>

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>
---
 setup.c | 80 ++++++++++++++++++++++++++++++++---------------------------------
 setup.h |  1 -
 2 files changed, 40 insertions(+), 41 deletions(-)
diff --git a/setup.c b/setup.c
index 98c6fd8ee4..8bf52df716 100644
--- a/setup.c
+++ b/setup.c
@@ -1002,6 +1002,46 @@ const char *read_gitfile_gently(const char *path, int *return_error_code)
 	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 bfea199bcd..d55dcc6608 100644
--- 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()`. */
-- 
2.52.0.rc2.482.gaa765fefd0.dirty
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 3 of 21 in “Centralize management of object database sources”
  1. 00/13 Centralize management of object database sourcesPatrick Steinhardt, Nov 19, 2025
  2. 01/13 path: move `enter_repo()` into "setup.c"Patrick Steinhardt, Nov 19, 2025
  3. 02/13 setup: convert `set_git_dir()` to have file scopePatrick Steinhardt, Nov 19, 2025
  4. 03/13 odb: adopt logic to close object databasesPatrick Steinhardt, Nov 19, 2025
  5. 04/13 odb: refactor `odb_clear()` to `odb_free()`Patrick Steinhardt, Nov 19, 2025
  6. 05/13 odb: move logic to disable ref updates into repoPatrick Steinhardt, Nov 19, 2025
  7. Junio C HamanoNov 19, 2025
  8. Patrick SteinhardtNov 21, 2025
  9. 06/13 oidset: introduce `oidset_equal()`Patrick Steinhardt, Nov 19, 2025
  10. Junio C HamanoNov 19, 2025
  11. 07/13 builtin/index-pack: fix deferred fsck outside reposPatrick Steinhardt, Nov 19, 2025
  12. Junio C HamanoNov 19, 2025
  13. Patrick SteinhardtNov 21, 2025
  14. 08/13 t/helper: stop setting up `the_repository` repeatedlyPatrick Steinhardt, Nov 19, 2025
  15. 09/13 http-push: stop setting up `the_repository` for each referencePatrick Steinhardt, Nov 19, 2025
  16. 10/13 odb: handle initialization of sources in `odb_new()`Patrick Steinhardt, Nov 19, 2025
  17. 11/13 chdir-notify: add function to unregister listenersPatrick Steinhardt, Nov 19, 2025
  18. 12/13 odb: handle changing a repository's commondirPatrick Steinhardt, Nov 19, 2025
  19. Junio C HamanoNov 20, 2025
  20. Patrick SteinhardtNov 21, 2025
  21. 13/13 odb: handle recreation of quarantine directoriesPatrick Steinhardt, Nov 19, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.