diff options
Diffstat (limited to 'repository.c')
-rw-r--r-- | repository.c | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/repository.c b/repository.c index a4174ddb06..448cd557d4 100644 --- a/repository.c +++ b/repository.c @@ -10,6 +10,7 @@ #include "object.h" #include "lockfile.h" #include "submodule-config.h" +#include "sparse-index.h" /* The main repository */ static struct repository the_repo; @@ -72,7 +73,7 @@ void repo_set_gitdir(struct repository *repo, repo_set_commondir(repo, o->commondir); if (!repo->objects->odb) { - repo->objects->odb = xcalloc(1, sizeof(*repo->objects->odb)); + CALLOC_ARRAY(repo->objects->odb, 1); repo->objects->odb_tail = &repo->objects->odb->next; } expand_base_dir(&repo->objects->odb->path, o->object_dir, @@ -261,10 +262,24 @@ void repo_clear(struct repository *repo) int repo_read_index(struct repository *repo) { + int res; + if (!repo->index) - repo->index = xcalloc(1, sizeof(*repo->index)); + CALLOC_ARRAY(repo->index, 1); + + /* Complete the double-reference */ + if (!repo->index->repo) + repo->index->repo = repo; + else if (repo->index->repo != repo) + BUG("repo's index should point back at itself"); + + res = read_index_from(repo->index, repo->index_file, repo->gitdir); + + prepare_repo_settings(repo); + if (repo->settings.command_requires_full_index) + ensure_full_index(repo->index); - return read_index_from(repo->index, repo->index_file, repo->gitdir); + return res; } int repo_hold_locked_index(struct repository *repo, |