repository: add index_state to struct repo
[git/git.git] / repository.c
index 686a964..6f6f4d9 100644 (file)
@@ -163,4 +163,20 @@ void repo_clear(struct repository *repo)
                free(repo->config);
                repo->config = NULL;
        }
+
+       if (repo->index) {
+               discard_index(repo->index);
+               free(repo->index);
+               repo->index = NULL;
+       }
+}
+
+int repo_read_index(struct repository *repo)
+{
+       if (!repo->index)
+               repo->index = xcalloc(1, sizeof(*repo->index));
+       else
+               discard_index(repo->index);
+
+       return read_index_from(repo->index, repo->index_file);
 }