summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2014-02-07 11:20:36 -0800
committerRussell Belfer <rb@github.com>2014-04-17 14:43:45 -0700
commitc67fd4c9d5e1ff715df28b884d7f7f9f20fad1ec (patch)
tree831176f87c09d36816a83ef5617623fd372f5e50 /src
parentc5cacc4ec2c13e93164b8e3013b0d18c8c6d820c (diff)
downloadlibgit2-c67fd4c9d5e1ff715df28b884d7f7f9f20fad1ec.tar.gz
Some vector utility tweaks
This is just laying some groundwork for internal index changes that I'm working on.
Diffstat (limited to 'src')
-rw-r--r--src/checkout.c8
-rw-r--r--src/index.c7
-rw-r--r--src/merge.c6
-rw-r--r--src/vector.c21
-rw-r--r--src/vector.h8
5 files changed, 41 insertions, 9 deletions
diff --git a/src/checkout.c b/src/checkout.c
index 141fc1331..f9bc5e9d8 100644
--- a/src/checkout.c
+++ b/src/checkout.c
@@ -653,10 +653,13 @@ static int checkout_conflictdata_cmp(const void *a, const void *b)
return diff;
}
-int checkout_conflictdata_empty(const git_vector *conflicts, size_t idx)
+int checkout_conflictdata_empty(
+ const git_vector *conflicts, size_t idx, void *payload)
{
checkout_conflictdata *conflict;
+ GIT_UNUSED(payload);
+
if ((conflict = git_vector_get(conflicts, idx)) == NULL)
return -1;
@@ -954,7 +957,8 @@ static int checkout_conflicts_coalesce_renames(
ancestor_conflict->one_to_two = 1;
}
- git_vector_remove_matching(&data->conflicts, checkout_conflictdata_empty);
+ git_vector_remove_matching(
+ &data->conflicts, checkout_conflictdata_empty, NULL);
done:
return error;
diff --git a/src/index.c b/src/index.c
index b0b5eae9d..08c4b79b6 100644
--- a/src/index.c
+++ b/src/index.c
@@ -1228,10 +1228,13 @@ int git_index_conflict_remove(git_index *index, const char *path)
return 0;
}
-static int index_conflicts_match(const git_vector *v, size_t idx)
+static int index_conflicts_match(const git_vector *v, size_t idx, void *p)
{
+ git_index *index = p;
git_index_entry *entry = git_vector_get(v, idx);
+ GIT_UNUSED(index);
+
if (GIT_IDXENTRY_STAGE(entry) > 0) {
index_entry_free(entry);
return 1;
@@ -1243,7 +1246,7 @@ static int index_conflicts_match(const git_vector *v, size_t idx)
void git_index_conflict_cleanup(git_index *index)
{
assert(index);
- git_vector_remove_matching(&index->entries, index_conflicts_match);
+ git_vector_remove_matching(&index->entries, index_conflicts_match, index);
}
int git_index_has_conflicts(const git_index *index)
diff --git a/src/merge.c b/src/merge.c
index 10c19b5c5..9c4a07b58 100644
--- a/src/merge.c
+++ b/src/merge.c
@@ -995,10 +995,12 @@ static void merge_diff_list_coalesce_renames(
}
}
-static int merge_diff_empty(const git_vector *conflicts, size_t idx)
+static int merge_diff_empty(const git_vector *conflicts, size_t idx, void *p)
{
git_merge_diff *conflict = conflicts->contents[idx];
+ GIT_UNUSED(p);
+
return (!GIT_MERGE_INDEX_ENTRY_EXISTS(conflict->ancestor_entry) &&
!GIT_MERGE_INDEX_ENTRY_EXISTS(conflict->our_entry) &&
!GIT_MERGE_INDEX_ENTRY_EXISTS(conflict->their_entry));
@@ -1079,7 +1081,7 @@ int git_merge_diff_list__find_renames(
merge_diff_list_coalesce_renames(diff_list, similarity_ours, similarity_theirs, opts);
/* And remove any entries that were merged and are now empty. */
- git_vector_remove_matching(&diff_list->conflicts, merge_diff_empty);
+ git_vector_remove_matching(&diff_list->conflicts, merge_diff_empty, NULL);
done:
if (cache != NULL) {
diff --git a/src/vector.c b/src/vector.c
index 37ea07f0b..9f7eed5a3 100644
--- a/src/vector.c
+++ b/src/vector.c
@@ -276,14 +276,16 @@ void git_vector_uniq(git_vector *v, void (*git_free_cb)(void *))
}
void git_vector_remove_matching(
- git_vector *v, int (*match)(const git_vector *v, size_t idx))
+ git_vector *v,
+ int (*match)(const git_vector *v, size_t idx, void *payload),
+ void *payload)
{
size_t i, j;
for (i = 0, j = 0; j < v->length; ++j) {
v->contents[i] = v->contents[j];
- if (!match(v, i))
+ if (!match(v, i, payload))
i++;
}
@@ -339,3 +341,18 @@ int git_vector_set(void **old, git_vector *v, size_t position, void *value)
return 0;
}
+
+int git_vector_verify_sorted(const git_vector *v)
+{
+ size_t i;
+
+ if (!git_vector_is_sorted(v))
+ return -1;
+
+ for (i = 1; i < v->length; ++i) {
+ if (v->_cmp(v->contents[i - 1], v->contents[i]) > 0)
+ return -1;
+ }
+
+ return 0;
+}
diff --git a/src/vector.h b/src/vector.h
index 682b6ad27..aac46c4b3 100644
--- a/src/vector.h
+++ b/src/vector.h
@@ -85,8 +85,11 @@ int git_vector_insert_sorted(git_vector *v, void *element,
int git_vector_remove(git_vector *v, size_t idx);
void git_vector_pop(git_vector *v);
void git_vector_uniq(git_vector *v, void (*git_free_cb)(void *));
+
void git_vector_remove_matching(
- git_vector *v, int (*match)(const git_vector *v, size_t idx));
+ git_vector *v,
+ int (*match)(const git_vector *v, size_t idx, void *payload),
+ void *payload);
int git_vector_resize_to(git_vector *v, size_t new_length);
int git_vector_set(void **old, git_vector *v, size_t position, void *value);
@@ -108,4 +111,7 @@ GIT_INLINE(void) git_vector_set_cmp(git_vector *v, git_vector_cmp cmp)
}
}
+/* Just use this in tests, not for realz. returns -1 if not sorted */
+int git_vector_verify_sorted(const git_vector *v);
+
#endif