Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>2018-03-03 14:35:55 +0300
committerJunio C Hamano <gitster@pobox.com>2018-03-05 22:14:03 +0300
commit357a03ebe9e04329705a46ff36d526c5ab0c3ebc (patch)
treec95809c925390ceae12fa925af722576c5675afe /repository.c
parentb2f0eceecf266e60fa95970e0973a8f23f911fb1 (diff)
repository.c: move env-related setup code back to environment.c
It does not make sense that generic repository code contains handling of environment variables, which are specific for the main repository only. Refactor repo_set_gitdir() function to take $GIT_DIR and optionally _all_ other customizable paths. These optional paths can be NULL and will be calculated according to the default directory layout. Note that some dead functions are left behind to reduce diff noise. They will be deleted in the next patch. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'repository.c')
-rw-r--r--repository.c58
1 files changed, 40 insertions, 18 deletions
diff --git a/repository.c b/repository.c
index 0eddf28fcd..bb53b54b6d 100644
--- a/repository.c
+++ b/repository.c
@@ -40,34 +40,55 @@ static int find_common_dir(struct strbuf *sb, const char *gitdir, int fromenv)
return get_common_dir_noenv(sb, gitdir);
}
-static void repo_setup_env(struct repository *repo)
+static void expand_base_dir(char **out, const char *in,
+ const char *base_dir, const char *def_in)
+{
+ free(*out);
+ if (in)
+ *out = xstrdup(in);
+ else
+ *out = xstrfmt("%s/%s", base_dir, def_in);
+}
+
+static void repo_set_commondir(struct repository *repo,
+ const char *commondir)
{
struct strbuf sb = STRBUF_INIT;
- repo->different_commondir = find_common_dir(&sb, repo->gitdir,
- !repo->ignore_env);
free(repo->commondir);
+
+ if (commondir) {
+ repo->different_commondir = 1;
+ repo->commondir = xstrdup(commondir);
+ return;
+ }
+
+ repo->different_commondir = get_common_dir_noenv(&sb, repo->gitdir);
repo->commondir = strbuf_detach(&sb, NULL);
- free(repo->objectdir);
- repo->objectdir = git_path_from_env(DB_ENVIRONMENT, repo->commondir,
- "objects", !repo->ignore_env);
- free(repo->graft_file);
- repo->graft_file = git_path_from_env(GRAFT_ENVIRONMENT, repo->commondir,
- "info/grafts", !repo->ignore_env);
- free(repo->index_file);
- repo->index_file = git_path_from_env(INDEX_ENVIRONMENT, repo->gitdir,
- "index", !repo->ignore_env);
}
-void repo_set_gitdir(struct repository *repo, const char *path)
+void repo_set_gitdir(struct repository *repo,
+ const char *root,
+ const struct set_gitdir_args *o)
{
- const char *gitfile = read_gitfile(path);
+ const char *gitfile = read_gitfile(root);
+ /*
+ * repo->gitdir is saved because the caller could pass "root"
+ * that also points to repo->gitdir. We want to keep it alive
+ * until after xstrdup(root). Then we can free it.
+ */
char *old_gitdir = repo->gitdir;
- repo->gitdir = xstrdup(gitfile ? gitfile : path);
- repo_setup_env(repo);
-
+ repo->gitdir = xstrdup(gitfile ? gitfile : root);
free(old_gitdir);
+
+ repo_set_commondir(repo, o->commondir);
+ expand_base_dir(&repo->objectdir, o->object_dir,
+ repo->commondir, "objects");
+ expand_base_dir(&repo->graft_file, o->graft_file,
+ repo->commondir, "info/grafts");
+ expand_base_dir(&repo->index_file, o->index_file,
+ repo->gitdir, "index");
}
void repo_set_hash_algo(struct repository *repo, int hash_algo)
@@ -85,6 +106,7 @@ static int repo_init_gitdir(struct repository *repo, const char *gitdir)
int error = 0;
char *abspath = NULL;
const char *resolved_gitdir;
+ struct set_gitdir_args args = { NULL };
abspath = real_pathdup(gitdir, 0);
if (!abspath) {
@@ -99,7 +121,7 @@ static int repo_init_gitdir(struct repository *repo, const char *gitdir)
goto out;
}
- repo_set_gitdir(repo, resolved_gitdir);
+ repo_set_gitdir(repo, resolved_gitdir, &args);
out:
free(abspath);