summaryrefslogtreecommitdiff
path: root/src/index.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/index.c')
-rw-r--r--src/index.c39
1 files changed, 23 insertions, 16 deletions
diff --git a/src/index.c b/src/index.c
index 06fa95c7b..dd33db92a 100644
--- a/src/index.c
+++ b/src/index.c
@@ -348,6 +348,7 @@ static int index_insert(git_index *index, const git_index_entry *source_entry, i
git_index_entry *entry;
size_t path_length;
int position;
+ git_index_entry **entry_array;
assert(index && source_entry);
@@ -375,27 +376,28 @@ static int index_insert(git_index *index, const git_index_entry *source_entry, i
else
entry->flags |= GIT_IDXENTRY_NAMEMASK;;
+ /*
+ * replacing is not requested: just insert entry at the end;
+ * the index is no longer sorted
+ */
+ if (!replace)
+ return git_vector_insert(&index->entries, entry);
/* look if an entry with this path already exists */
position = git_index_find(index, source_entry->path);
- /* if no entry exists and replace is not set,
- * add the entry at the end;
- * the index is no longer sorted */
- if (!replace || position == GIT_ENOTFOUND) {
- if (git_vector_insert(&index->entries, entry) < GIT_SUCCESS)
- return GIT_ENOMEM;
+ /*
+ * if no entry exists add the entry at the end;
+ * the index is no longer sorted
+ */
+ if (position == GIT_ENOTFOUND)
+ return git_vector_insert(&index->entries, entry);
- /* if a previous entry exists and replace is set,
- * replace it */
- } else {
- git_index_entry **entry_array = (git_index_entry **)index->entries.contents;
-
- free((char *)entry_array[position]->path);
- free(entry_array[position]);
-
- entry_array[position] = entry;
- }
+ /* exists, replace it */
+ entry_array = (git_index_entry **) index->entries.contents;
+ free((char *)entry_array[position]->path);
+ free(entry_array[position]);
+ entry_array[position] = entry;
return GIT_SUCCESS;
}
@@ -485,6 +487,11 @@ int git_index_find(git_index *index, const char *path)
return git_vector_bsearch2(&index->entries, index_srch, path);
}
+void git_index_uniq(git_index *index)
+{
+ git_vector_uniq(&index->entries);
+}
+
const git_index_entry_unmerged *git_index_get_unmerged_bypath(git_index *index, const char *path)
{
int pos;