aboutsummaryrefslogtreecommitdiffstats
path: root/cshared/objects_cshared.go
blob: 17b2e1bfeca84e79b00d903cef781901f6e6215a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// +build ignore
package main

import (
	"C"
	"io/ioutil"
	"time"

	"gopkg.in/src-d/go-git.v4"
	"gopkg.in/src-d/go-git.v4/core"
)

//export c_Signature_Name
func c_Signature_Name(s uint64) *C.char {
	obj, ok := GetObject(Handle(s))
	if !ok {
		return nil
	}
	sign := obj.(*git.Signature)
	return C.CString(sign.Name)
}

//export c_Signature_Email
func c_Signature_Email(s uint64) *C.char {
	obj, ok := GetObject(Handle(s))
	if !ok {
		return nil
	}
	sign := obj.(*git.Signature)
	return C.CString(sign.Email)
}

//export c_Signature_When
func c_Signature_When(s uint64) *C.char {
	obj, ok := GetObject(Handle(s))
	if !ok {
		return nil
	}
	sign := obj.(*git.Signature)
	return C.CString(sign.When.Format(time.RFC3339))
}

//export c_Signature_Decode
func c_Signature_Decode(b []byte) uint64 {
	sign := git.Signature{}
	sign.Decode(b)
	return uint64(RegisterObject(&sign))
}

//export c_Blob_get_Hash
func c_Blob_get_Hash(b uint64) *C.char {
	obj, ok := GetObject(Handle(b))
	if !ok {
		return nil
	}
	blob := obj.(*git.Blob)
	return CBytes(blob.Hash[:])
}

//export c_Blob_Size
func c_Blob_Size(b uint64) int64 {
	obj, ok := GetObject(Handle(b))
	if !ok {
		return -1
	}
	blob := obj.(*git.Blob)
	return blob.Size
}

//export c_Blob_Decode
func c_Blob_Decode(o uint64) uint64 {
	obj, ok := GetObject(Handle(o))
	if !ok {
		return IH
	}
	cobj := obj.(*core.Object)
	blob := git.Blob{}
	blob.Decode(*cobj)
	return uint64(RegisterObject(&blob))
}

//export c_Blob_Read
func c_Blob_Read(b uint64) (int, *C.char) {
	obj, ok := GetObject(Handle(b))
	if !ok {
		return ErrorCodeNotFound, C.CString(MessageNotFound)
	}
	blob := obj.(*git.Blob)
	reader, err := blob.Reader()
	if err != nil {
		return ErrorCodeInternal, C.CString(err.Error())
	}
  data, err := ioutil.ReadAll(reader)
	reader.Close()
	if err != nil {
		return ErrorCodeInternal, C.CString(err.Error())
	}
	return len(data), CBytes(data)
}

//export c_Blob_Type
func c_Blob_Type(c uint64) int8 {
	obj, ok := GetObject(Handle(c))
	if !ok {
		return -1
	}
	blob := obj.(*git.Blob)
	return int8(blob.Type())
}