]> git.ipfire.org Git - thirdparty/git.git/commitdiff
repository: add repo reference to index_state
authorDerrick Stolee <dstolee@microsoft.com>
Sat, 23 Jan 2021 19:58:15 +0000 (19:58 +0000)
committerJunio C Hamano <gitster@pobox.com>
Sun, 24 Jan 2021 01:14:07 +0000 (17:14 -0800)
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>
cache.h
repository.c

diff --git a/cache.h b/cache.h
index 71097657489362059c225ed084ec5141aefe9384..f9c7a6038418934f94efe887ce49a03f61d17309 100644 (file)
--- a/cache.h
+++ b/cache.h
@@ -328,6 +328,7 @@ struct index_state {
        struct ewah_bitmap *fsmonitor_dirty;
        struct mem_pool *ce_mem_pool;
        struct progress *progress;
+       struct repository *repo;
 };
 
 /* Name hashing */
index a4174ddb0629cdd690142fb42c5d4182492485c4..c98298acd017b551894f838e2000b253b271202e 100644 (file)
@@ -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);
 }