diff options
Diffstat (limited to 'repository.c')
-rw-r--r-- | repository.c | 50 |
1 files changed, 24 insertions, 26 deletions
diff --git a/repository.c b/repository.c index f107af7d76..998413b8bb 100644 --- a/repository.c +++ b/repository.c @@ -5,7 +5,7 @@ /* The main repository */ static struct repository the_repo = { - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &the_index, 0, 0 + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &the_index, NULL, 0, 0 }; struct repository *the_repository = &the_repo; @@ -40,11 +40,15 @@ static void repo_setup_env(struct repository *repo) repo->different_commondir = find_common_dir(&sb, repo->gitdir, !repo->ignore_env); + free(repo->commondir); 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); } @@ -52,16 +56,17 @@ static void repo_setup_env(struct repository *repo) void repo_set_gitdir(struct repository *repo, const char *path) { const char *gitfile = read_gitfile(path); + char *old_gitdir = repo->gitdir; - /* - * NEEDSWORK: Eventually we want to be able to free gitdir and the rest - * of the environment before reinitializing it again, but we have some - * crazy code paths where we try to set gitdir with the current gitdir - * and we don't want to free gitdir before copying the passed in value. - */ repo->gitdir = xstrdup(gitfile ? gitfile : path); - repo_setup_env(repo); + + free(old_gitdir); +} + +void repo_set_hash_algo(struct repository *repo, int hash_algo) +{ + repo->hash_algo = &hash_algos[hash_algo]; } /* @@ -136,6 +141,8 @@ int repo_init(struct repository *repo, const char *gitdir, const char *worktree) if (read_and_verify_repository_format(&format, repo->commondir)) goto error; + repo_set_hash_algo(repo, format.hash_algo); + if (worktree) repo_set_worktree(repo, worktree); @@ -200,25 +207,17 @@ out: void repo_clear(struct repository *repo) { - free(repo->gitdir); - repo->gitdir = NULL; - free(repo->commondir); - repo->commondir = NULL; - free(repo->objectdir); - repo->objectdir = NULL; - free(repo->graft_file); - repo->graft_file = NULL; - free(repo->index_file); - repo->index_file = NULL; - free(repo->worktree); - repo->worktree = NULL; - free(repo->submodule_prefix); - repo->submodule_prefix = NULL; + FREE_AND_NULL(repo->gitdir); + FREE_AND_NULL(repo->commondir); + FREE_AND_NULL(repo->objectdir); + FREE_AND_NULL(repo->graft_file); + FREE_AND_NULL(repo->index_file); + FREE_AND_NULL(repo->worktree); + FREE_AND_NULL(repo->submodule_prefix); if (repo->config) { git_configset_clear(repo->config); - free(repo->config); - repo->config = NULL; + FREE_AND_NULL(repo->config); } if (repo->submodule_cache) { @@ -228,8 +227,7 @@ void repo_clear(struct repository *repo) if (repo->index) { discard_index(repo->index); - free(repo->index); - repo->index = NULL; + FREE_AND_NULL(repo->index); } } |