diff options
| author | Vicent Martà <vicent@github.com> | 2013-11-05 06:55:16 -0800 |
|---|---|---|
| committer | Vicent Martà <vicent@github.com> | 2013-11-05 06:55:16 -0800 |
| commit | c82f7f8e9954bb74b9f7eabd0e1b1ce99110dbbf (patch) | |
| tree | dc063e03e359c10553486b82e24d560fe51e818e /include/git2 | |
| parent | ffd040532a1f3c7f4e268be682bb91fe724693be (diff) | |
| parent | 8ec889a45fded32bf8508f99d77ea666d0aacdd5 (diff) | |
| download | libgit2-c82f7f8e9954bb74b9f7eabd0e1b1ce99110dbbf.tar.gz | |
Merge pull request #1938 from libgit2/cmn/branch-iterator
branch: move from foreach to an iterator
Diffstat (limited to 'include/git2')
| -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. |
