iterator: move the index into the iterator itself
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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
diff --git a/src/iterator.c b/src/iterator.c
index 88b7ed2..188f0cf 100644
--- a/src/iterator.c
+++ b/src/iterator.c
@@ -1321,7 +1321,7 @@ static int is_submodule(
}
}
- if (!is_submodule && iter->index) {
+ if (!is_submodule && iter->base.index) {
size_t pos;
error = git_index_snapshot_find(&pos,
@@ -2090,7 +2090,7 @@ static int iterator_for_filesystem(
if (tree && (error = git_tree_dup(&iter->tree, tree)) < 0)
goto on_error;
- if ((iter->index = index) != NULL &&
+ if ((iter->base.index = index) != NULL &&
(error = git_index_snapshot_new(&iter->index_snapshot, index)) < 0)
goto on_error;
@@ -2156,7 +2156,6 @@ int git_iterator_for_workdir_ext(
typedef struct {
git_iterator base;
git_iterator_callbacks cb;
- git_index *index;
git_vector entries;
git_vector_cmp entry_srch;
size_t current;
@@ -2389,8 +2388,8 @@ static int index_iterator__reset_range(
static void index_iterator__free(git_iterator *self)
{
index_iterator *ii = (index_iterator *)self;
- git_index_snapshot_release(&ii->entries, ii->index);
- ii->index = NULL;
+ git_index_snapshot_release(&ii->entries, ii->base.index);
+ ii->base.index = NULL;
git_buf_free(&ii->partial);
}
@@ -2408,7 +2407,7 @@ int git_iterator_for_index(
git__free(ii);
return error;
}
- ii->index = index;
+ ii->base.index = index;
ITERATOR_BASE_INIT(ii, index, INDEX, repo);
@@ -2434,6 +2433,9 @@ int git_iterator_for_index(
}
+/* Iterator API */
+
+
void git_iterator_free(git_iterator *iter)
{
if (iter == NULL)
@@ -2450,33 +2452,6 @@ void git_iterator_free(git_iterator *iter)
git__free(iter);
}
-int git_iterator_cmp(git_iterator *iter, const char *path_prefix)
-{
- const git_index_entry *entry;
-
- /* a "done" iterator is after every prefix */
- if (git_iterator_current(&entry, iter) < 0 || entry == NULL)
- return 1;
-
- /* a NULL prefix is after any valid iterator */
- if (!path_prefix)
- return -1;
-
- return iter->prefixcomp(entry->path, path_prefix);
-}
-
-git_index *git_iterator_index(git_iterator *iter)
-{
- if (iter->type == GIT_ITERATOR_TYPE_INDEX)
- return ((index_iterator *)iter)->index;
-
- if (iter->type == GIT_ITERATOR_TYPE_FS ||
- iter->type == GIT_ITERATOR_TYPE_WORKDIR)
- return ((filesystem_iterator *)iter)->index;
-
- return NULL;
-}
-
int git_iterator_walk(
git_iterator **iterators,
size_t cnt,
diff --git a/src/iterator.h b/src/iterator.h
index 85444f1..460f947 100644
--- a/src/iterator.h
+++ b/src/iterator.h
@@ -77,7 +77,9 @@ typedef struct {
struct git_iterator {
git_iterator_type_t type;
git_iterator_callbacks *cb;
+
git_repository *repo;
+ git_index *index;
char *start;
size_t start_len;
@@ -260,6 +262,11 @@ GIT_INLINE(git_repository *) git_iterator_owner(git_iterator *iter)
return iter->repo;
}
+GIT_INLINE(git_index *) git_iterator_index(git_iterator *iter)
+{
+ return iter->index;
+}
+
GIT_INLINE(git_iterator_flag_t) git_iterator_flags(git_iterator *iter)
{
return iter->flags;
@@ -282,9 +289,6 @@ extern bool git_iterator_current_is_ignored(git_iterator *iter);
extern bool git_iterator_current_tree_is_ignored(git_iterator *iter);
-extern int git_iterator_cmp(
- git_iterator *iter, const char *path_prefix);
-
/**
* Get full path of the current item from a workdir iterator. This will
* return NULL for a non-workdir iterator. The git_buf is still owned by