summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/git/index.h22
-rw-r--r--src/index.c16
2 files changed, 31 insertions, 7 deletions
diff --git a/src/git/index.h b/src/git/index.h
index ee410865d..bdfb7e192 100644
--- a/src/git/index.h
+++ b/src/git/index.h
@@ -108,14 +108,32 @@ GIT_EXTERN(int) git_index_write(git_index *index);
GIT_EXTERN(int) git_index_find(git_index *index, const char *path);
/**
- * Add a new empty entry to the index.
+ * Add a new empty entry to the index with a given path.
*
* @param index an existing index object
* @param path filename pointed to by the entry
* @param stage stage for the entry
* @return 0 on success, otherwise an error code
*/
-GIT_EXTERN(int) git_index_add(git_index *index, const char *path, int stage);
+GIT_EXTERN(int) git_index_add_bypath(git_index *index, const char *path, int stage);
+
+/**
+ * Remove an entry from the index
+ *
+ * @param index an existing index object
+ * @param position position of the entry to remove
+ * @return 0 on success, otherwise an error code
+ */
+GIT_EXTERN(int) git_index_remove(git_index *index, int position);
+
+/**
+ * Add a new entry to the index
+ *
+ * @param index an existing index object
+ * @param source_entry new entry object
+ * @return 0 on success, otherwise an error code
+ */
+GIT_EXTERN(int) git_index_add(git_index *index, const git_index_entry *source_entry);
/**
* Get a pointer to one of the entries in the index
diff --git a/src/index.c b/src/index.c
index 71481cc2d..77de0a8e2 100644
--- a/src/index.c
+++ b/src/index.c
@@ -223,10 +223,11 @@ int git_index_write(git_index *index)
git_index_entry *git_index_get(git_index *index, int n)
{
+ assert(index);
return (n >= 0 && (unsigned int)n < index->entry_count) ? &index->entries[n] : NULL;
}
-int git_index_add(git_index *index, const char *filename, int stage)
+int git_index_add_bypath(git_index *index, const char *filename, int stage)
{
git_index_entry entry;
size_t path_length;
@@ -247,7 +248,7 @@ int git_index_add(git_index *index, const char *filename, int stage)
entry.path = git__strdup(filename);
- return git_index__append(index, &entry);
+ return git_index_add(index, &entry);
}
void git_index__sort(git_index *index)
@@ -274,7 +275,7 @@ void git_index__sort(git_index *index)
index->sorted = 1;
}
-int git_index__append(git_index *index, const git_index_entry *source_entry)
+int git_index_add(git_index *index, const git_index_entry *source_entry)
{
git_index_entry *offset;
@@ -303,18 +304,23 @@ int git_index__append(git_index *index, const git_index_entry *source_entry)
return GIT_SUCCESS;
}
-int git_index__remove_pos(git_index *index, unsigned int position)
+int git_index_remove(git_index *index, int position)
{
git_index_entry *offset;
size_t copy_size;
+ assert(index);
+
+ if (position < 0 || (unsigned int)position > index->entry_count)
+ return GIT_ENOTFOUND;
+
offset = &index->entries[position];
index->entry_count--;
copy_size = (index->entry_count - position) * sizeof(git_index_entry);
memcpy(offset, offset + sizeof(git_index_entry), copy_size);
- return 0;
+ return GIT_SUCCESS;
}
int git_index_find(git_index *index, const char *path)