Skip to content

Commit 1fd9ae5

Browse files
derrickstoleegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent cae70ac commit 1fd9ae5

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

cache.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ struct index_state {
328328
struct ewah_bitmap *fsmonitor_dirty;
329329
struct mem_pool *ce_mem_pool;
330330
struct progress *progress;
331+
struct repository *repo;
331332
};
332333

333334
/* Name hashing */

repository.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,12 @@ int repo_read_index(struct repository *repo)
264264
if (!repo->index)
265265
repo->index = xcalloc(1, sizeof(*repo->index));
266266

267+
/* Complete the double-reference */
268+
if (!repo->index->repo)
269+
repo->index->repo = repo;
270+
else if (repo->index->repo != repo)
271+
BUG("repo's index should point back at itself");
272+
267273
return read_index_from(repo->index, repo->index_file, repo->gitdir);
268274
}
269275

0 commit comments

Comments
 (0)