From 27d123f631abfaaf8079ba4d3270744a840b579b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Sat, 8 Jul 2017 18:24:41 +0200 Subject: [PATCH 1/2] Deduplicate Makefile static target and add thread locking check It turns out we had been running CI without performing the thread locking check. --- Makefile | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Makefile b/Makefile index b2399f8..cf00cef 100644 --- a/Makefile +++ b/Makefile @@ -10,12 +10,9 @@ install: build-libgit2 build-libgit2: ./script/build-libgit2-static.sh -static: build-libgit2 - go run script/check-MakeGitError-thread-lock.go - go test --tags "static" ./... - install-static: build-libgit2 go install --tags "static" ./... test-static: build-libgit2 + go run script/check-MakeGitError-thread-lock.go go test --tags "static" ./... From b98b0e764066066fd9a5224468c15b50f6627fa9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Sat, 8 Jul 2017 20:58:08 +0200 Subject: [PATCH 2/2] rebase: correct the return values for CurrentOperationIndex We were incorectly reporting `C.GIT_REBASE_NO_OPERATION` as an error code when it is none. We should instead return it as the value. The compiler doesn't seem to actually look at the sizes so instead we must recreate the value ourselves with `^uint(0)`. The error return is kept for API compatibility but should go away eventually. --- rebase.go | 22 ++++++++++++++++------ rebase_test.go | 2 +- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/rebase.go b/rebase.go index 390b924..1f1324d 100644 --- a/rebase.go +++ b/rebase.go @@ -5,6 +5,7 @@ package git */ import "C" import ( + "errors" "runtime" "unsafe" ) @@ -25,6 +26,12 @@ const ( RebaseOperationExec RebaseOperationType = C.GIT_REBASE_OPERATION_EXEC ) +// Special value indicating that there is no currently active operation +var RebaseNoOperation uint = ^uint(0) + +// Error returned if there is no current rebase operation +var ErrRebaseNoOperation = errors.New("o current rebase operation") + // RebaseOperation describes a single instruction/operation to be performed during the rebase. type RebaseOperation struct { Type RebaseOperationType @@ -154,18 +161,21 @@ func (rebase *Rebase) OperationAt(index uint) *RebaseOperation { return newRebaseOperationFromC(operation) } -// CurrentOperationIndex gets the index of the rebase operation that is currently being applied. -// Returns an error if no rebase operation is currently applied. +// CurrentOperationIndex gets the index of the rebase operation that is +// currently being applied. There is also an error returned for API +// compatibility. func (rebase *Rebase) CurrentOperationIndex() (uint, error) { runtime.LockOSThread() defer runtime.UnlockOSThread() - operationIndex := int(C.git_rebase_operation_current(rebase.ptr)) - if operationIndex == C.GIT_REBASE_NO_OPERATION { - return 0, MakeGitError(C.GIT_REBASE_NO_OPERATION) + var err error + operationIndex := uint(C.git_rebase_operation_current(rebase.ptr)) + runtime.KeepAlive(rebase) + if operationIndex == RebaseNoOperation { + err = ErrRebaseNoOperation } - return uint(operationIndex), nil + return uint(operationIndex), err } // OperationCount gets the count of rebase operations that are to be applied. diff --git a/rebase_test.go b/rebase_test.go index fb88a4e..ef4f920 100644 --- a/rebase_test.go +++ b/rebase_test.go @@ -182,7 +182,7 @@ func performRebaseOnto(repo *Repository, branch string) (*Rebase, error) { // Check no operation has been started yet rebaseOperationIndex, err := rebase.CurrentOperationIndex() - if err == nil { + if rebaseOperationIndex != RebaseNoOperation && err != ErrRebaseNoOperation { return nil, errors.New("No operation should have been started yet") }