diff options
author | Carlos MartÃn Nieto <cmn@dwim.me> | 2013-11-02 14:07:02 +0100 |
---|---|---|
committer | Vicent Marti <tanoku@gmail.com> | 2013-11-05 14:58:16 +0100 |
commit | 8ec889a45fded32bf8508f99d77ea666d0aacdd5 (patch) | |
tree | e78e392f1c3d3f05cd1620a6cc3ffbe5c87f158b /include/git2/branch.h | |
parent | b7fbfbb21f4248bf4103a2c13479bf65ba175f36 (diff) | |
download | libgit2-8ec889a45fded32bf8508f99d77ea666d0aacdd5.tar.gz |
branch: move from foreach to an iterator
Create a git_branch_iterator type which is equivalent to the foreach but
lets us write loops instead of callbacks.
Since the introduction of git_reference_shorthand(), the added value of
passing the name is reduced.
Diffstat (limited to 'include/git2/branch.h')
-rw-r--r-- | include/git2/branch.h | 40 |
1 files changed, 24 insertions, 16 deletions
diff --git a/include/git2/branch.h b/include/git2/branch.h index de414e9b0..b5e7d60ea 100644 --- a/include/git2/branch.h +++ b/include/git2/branch.h @@ -66,33 +66,41 @@ GIT_EXTERN(int) git_branch_create( */ GIT_EXTERN(int) git_branch_delete(git_reference *branch); -typedef int (*git_branch_foreach_cb)( - const char *branch_name, - git_branch_t branch_type, - void *payload); +/** Iterator type for branches */ +typedef struct git_branch_iterator git_branch_iterator; /** - * Loop over all the branches and issue a callback for each one. - * - * If the callback returns a non-zero value, this will stop looping. + * Create an iterator which loops over the requested branches. * + * @param out the iterator * @param repo Repository where to find the branches. - * * @param list_flags Filtering flags for the branch * listing. Valid values are GIT_BRANCH_LOCAL, GIT_BRANCH_REMOTE * or a combination of the two. * - * @param branch_cb Callback to invoke per found branch. + * @return 0 on success or an error code + */ +GIT_EXTERN(int) git_branch_iterator_new( + git_branch_iterator **out, + git_repository *repo, + unsigned int list_flags); + +/** + * Retrieve the next branch from the iterator * - * @param payload Extra parameter to callback function. + * @param out the reference + * @param out_type the type of branch (local or remote-tracking) + * @param iter the branch iterator + * @return 0 on success, GIT_ITEROVER if there are no more branches or an error code. + */ +GIT_EXTERN(int) git_branch_next(git_reference **out, unsigned int *out_type, git_branch_iterator *iter); + +/** + * Free a branch iterator * - * @return 0 on success, GIT_EUSER on non-zero callback, or error code + * @param iter the iterator to free */ -GIT_EXTERN(int) git_branch_foreach( - git_repository *repo, - unsigned int list_flags, - git_branch_foreach_cb branch_cb, - void *payload); +GIT_EXTERN(void) git_branch_iterator_free(git_branch_iterator *iter); /** * Move/rename an existing local branch reference. |