summaryrefslogtreecommitdiff
path: root/branch.go
diff options
context:
space:
mode:
authorCarlos Martín Nieto <[email protected]>2015-03-15 01:09:11 +0100
committerCarlos Martín Nieto <[email protected]>2015-03-15 01:09:11 +0100
commit137c4fc3c838a803dddeb2855e726fc30713fdea (patch)
treecc2bbc371b93ed92d4b2f3a1abc2a62d6d578277 /branch.go
parent063bed33a90e7d5b1ece1b6bd1aba04a69a78a28 (diff)
parent76d600f7b3633f78e5f1433c16eba4eddfdad3e0 (diff)
Merge branch 'master' into v22
Diffstat (limited to 'branch.go')
-rw-r--r--branch.go29
1 files changed, 22 insertions, 7 deletions
diff --git a/branch.go b/branch.go
index bb231c3..22b767e 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
@@ -87,7 +96,10 @@ func (repo *Repository) CreateBranch(branchName string, target *Commit, force bo
cBranchName := C.CString(branchName)
cForce := cbool(force)
- cSignature := signature.toC()
+ cSignature, err := signature.toC()
+ if err != nil {
+ return nil, err
+ }
defer C.git_signature_free(cSignature)
var cmsg *C.char
@@ -124,7 +136,10 @@ func (b *Branch) Move(newBranchName string, force bool, signature *Signature, ms
cNewBranchName := C.CString(newBranchName)
cForce := cbool(force)
- cSignature := signature.toC()
+ cSignature, err := signature.toC()
+ if err != nil {
+ return nil, err
+ }
defer C.git_signature_free(cSignature)
var cmsg *C.char