index: Add `git_index_new`
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
diff --git a/include/git2/index.h b/include/git2/index.h
index 2a0b001..bca9791 100644
--- a/include/git2/index.h
+++ b/include/git2/index.h
@@ -126,6 +126,19 @@ enum {
GIT_EXTERN(int) git_index_open(git_index **index, const char *index_path);
/**
+ * Create an in-memory index object.
+ *
+ * This index object cannot be read/written to the filesystem,
+ * but may be used to perform in-memory index operations.
+ *
+ * The index must be freed once it's no longer in use.
+ *
+ * @param index the pointer for the new index
+ * @return 0 or an error code
+ */
+GIT_EXTERN(int) git_index_new(git_index **index);
+
+/**
* Free an existing index object.
*
* @param index an existing index object
diff --git a/src/index.c b/src/index.c
index ffa63f6..cb83015 100644
--- a/src/index.c
+++ b/src/index.c
@@ -287,6 +287,11 @@ int git_index_open(git_index **index_out, const char *index_path)
return (index_path != NULL) ? git_index_read(index) : 0;
}
+int git_index_new(git_index **out)
+{
+ return git_index_open(out, NULL);
+}
+
static void index_free(git_index *index)
{
git_index_entry *e;