summaryrefslogtreecommitdiff
path: root/repository.c
diff options
context:
space:
mode:
authorDerrick Stolee <dstolee@microsoft.com>2021-01-23 19:58:15 (GMT)
committerJunio C Hamano <gitster@pobox.com>2021-01-24 01:14:07 (GMT)
commit1fd9ae517c45294a01466aad0d38f99c7893d814 (patch)
treeb19cb6e494b98f5e4673c74cceaeaee9d421c4a4 /repository.c
parentcae70acf2431f0c31e5c097b96fa5bd752526e6d (diff)
downloadgit-1fd9ae517c45294a01466aad0d38f99c7893d814.zip
git-1fd9ae517c45294a01466aad0d38f99c7893d814.tar.gz
git-1fd9ae517c45294a01466aad0d38f99c7893d814.tar.bz2
repository: add repo reference to index_state
It will be helpful to add behavior to index operations that might trigger an object lookup. Since each index belongs to a specific repository, add a 'repo' pointer to struct index_state that allows access to this repository. Add a BUG() statement if the repo already has an index, and the index already has a repo, but somehow the index points to a different repo. This will prevent future changes from needing to pass an additional 'struct repository *repo' parameter and instead rely only on the 'struct index_state *istate' parameter. Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'repository.c')
-rw-r--r--repository.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/repository.c b/repository.c
index a4174dd..c98298a 100644
--- a/repository.c
+++ b/repository.c
@@ -264,6 +264,12 @@ int repo_read_index(struct repository *repo)
if (!repo->index)
repo->index = xcalloc(1, sizeof(*repo->index));
+ /* 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");
+
return read_index_from(repo->index, repo->index_file, repo->gitdir);
}