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

[PATCH 5/5] Make setup_git_directory reentrant

From
CTChristian Thaeter <ct@pipapo.org>
Date
Jan 7, 2008, 05:47 UTC
Message-ID
<1199684855-14246-5-git-send-email-ct@pipapo.org>
In-Reply-To
<1199684855-14246-4-git-send-email-ct@pipapo.org>
Reentrant means here one can call it serveral times for different repos.

The functionality introduced here (based on earlier commits) is sufficent to call setup_git_directory() for inspecting the refs like generating a repository list for a browser. For full reset some more works needs to be done later.

Signed-off-by: Christian Thaeter <ct@pipapo.org>
---
 setup.c |   13 ++++++++++++-
 1 files changed, 12 insertions(+), 1 deletions(-)
diff --git a/setup.c b/setup.c
index adede16..770dc41 100644
--- a/setup.c
+++ b/setup.c
@@ -200,6 +200,8 @@ static const char *set_work_tree(const char *dir)
 
 	if (!getcwd(buffer, sizeof(buffer)))
 		die ("Could not get the current working directory");
+	if (git_work_tree_cfg)
+		free (git_work_tree_cfg);
 	git_work_tree_cfg = xstrdup(buffer);
 	inside_work_tree = 1;
 
@@ -329,6 +331,8 @@ const char *setup_git_directory_gently(int *nongit_ok)
 	inside_git_dir = 0;
 	if (!work_tree_env)
 		inside_work_tree = 1;
+	if (git_work_tree_cfg)
+		free (git_work_tree_cfg);
 	git_work_tree_cfg = xstrndup(cwd, offset);
 	if (check_repository_format_gently(nongit_ok))
 		return NULL;
@@ -387,7 +391,14 @@ int check_repository_format(void)
 
 const char *setup_git_directory(void)
 {
-	const char *retval = setup_git_directory_gently(NULL);
+	const char *retval;
+
+	inside_git_dir = -1;
+	inside_work_tree = -1;
+	git_invalidate_cached_refs();
+	reset_packed_git();
+	reset_git_work_tree();
+	retval = setup_git_directory_gently(NULL);
 
 	/* If the work tree is not the default one, recompute prefix */
 	if (inside_work_tree < 0) {
-- 
1.5.3.7
Previous: Christian ThaeterNext: Johannes Schindelin
Message 5 of 8 in “Add streq() to compat-util”
  1. 1/5 Add streq() to compat-utilChristian Thaeter, Jan 7, 2008
  2. 2/5 First step, making setup (somewhat) reentrantChristian Thaeter, Jan 7, 2008
  3. 3/5 provide a reset_packed_git() functionChristian Thaeter, Jan 7, 2008
  4. 4/5 Export some more functions to enable resetting the git stateChristian Thaeter, Jan 7, 2008
  5. 5/5 Make setup_git_directory reentrantChristian Thaeter, Jan 7, 2008
  6. Johannes SchindelinJan 7, 2008
  7. Junio C HamanoJan 7, 2008
  8. Johannes SchindelinJan 7, 2008

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.