diff options
author | Russell Belfer <arrbee@arrbee.com> | 2012-02-21 14:46:24 -0800 |
---|---|---|
committer | Russell Belfer <arrbee@arrbee.com> | 2012-02-21 14:46:24 -0800 |
commit | b6c93aef4276051f9c4536ecbed48f4cd093bd1b (patch) | |
tree | a15962c672890c0c8cc021dafa7d29487f81c75a /src/vector.c | |
parent | 9c94a356cc61daa85e17c6342db9b3d62f788802 (diff) | |
download | libgit2-b6c93aef4276051f9c4536ecbed48f4cd093bd1b.tar.gz |
Uniform iterators for trees, index, and workdir
This create a new git_iterator type of object that provides a
uniform interface for iterating over the index, an arbitrary
tree, or the working directory of a repository.
As part of this, git ignore support was extended to support
push and pop of directory-based ignore files as the working
directory is being traversed (so the array of ignores does
not have to be recreated at each directory during traveral).
There are a number of other small utility functions in buffer,
path, vector, and fileops that are included in this patch
that made the iterator implementation cleaner.
Diffstat (limited to 'src/vector.c')
-rw-r--r-- | src/vector.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/vector.c b/src/vector.c index ba8499d4e..49909bbad 100644 --- a/src/vector.c +++ b/src/vector.c @@ -25,6 +25,23 @@ static int resize_vector(git_vector *v) return GIT_SUCCESS; } +int git_vector_alloc( + git_vector **vptr, unsigned int initial_size, git_vector_cmp cmp) +{ + int error; + git_vector *v = git__malloc(sizeof(git_vector)); + if (!v) { + *vptr = NULL; + return GIT_ENOMEM; + } + + if ((error = git_vector_init(v, initial_size, cmp)) < GIT_SUCCESS) { + git__free(v); + v = NULL; + } + *vptr = v; + return error; +} void git_vector_free(git_vector *v) { @@ -188,6 +205,21 @@ int git_vector_remove(git_vector *v, unsigned int idx) return GIT_SUCCESS; } +int git_vector_pop(git_vector *v, void **element) +{ + assert(v); + + if (v->length == 0) + return git__throw(GIT_ENOTFOUND, "Can't remove element from empty list"); + + if (element != NULL) + *element = v->contents[v->length - 1]; + + v->length--; + + return GIT_SUCCESS; +} + void git_vector_uniq(git_vector *v) { git_vector_cmp cmp; |