Signed-off-by: Brandon Williams <bmw...@google.com>
---
 repository.c | 16 ++++++++++++++++
 repository.h |  6 ++++++
 2 files changed, 22 insertions(+)

diff --git a/repository.c b/repository.c
index 3dcfec3b8..883e6e9e9 100644
--- a/repository.c
+++ b/repository.c
@@ -175,5 +175,21 @@ void repo_clear(struct repository *repo)
                repo->config = NULL;
        }
 
+       if (repo->index) {
+               discard_index(repo->index);
+               free(repo->index);
+               repo->index = NULL;
+       }
+
        memset(repo, 0, sizeof(*repo));
 }
+
+int repo_read_index(struct repository *repo)
+{
+       if (!repo->index)
+               repo->index = xcalloc(1, sizeof(struct index_state));
+       else
+               discard_index(repo->index);
+
+       return read_index_from(repo->index, repo->index_file);
+}
diff --git a/repository.h b/repository.h
index 379b64170..1fa65c42f 100644
--- a/repository.h
+++ b/repository.h
@@ -2,6 +2,7 @@
 #define REPOSITORY_H
 
 struct config_set;
+struct index_state;
 
 struct repository {
        /* Environment */
@@ -31,6 +32,9 @@ struct repository {
         */
        struct config_set *config;
 
+       /* Repository's in-memory index */
+       struct index_state *index;
+
        /* Configurations */
        /*
         * Bit used during initialization to indicate if repository state (like
@@ -53,4 +57,6 @@ extern void repo_set_worktree(struct repository *repo, const 
char *path);
 extern int repo_init(struct repository *repo, const char *gitdir, const char 
*worktree);
 extern void repo_clear(struct repository *repo);
 
+extern int repo_read_index(struct repository *repo);
+
 #endif /* REPOSITORY_H */
-- 
2.13.1.611.g7e3b11ae1-goog

Reply via email to