Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2012-12-28 10:25:52 +0400
committerRussell Belfer <rb@github.com>2012-12-28 10:25:52 +0400
commitf616a36bdd9b1a0f26f399414bbccb434595edff (patch)
tree43094256b9615370e3a7945932601c0671117933 /src/iterator.h
parent83261a449f76147c1ebb3ebe592821f7d69bb6f6 (diff)
Make spoolandsort a pushable iterator behavior
An earlier change to `git_diff_from_iterators` introduced a memory leak where the allocated spoolandsort iterator was not returned to the caller and thus not freed. One proposal changes all iterator APIs to use git_iterator** so we can reallocate the iterator at will, but that seems unexpected. This commit makes it so that an iterator can be changed in place. The callbacks are isolated in a separate structure and a pointer to that structure can be reassigned by the spoolandsort extension. This means that spoolandsort doesn't create a new iterator; it just allocates a new block of callbacks (along with space for its own extra data) and swaps that into the iterator. Additionally, since spoolandsort is only needed to switch the case sensitivity of an iterator, this simplifies the API to only take the ignore_case boolean and to be a no-op if the iterator already matches the requested case sensitivity.
Diffstat (limited to 'src/iterator.h')
-rw-r--r--src/iterator.h46
1 files changed, 22 insertions, 24 deletions
diff --git a/src/iterator.h b/src/iterator.h
index 9fe684412..8bcb6fb0c 100644
--- a/src/iterator.h
+++ b/src/iterator.h
@@ -26,19 +26,22 @@ typedef enum {
GIT_ITERATOR_SPOOLANDSORT = 4
} git_iterator_type_t;
-struct git_iterator {
- git_iterator_type_t type;
- git_repository *repo;
- char *start;
- char *end;
- bool ignore_case;
-
+typedef struct {
int (*current)(git_iterator *, const git_index_entry **);
int (*at_end)(git_iterator *);
int (*advance)(git_iterator *, const git_index_entry **);
int (*seek)(git_iterator *, const char *prefix);
int (*reset)(git_iterator *, const char *start, const char *end);
void (*free)(git_iterator *);
+} git_iterator_callbacks;
+
+struct git_iterator {
+ git_iterator_type_t type;
+ git_iterator_callbacks *cb;
+ git_repository *repo;
+ char *start;
+ char *end;
+ bool ignore_case;
};
extern int git_iterator_for_nothing(git_iterator **iter);
@@ -82,18 +85,13 @@ GIT_INLINE(int) git_iterator_for_workdir(
return git_iterator_for_workdir_range(iter, repo, NULL, NULL);
}
-extern int git_iterator_spoolandsort_range(
- git_iterator **iter, git_iterator *towrap,
- git_vector_cmp comparer, bool ignore_case,
- const char *start, const char *end);
+/* Spool all iterator values, resort with alternative ignore_case value
+ * and replace callbacks with spoolandsort alternates.
+ */
+extern int git_iterator_spoolandsort_push(git_iterator *iter, bool ignore_case);
-GIT_INLINE(int) git_iterator_spoolandsort(
- git_iterator **iter, git_iterator *towrap,
- git_vector_cmp comparer, bool ignore_case)
-{
- return git_iterator_spoolandsort_range(
- iter, towrap, comparer, ignore_case, NULL, NULL);
-}
+/* Restore original callbacks - not required in most circumstances */
+extern void git_iterator_spoolandsort_pop(git_iterator *iter);
/* Entry is not guaranteed to be fully populated. For a tree iterator,
* we will only populate the mode, oid and path, for example. For a workdir
@@ -106,30 +104,30 @@ GIT_INLINE(int) git_iterator_spoolandsort(
GIT_INLINE(int) git_iterator_current(
git_iterator *iter, const git_index_entry **entry)
{
- return iter->current(iter, entry);
+ return iter->cb->current(iter, entry);
}
GIT_INLINE(int) git_iterator_at_end(git_iterator *iter)
{
- return iter->at_end(iter);
+ return iter->cb->at_end(iter);
}
GIT_INLINE(int) git_iterator_advance(
git_iterator *iter, const git_index_entry **entry)
{
- return iter->advance(iter, entry);
+ return iter->cb->advance(iter, entry);
}
GIT_INLINE(int) git_iterator_seek(
git_iterator *iter, const char *prefix)
{
- return iter->seek(iter, prefix);
+ return iter->cb->seek(iter, prefix);
}
GIT_INLINE(int) git_iterator_reset(
git_iterator *iter, const char *start, const char *end)
{
- return iter->reset(iter, start, end);
+ return iter->cb->reset(iter, start, end);
}
GIT_INLINE(void) git_iterator_free(git_iterator *iter)
@@ -137,7 +135,7 @@ GIT_INLINE(void) git_iterator_free(git_iterator *iter)
if (iter == NULL)
return;
- iter->free(iter);
+ iter->cb->free(iter);
git__free(iter->start);
git__free(iter->end);