- Notifications
You must be signed in to change notification settings - Fork 324
/
Copy pathmessage.go
42 lines (36 loc) · 1.17 KB
/
message.go
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
package git
/*
#include <git2.h>
*/
import"C"
import (
"runtime"
"unsafe"
)
// Trailer represents a single git message trailer.
typeTrailerstruct {
Keystring
Valuestring
}
// MessageTrailers parses trailers out of a message, returning a slice of
// Trailer structs. Trailers are key/value pairs in the last paragraph of a
// message, not including any patches or conflicts that may be present.
funcMessageTrailers(messagestring) ([]Trailer, error) {
vartrailersC C.git_message_trailer_array
messageC:=C.CString(message)
deferC.free(unsafe.Pointer(messageC))
runtime.LockOSThread()
deferruntime.UnlockOSThread()
ecode:=C.git_message_trailers(&trailersC, messageC)
ifecode<0 {
returnnil, MakeGitError(ecode)
}
deferC.git_message_trailer_array_free(&trailersC)
trailers:=make([]Trailer, trailersC.count)
vartrailer*C.git_message_trailer
fori, p:=0, uintptr(unsafe.Pointer(trailersC.trailers)); i<int(trailersC.count); i, p=i+1, p+unsafe.Sizeof(C.git_message_trailer{}) {
trailer= (*C.git_message_trailer)(unsafe.Pointer(p))
trailers[i] =Trailer{Key: C.GoString(trailer.key), Value: C.GoString(trailer.value)}
}
returntrailers, nil
}