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

[PATCH 4/4] Eliminate an unnecessary chdir("..")

From
DRDavid Reiss <dreiss@facebook.com>
Date
May 20, 2008, 06:49 UTC
Message-ID
<4832747E.7070607@facebook.com>

In the case where setup_git_directory_gently fails, avoid the last chdir("..") by moving it after the ceil_offset check.

Signed-off-by: David Reiss <dreiss@facebook.com>
---
Johannes originally asked me to squash this, then asked me to keep the
patch minimal.  I'm including it here in case anyone else thinks it should
go in.  It should be harmless because getcwd is not called in the loop,
and any nonlocal exit from the loop is either a "die" or does a chdir
to cwd, which is an absolute path.
 setup.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/setup.c b/setup.c
index c14b106..045ca20 100644
--- a/setup.c
+++ b/setup.c
@@ -446,7 +446,6 @@ const char *setup_git_directory_gently(int *nongit_ok)
 			check_repository_format_gently(nongit_ok);
 			return NULL;
 		}
-		chdir("..");
 		while (--offset > ceil_offset && cwd[offset] != '/');
 		if (offset <= ceil_offset) {
 			if (nongit_ok) {
@@ -457,6 +456,7 @@ const char *setup_git_directory_gently(int *nongit_ok)
 			}
 			die("Not a git repository");
 		}
+		chdir("..");
 	}
 
 	inside_git_dir = 0;
-- 
1.5.4
Message 1 of 1 in “Eliminate an unnecessary chdir("..")”
  1. 4/4 Eliminate an unnecessary chdir("..")David Reiss, May 20, 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.