summaryrefslogtreecommitdiff
path: root/environment.c
diff options
context:
space:
mode:
Diffstat (limited to 'environment.c')
-rw-r--r--environment.c31
1 files changed, 23 insertions, 8 deletions
diff --git a/environment.c b/environment.c
index e72a02d0d5..52e0c979ba 100644
--- a/environment.c
+++ b/environment.c
@@ -14,9 +14,10 @@
#include "refs.h"
#include "fmt-merge-msg.h"
#include "commit.h"
-#include "argv-array.h"
+#include "strvec.h"
#include "object-store.h"
#include "chdir-notify.h"
+#include "shallow.h"
int trust_executable_bit = 1;
int trust_ctime = 1;
@@ -155,15 +156,15 @@ static char *expand_namespace(const char *raw_namespace)
* Wrapper of getenv() that returns a strdup value. This value is kept
* in argv to be freed later.
*/
-static const char *getenv_safe(struct argv_array *argv, const char *name)
+static const char *getenv_safe(struct strvec *argv, const char *name)
{
const char *value = getenv(name);
if (!value)
return NULL;
- argv_array_push(argv, value);
- return argv->argv[argv->argc - 1];
+ strvec_push(argv, value);
+ return argv->v[argv->nr - 1];
}
void setup_git_env(const char *git_dir)
@@ -171,7 +172,7 @@ void setup_git_env(const char *git_dir)
const char *shallow_file;
const char *replace_ref_base;
struct set_gitdir_args args = { NULL };
- struct argv_array to_free = ARGV_ARRAY_INIT;
+ struct strvec to_free = STRVEC_INIT;
args.commondir = getenv_safe(&to_free, GIT_COMMON_DIR_ENVIRONMENT);
args.object_dir = getenv_safe(&to_free, DB_ENVIRONMENT);
@@ -179,7 +180,7 @@ void setup_git_env(const char *git_dir)
args.index_file = getenv_safe(&to_free, INDEX_ENVIRONMENT);
args.alternate_db = getenv_safe(&to_free, ALTERNATE_DB_ENVIRONMENT);
repo_set_gitdir(the_repository, git_dir, &args);
- argv_array_clear(&to_free);
+ strvec_clear(&to_free);
if (getenv(NO_REPLACE_OBJECTS_ENVIRONMENT))
read_replace_refs = 0;
@@ -254,8 +255,11 @@ static int git_work_tree_initialized;
*/
void set_git_work_tree(const char *new_work_tree)
{
+ struct strbuf realpath = STRBUF_INIT;
+
if (git_work_tree_initialized) {
- new_work_tree = real_path(new_work_tree);
+ strbuf_realpath(&realpath, new_work_tree, 1);
+ new_work_tree = realpath.buf;
if (strcmp(new_work_tree, the_repository->worktree))
die("internal error: work tree has already been set\n"
"Current worktree: %s\nNew worktree: %s",
@@ -264,6 +268,8 @@ void set_git_work_tree(const char *new_work_tree)
}
git_work_tree_initialized = 1;
repo_set_worktree(the_repository, new_work_tree);
+
+ strbuf_release(&realpath);
}
const char *get_git_work_tree(void)
@@ -345,11 +351,20 @@ static void update_relative_gitdir(const char *name,
free(path);
}
-void set_git_dir(const char *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 *get_log_output_encoding(void)