summaryrefslogtreecommitdiff
path: root/environment.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2018-04-25 04:28:52 (GMT)
committerJunio C Hamano <gitster@pobox.com>2018-04-25 04:28:52 (GMT)
commitff6eb825f0aa1f45230c10fbb0cf8d484c927c55 (patch)
treee64f3f038b0f888c0ddc0a5c97e0d266068b82a4 /environment.c
parent5d8da91e707668227464c9ba0e74b5fea1ee3b7e (diff)
parentfb9c2d27039a23457cb9710d86e00c51dfb910dc (diff)
downloadgit-ff6eb825f0aa1f45230c10fbb0cf8d484c927c55.zip
git-ff6eb825f0aa1f45230c10fbb0cf8d484c927c55.tar.gz
git-ff6eb825f0aa1f45230c10fbb0cf8d484c927c55.tar.bz2
Merge branch 'jk/relative-directory-fix'
Some codepaths, including the refs API, get and keep relative paths, that go out of sync when the process does chdir(2). The chdir-notify API is introduced to let these codepaths adjust these cached paths to the new current directory. * jk/relative-directory-fix: refs: use chdir_notify to update cached relative paths set_work_tree: use chdir_notify add chdir-notify API trace.c: export trace_setup_key set_git_dir: die when setenv() fails
Diffstat (limited to 'environment.c')
-rw-r--r--environment.c26
1 files changed, 23 insertions, 3 deletions
diff --git a/environment.c b/environment.c
index 39b3d90..fd970b8 100644
--- a/environment.c
+++ b/environment.c
@@ -15,6 +15,7 @@
#include "commit.h"
#include "argv-array.h"
#include "object-store.h"
+#include "chdir-notify.h"
int trust_executable_bit = 1;
int trust_ctime = 1;
@@ -323,12 +324,31 @@ char *get_graft_file(void)
return the_repository->graft_file;
}
-int set_git_dir(const char *path)
+static void set_git_dir_1(const char *path)
{
if (setenv(GIT_DIR_ENVIRONMENT, path, 1))
- return error("Could not set GIT_DIR to '%s'", path);
+ die("could not set GIT_DIR to '%s'", path);
setup_git_env(path);
- return 0;
+}
+
+static void update_relative_gitdir(const char *name,
+ const char *old_cwd,
+ const char *new_cwd,
+ void *data)
+{
+ char *path = reparent_relative_path(old_cwd, new_cwd, get_git_dir());
+ trace_printf_key(&trace_setup_key,
+ "setup: move $GIT_DIR to '%s'",
+ path);
+ set_git_dir_1(path);
+ free(path);
+}
+
+void set_git_dir(const char *path)
+{
+ set_git_dir_1(path);
+ if (!is_absolute_path(path))
+ chdir_notify_register(NULL, update_relative_gitdir, NULL);
}
const char *get_log_output_encoding(void)