summaryrefslogtreecommitdiff
path: root/branch.go
diff options
context:
space:
mode:
authorDavid Calavera <[email protected]>2015-02-18 15:32:50 +0530
committerCarlos Martín Nieto <[email protected]>2015-02-19 11:44:56 +0100
commit755721e68453c5d6de0681789dbe3307744fc9c4 (patch)
treefd72784084bb7a60982569af51e891195855400c /branch.go
parent94b1f7d07dd3786de15f44e3faf2a3e4d680a0b8 (diff)
Add BranchIterator#ForEach.
This abstracts the branch iteration from the user.
Diffstat (limited to 'branch.go')
-rw-r--r--branch.go19
1 files changed, 14 insertions, 5 deletions
diff --git a/branch.go b/branch.go
index bb231c3..54b01fb 100644
--- a/branch.go
+++ b/branch.go
@@ -30,10 +30,7 @@ type BranchIterator struct {
repo *Repository
}
-type BranchInfo struct {
- Branch *Branch
- Type BranchType
-}
+type BranchIteratorFunc func(*Branch, BranchType) error
func newBranchIteratorFromC(repo *Repository, ptr *C.git_branch_iterator) *BranchIterator {
i := &BranchIterator{repo: repo, ptr: ptr}
@@ -65,8 +62,20 @@ func (i *BranchIterator) Free() {
C.git_branch_iterator_free(i.ptr)
}
-func (repo *Repository) NewBranchIterator(flags BranchType) (*BranchIterator, error) {
+func (i *BranchIterator) ForEach(f BranchIteratorFunc) error {
+ b, t, err := i.Next()
+
+ for err == nil {
+ err = f(b, t)
+ if err == nil {
+ b, t, err = i.Next()
+ }
+ }
+ return err
+}
+
+func (repo *Repository) NewBranchIterator(flags BranchType) (*BranchIterator, error) {
refType := C.git_branch_t(flags)
var ptr *C.git_branch_iterator