repository: add index_state to struct repo

Signed-off-by: Brandon Williams <bmwill@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Brandon Williams committed Jun 22, 2017 at 11:43 UTC 639e30b5b2214c68c042215a279ac1fbb372d73d
2 files changed +25
repository.c
+16
@@ -163,4 +163,20 @@ void repo_clear(struct repository *repo)
163 free(repo->config);
164 repo->config = NULL;
165 }
166 +
167 + if (repo->index) {
168 + discard_index(repo->index);
169 + free(repo->index);
170 + repo->index = NULL;
171 + }
172 +}
173 +
174 +int repo_read_index(struct repository *repo)
175 +{
176 + if (!repo->index)
177 + repo->index = xcalloc(1, sizeof(*repo->index));
178 + else
179 + discard_index(repo->index);
180 +
181 + return read_index_from(repo->index, repo->index_file);
182 }
repository.h
+9
@@ -2,6 +2,7 @@
2 #define REPOSITORY_H
3
4 struct config_set;
5 +struct index_state;
6
7 struct repository {
8 /* Environment */
@@ -49,6 +50,12 @@ struct repository {
50 */
51 struct config_set *config;
52
53 + /*
54 + * Repository's in-memory index.
55 + * 'repo_read_index()' can be used to populate 'index'.
56 + */
57 + struct index_state *index;
58 +
59 /* Configurations */
60 /*
61 * Bit used during initialization to indicate if repository state (like
@@ -71,4 +78,6 @@ extern void repo_set_worktree(struct repository *repo, const char *path);
78 extern int repo_init(struct repository *repo, const char *gitdir, const char *worktree);
79 extern void repo_clear(struct repository *repo);
80
81 +extern int repo_read_index(struct repository *repo);
82 +
83 #endif /* REPOSITORY_H */