summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@github.com>2016-03-18 12:59:35 -0400
committerEdward Thomson <ethomson@github.com>2016-03-24 15:59:48 -0400
commit82a1aab647c9a587e0b8959719a6ea507a68ea31 (patch)
tree05b3022bbaf3a1b9a1df4f318851978a5528a7c9
parentde034cd23929734dde37e53ce5eba4563b9c914c (diff)
downloadlibgit2-82a1aab647c9a587e0b8959719a6ea507a68ea31.tar.gz
iterator: move the index into the iterator itself
-rw-r--r--src/iterator.c41
-rw-r--r--src/iterator.h10
2 files changed, 15 insertions, 36 deletions
diff --git a/src/iterator.c b/src/iterator.c
index 88b7ed28a..188f0cf56 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 85444f11f..460f9475a 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