diff options
author | Russell Belfer <rb@github.com> | 2012-05-16 01:17:39 +0400 |
---|---|---|
committer | Russell Belfer <rb@github.com> | 2012-05-16 01:34:15 +0400 |
commit | 41a82592ef56a216f96558942d717af15589071d (patch) | |
tree | 8f9c2969000d388f1091b2cd134776bee59e29c6 /src/iterator.h | |
parent | 54695f4098c75801f477f5bc229a52653484e08a (diff) |
Ranged iterators and rewritten git_status_file
The goal of this work is to rewrite git_status_file to use the
same underlying code as git_status_foreach.
This is done in 3 phases:
1. Extend iterators to allow ranged iteration with start and
end prefixes for the range of file names to be covered.
2. Improve diff so that when there is a pathspec and there is
a common non-wildcard prefix of the pathspec, it will use
ranged iterators to minimize excess iteration.
3. Rewrite git_status_file to call git_status_foreach_ext
with a pathspec that covers just the one file being checked.
Since ranged iterators underlie the status & diff implementation,
this is actually fairly efficient. The workdir iterator does
end up loading the contents of all the directories down to the
single file, which should ideally be avoided, but it is pretty
good.
Diffstat (limited to 'src/iterator.h')
-rw-r--r-- | src/iterator.h | 54 |
1 files changed, 47 insertions, 7 deletions
diff --git a/src/iterator.h b/src/iterator.h index 974c2daeb..b916a9080 100644 --- a/src/iterator.h +++ b/src/iterator.h @@ -21,23 +21,48 @@ typedef enum { struct git_iterator { git_iterator_type_t type; + char *start; + char *end; 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 *); void (*free)(git_iterator *); }; -int git_iterator_for_nothing(git_iterator **iter); +extern int git_iterator_for_nothing(git_iterator **iter); -int git_iterator_for_tree( - git_repository *repo, git_tree *tree, git_iterator **iter); +extern int git_iterator_for_tree_range( + git_iterator **iter, git_repository *repo, git_tree *tree, + const char *start, const char *end); -int git_iterator_for_index( - git_repository *repo, git_iterator **iter); +GIT_INLINE(int) git_iterator_for_tree( + git_iterator **iter, git_repository *repo, git_tree *tree) +{ + return git_iterator_for_tree_range(iter, repo, tree, NULL, NULL); +} + +extern int git_iterator_for_index_range( + git_iterator **iter, git_repository *repo, + const char *start, const char *end); + +GIT_INLINE(int) git_iterator_for_index( + git_iterator **iter, git_repository *repo) +{ + return git_iterator_for_index_range(iter, repo, NULL, NULL); +} + +extern int git_iterator_for_workdir_range( + git_iterator **iter, git_repository *repo, + const char *start, const char *end); + +GIT_INLINE(int) git_iterator_for_workdir( + git_iterator **iter, git_repository *repo) +{ + return git_iterator_for_workdir_range(iter, repo, NULL, NULL); +} -int git_iterator_for_workdir( - git_repository *repo, 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 @@ -64,6 +89,12 @@ GIT_INLINE(int) git_iterator_advance( return iter->advance(iter, entry); } +GIT_INLINE(int) git_iterator_seek( + git_iterator *iter, const char *prefix) +{ + return iter->seek(iter, prefix); +} + GIT_INLINE(int) git_iterator_reset(git_iterator *iter) { return iter->reset(iter); @@ -75,6 +106,12 @@ GIT_INLINE(void) git_iterator_free(git_iterator *iter) return; iter->free(iter); + + git__free(iter->start); + git__free(iter->end); + + memset(iter, 0, sizeof(*iter)); + git__free(iter); } @@ -108,4 +145,7 @@ extern int git_iterator_current_is_ignored(git_iterator *iter); extern int git_iterator_advance_into_directory( git_iterator *iter, const git_index_entry **entry); +extern int git_iterator_cmp( + git_iterator *iter, const char *path_prefix); + #endif |