aboutsummaryrefslogtreecommitdiffstats
path: root/cshared
diff options
context:
space:
mode:
authorferhat elmas <elmas.ferhat@gmail.com>2016-11-07 20:32:00 +0100
committerMáximo Cuadros <mcuadros@gmail.com>2016-11-07 20:32:00 +0100
commit7b0f65f5f5486f5e32f749826744929813734e24 (patch)
treeda3d4bbf7caf3fe5d712fb3a1df9c42fb549ee2c /cshared
parent0ff9ef2b44c53e557c78bde0fd9c29847e5f0e23 (diff)
downloadgo-git-7b0f65f5f5486f5e32f749826744929813734e24.tar.gz
gofmt simplify (#111)
Diffstat (limited to 'cshared')
-rw-r--r--cshared/auth_method_cshared.go6
-rw-r--r--cshared/blame_cshared.go2
-rw-r--r--cshared/file_cshared.go2
-rw-r--r--cshared/objects.go33
-rw-r--r--cshared/objects_cshared.go4
-rw-r--r--cshared/std_cshared.go2
-rw-r--r--cshared/tag_cshared.go8
7 files changed, 28 insertions, 29 deletions
diff --git a/cshared/auth_method_cshared.go b/cshared/auth_method_cshared.go
index afd9549..2219edb 100644
--- a/cshared/auth_method_cshared.go
+++ b/cshared/auth_method_cshared.go
@@ -87,12 +87,12 @@ func c_ParseAuthorizedKey(in []byte) (uint64, *C.char, *C.char, *C.char, int, in
pkey, comment, options, rest, err := ssh.ParseAuthorizedKey(in)
if err != nil {
return IH, nil, nil, nil, 0, ErrorCodeInternal,
- C.CString(err.Error())
+ C.CString(err.Error())
}
pkey_handle := RegisterObject(&pkey)
mopt := strings.Join(options, "\xff")
return uint64(pkey_handle), C.CString(comment), C.CString(mopt),
- C.CString(string(rest)), len(rest), ErrorCodeSuccess, nil
+ C.CString(string(rest)), len(rest), ErrorCodeSuccess, nil
}
//export c_ssh_Password_New
@@ -189,4 +189,4 @@ func c_ssh_PublicKeys_set_Signer(p uint64, v uint64) {
return
}
obj.(*gssh.PublicKeys).Signer = *signer.(*ssh.Signer)
-} \ No newline at end of file
+}
diff --git a/cshared/blame_cshared.go b/cshared/blame_cshared.go
index 939000a..8cb55e8 100644
--- a/cshared/blame_cshared.go
+++ b/cshared/blame_cshared.go
@@ -27,7 +27,6 @@ func c_Blame_get_Rev(b uint64) *C.char {
return CBytes(blame.Rev[:])
}
-
//export c_Blame_get_Lines_len
func c_Blame_get_Lines_len(b uint64) int {
obj, ok := GetObject(Handle(b))
@@ -48,4 +47,3 @@ func c_Blame_get_Lines_item(b uint64, i int) {
line := blame.Lines[i]
_ = line
}
-
diff --git a/cshared/file_cshared.go b/cshared/file_cshared.go
index 2a6678a..8191289 100644
--- a/cshared/file_cshared.go
+++ b/cshared/file_cshared.go
@@ -72,7 +72,7 @@ func c_File_Read(b uint64) (int, *C.char) {
if err != nil {
return ErrorCodeInternal, C.CString(err.Error())
}
- data, err := ioutil.ReadAll(reader)
+ data, err := ioutil.ReadAll(reader)
reader.Close()
if err != nil {
return ErrorCodeInternal, C.CString(err.Error())
diff --git a/cshared/objects.go b/cshared/objects.go
index ae3440d..d83f224 100644
--- a/cshared/objects.go
+++ b/cshared/objects.go
@@ -5,14 +5,14 @@ import (
"C"
"fmt"
"math"
- "sync"
"reflect"
+ "sync"
)
type Handle uint64
const (
- ErrorCodeSuccess = iota
+ ErrorCodeSuccess = iota
ErrorCodeNotFound = -iota
ErrorCodeInternal = -iota
)
@@ -20,6 +20,7 @@ const (
const MessageNotFound string = "object not found"
const InvalidHandle Handle = 0
const IH uint64 = uint64(InvalidHandle)
+
var counter Handle = InvalidHandle
var opMutex sync.Mutex
var registryHandle2Obj map[Handle]interface{} = map[Handle]interface{}{}
@@ -43,7 +44,7 @@ func RegisterObject(obj interface{}) Handle {
defer opMutex.Unlock()
handles, ok := registryObj2Handle[data_ptr]
if ok {
- for _, h := range(handles) {
+ for _, h := range handles {
other, ok := registryHandle2Obj[h]
if !ok {
panic("Inconsistent internal object mapping state (1)")
@@ -56,7 +57,7 @@ func RegisterObject(obj interface{}) Handle {
}
}
}
- handle := getNewHandle()
+ handle := getNewHandle()
registryHandle2Obj[handle] = obj
registryObj2Handle[data_ptr] = append(registryObj2Handle[data_ptr], handle)
if trace {
@@ -67,7 +68,7 @@ func RegisterObject(obj interface{}) Handle {
func UnregisterObject(handle Handle) int {
if trace {
- fmt.Printf("UnregisterObject %d\n", handle)
+ fmt.Printf("UnregisterObject %d\n", handle)
}
if handle == InvalidHandle {
return ErrorCodeNotFound
@@ -83,10 +84,10 @@ func UnregisterObject(handle Handle) int {
other_handles, ok := registryObj2Handle[data_ptr]
if !ok {
panic(fmt.Sprintf("Inconsistent internal object mapping state (2): %d",
- handle))
+ handle))
}
hi := -1
- for i, h := range(other_handles) {
+ for i, h := range other_handles {
if h == handle {
hi = i
break
@@ -94,12 +95,12 @@ func UnregisterObject(handle Handle) int {
}
if hi < 0 {
panic(fmt.Sprintf("Inconsistent internal object mapping state (3): %d",
- handle))
+ handle))
}
if len(other_handles) == 1 {
delete(registryObj2Handle, data_ptr)
} else {
- registryObj2Handle[data_ptr] = append(other_handles[:hi], other_handles[hi + 1:]...)
+ registryObj2Handle[data_ptr] = append(other_handles[:hi], other_handles[hi+1:]...)
}
if trace {
c_dump_objects()
@@ -125,7 +126,7 @@ func GetHandle(obj interface{}) (Handle, bool) {
if !ok {
return InvalidHandle, false
}
- for _, h := range(handles) {
+ for _, h := range handles {
candidate := registryHandle2Obj[h]
if candidate == obj {
return h, true
@@ -143,13 +144,13 @@ func CopyString(str string) string {
// https://github.com/golang/go/issues/14838
func CBytes(bytes []byte) *C.char {
ptr := C.malloc(C.size_t(len(bytes)))
- copy((*[1<<30]byte)(ptr)[:], bytes)
+ copy((*[1 << 30]byte)(ptr)[:], bytes)
return (*C.char)(ptr)
}
func SafeIsNil(v reflect.Value) bool {
- defer func() { recover() }()
- return v.IsNil()
+ defer func() { recover() }()
+ return v.IsNil()
}
//export c_dispose
@@ -165,17 +166,17 @@ func c_objects_size() int {
//export c_dump_objects
func c_dump_objects() {
fmt.Printf("handles (%d):\n", len(registryHandle2Obj))
- for h, obj := range(registryHandle2Obj) {
+ for h, obj := range registryHandle2Obj {
fmt.Printf("0x%x\t0x%x %v\n", h,
reflect.ValueOf(&obj).Elem().InterfaceData()[1], obj)
}
fmt.Println()
phs := 0
- for _, h := range(registryObj2Handle) {
+ for _, h := range registryObj2Handle {
phs += len(h)
}
fmt.Printf("pointers (%d):\n", phs)
- for ptr, h := range(registryObj2Handle) {
+ for ptr, h := range registryObj2Handle {
fmt.Printf("0x%x\t%v\n", ptr, h)
}
}
diff --git a/cshared/objects_cshared.go b/cshared/objects_cshared.go
index 17b2e1b..2600555 100644
--- a/cshared/objects_cshared.go
+++ b/cshared/objects_cshared.go
@@ -90,7 +90,7 @@ func c_Blob_Read(b uint64) (int, *C.char) {
if err != nil {
return ErrorCodeInternal, C.CString(err.Error())
}
- data, err := ioutil.ReadAll(reader)
+ data, err := ioutil.ReadAll(reader)
reader.Close()
if err != nil {
return ErrorCodeInternal, C.CString(err.Error())
@@ -106,4 +106,4 @@ func c_Blob_Type(c uint64) int8 {
}
blob := obj.(*git.Blob)
return int8(blob.Type())
-} \ No newline at end of file
+}
diff --git a/cshared/std_cshared.go b/cshared/std_cshared.go
index ca93993..90514b8 100644
--- a/cshared/std_cshared.go
+++ b/cshared/std_cshared.go
@@ -25,7 +25,7 @@ func c_std_map_get_str_str(m uint64, key string) *C.char {
return nil
}
if (val.Kind() == reflect.Slice || val.Kind() == reflect.Array) &&
- val.Type().Elem().Kind() == reflect.Uint8 {
+ val.Type().Elem().Kind() == reflect.Uint8 {
arr := make([]byte, val.Len(), val.Len())
reflect.Copy(reflect.ValueOf(arr), val)
return CBytes(arr)
diff --git a/cshared/tag_cshared.go b/cshared/tag_cshared.go
index d138f63..67c3ada 100644
--- a/cshared/tag_cshared.go
+++ b/cshared/tag_cshared.go
@@ -4,7 +4,7 @@ package main
import (
"C"
"io"
-
+
"gopkg.in/src-d/go-git.v4"
"gopkg.in/src-d/go-git.v4/core"
)
@@ -37,7 +37,7 @@ func c_Tag_get_Tagger(t uint64) uint64 {
}
func c_Tag_get_Message(t uint64) *C.char {
- obj, ok := GetObject(Handle(t))
+ obj, ok := GetObject(Handle(t))
if !ok {
return nil
}
@@ -46,7 +46,7 @@ func c_Tag_get_Message(t uint64) *C.char {
}
func c_Tag_get_TargetType(t uint64) int8 {
- obj, ok := GetObject(Handle(t))
+ obj, ok := GetObject(Handle(t))
if !ok {
return -1
}
@@ -55,7 +55,7 @@ func c_Tag_get_TargetType(t uint64) int8 {
}
func c_Tag_get_Target(t uint64) *C.char {
- obj, ok := GetObject(Handle(t))
+ obj, ok := GetObject(Handle(t))
if !ok {
return nil
}