{"thread":{"id":"13584","subject":"[PATCH 4/4] Eliminate an unnecessary chdir(\"..\")","startedAt":"2008-05-20T06:49:34Z","lastAt":"2008-05-20T06:49:34Z","messageCount":1,"participants":["David Reiss"],"isPatch":true,"patchVersion":1,"patchTotal":4},"messages":[{"id":"77309","messageId":"4832747E.7070607@facebook.com","threadId":"13584","inReplyTo":null,"subject":"[PATCH 4/4] Eliminate an unnecessary chdir(\"..\")","fromName":"David Reiss","fromEmail":"dreiss@facebook.com","sentAt":"2008-05-20T06:49:34Z","receivedAt":"2008-05-20T06:49:34Z","isPatch":true,"sender":{"key":"dreiss@facebook.com","avatar":null},"body":"In the case where setup_git_directory_gently fails, avoid the last\nchdir(\"..\") by moving it after the ceil_offset check.\n\nSigned-off-by: David Reiss <dreiss@facebook.com>\n---\nJohannes originally asked me to squash this, then asked me to keep the\npatch minimal.  I'm including it here in case anyone else thinks it should\ngo in.  It should be harmless because getcwd is not called in the loop,\nand any nonlocal exit from the loop is either a \"die\" or does a chdir\nto cwd, which is an absolute path.\n\n setup.c |    2 +-\n 1 files changed, 1 insertions(+), 1 deletions(-)\n\ndiff --git a/setup.c b/setup.c\nindex c14b106..045ca20 100644\n--- a/setup.c\n+++ b/setup.c\n@@ -446,7 +446,6 @@ const char *setup_git_directory_gently(int *nongit_ok)\n \t\t\tcheck_repository_format_gently(nongit_ok);\n \t\t\treturn NULL;\n \t\t}\n-\t\tchdir(\"..\");\n \t\twhile (--offset > ceil_offset && cwd[offset] != '/');\n \t\tif (offset <= ceil_offset) {\n \t\t\tif (nongit_ok) {\n@@ -457,6 +456,7 @@ const char *setup_git_directory_gently(int *nongit_ok)\n \t\t\t}\n \t\t\tdie(\"Not a git repository\");\n \t\t}\n+\t\tchdir(\"..\");\n \t}\n \n \tinside_git_dir = 0;\n-- \n1.5.4\n"}]}