summaryrefslogtreecommitdiff
path: root/src/index.c
diff options
context:
space:
mode:
authorVicent Marti <tanoku@gmail.com>2010-11-07 01:24:45 +0200
committerVicent Marti <tanoku@gmail.com>2010-11-07 01:24:45 +0200
commit3f43678e889a7ee77b1cd2e40727f104ea3d7ac1 (patch)
tree3040907d3c6db401458989961619ea019f09b5cb /src/index.c
parent88d035bd1502d507554f59d6c699b3759bc2b758 (diff)
downloadlibgit2-3f43678e889a7ee77b1cd2e40727f104ea3d7ac1.tar.gz
Make the Index API public
Several private methods of the Index API are now public, including the methods to remove, get and add index entries. All the methods only take an integer value for the position of the entry to get/remove. To get or remove entries based on their path names, look them up first using the git_index_find method. Signed-off-by: Vicent Marti <tanoku@gmail.com>
Diffstat (limited to 'src/index.c')
-rw-r--r--src/index.c16
1 files changed, 11 insertions, 5 deletions
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)