Signed-off-by: Brandon Williams <[email protected]>
---
repo.c | 17 +++++++++++++++++
repo.h | 3 +++
2 files changed, 20 insertions(+)
diff --git a/repo.c b/repo.c
index c67cad5a2..c79d29534 100644
--- a/repo.c
+++ b/repo.c
@@ -104,6 +104,17 @@ void repo_read_config(struct repo *repo)
git_config_with_options(config_set_callback, repo->config, NULL, &opts);
}
+void repo_read_index(struct repo *repo)
+{
+ if (!repo->index)
+ repo->index = xcalloc(1, sizeof(struct index_state));
+ else
+ discard_index(repo->index);
+
+ if (read_index_from(repo->index, repo->index_file) < 0)
+ die(_("failure reading index"));
+}
+
int repo_init(struct repo *repo, const char *gitdir)
{
int error = 0;
@@ -149,4 +160,10 @@ void repo_clear(struct repo *repo)
free(repo->config);
repo->config = NULL;
}
+
+ if (repo->index) {
+ discard_index(repo->index);
+ free(repo->index);
+ repo->index = NULL;
+ }
}
diff --git a/repo.h b/repo.h
index 284452832..756cda9e1 100644
--- a/repo.h
+++ b/repo.h
@@ -2,6 +2,7 @@
#define REPO_H
struct config_set;
+struct index_state;
struct repo {
/* Environment */
@@ -20,6 +21,7 @@ struct repo {
* ~/.gitconfig, XDG config file and the global /etc/gitconfig)
*/
struct config_set *config;
+ struct index_state *index;
/* Configurations */
unsigned ignore_env:1;
@@ -32,6 +34,7 @@ extern struct repo the_repository;
extern void repo_set_gitdir(struct repo *repo, const char *path);
extern void repo_set_worktree(struct repo *repo, const char *path);
extern void repo_read_config(struct repo *repo);
+extern void repo_read_index(struct repo *repo);
extern int repo_init(struct repo *repo, const char *path);
extern void repo_clear(struct repo *repo);
--
2.13.0.506.g27d5fe0cd-goog