summaryrefslogtreecommitdiff
path: root/commit.go
diff options
context:
space:
mode:
Diffstat (limited to 'commit.go')
-rw-r--r--commit.go64
1 files changed, 29 insertions, 35 deletions
diff --git a/commit.go b/commit.go
index 559a1bd..52f7c01 100644
--- a/commit.go
+++ b/commit.go
@@ -9,7 +9,6 @@ import "C"
import (
"runtime"
- "time"
"unsafe"
)
@@ -23,6 +22,10 @@ func (c Commit) Message() string {
return C.GoString(C.git_commit_message(c.cast_ptr))
}
+func (c Commit) Summary() string {
+ return C.GoString(C.git_commit_summary(c.cast_ptr))
+}
+
func (c Commit) Tree() (*Tree, error) {
var ptr *C.git_tree
@@ -69,48 +72,39 @@ func (c *Commit) ParentCount() uint {
return uint(C.git_commit_parentcount(c.cast_ptr))
}
-// Signature
-
-type Signature struct {
- Name string
- Email string
- When time.Time
-}
-
-func newSignatureFromC(sig *C.git_signature) *Signature {
- // git stores minutes, go wants seconds
- loc := time.FixedZone("", int(sig.when.offset)*60)
- return &Signature{
- C.GoString(sig.name),
- C.GoString(sig.email),
- time.Unix(int64(sig.when.time), 0).In(loc),
+func (c *Commit) Amend(refname string, author, committer *Signature, message string, tree *Tree) (*Oid, error) {
+ var cref *C.char
+ if refname == "" {
+ cref = nil
+ } else {
+ cref = C.CString(refname)
+ defer C.free(unsafe.Pointer(cref))
}
-}
-// the offset in mintes, which is what git wants
-func (v *Signature) Offset() int {
- _, offset := v.When.Zone()
- return offset / 60
-}
+ cmsg := C.CString(message)
+ defer C.free(unsafe.Pointer(cmsg))
-func (sig *Signature) toC() *C.git_signature {
+ runtime.LockOSThread()
+ defer runtime.UnlockOSThread()
- if sig == nil {
- return nil
+ authorSig, err := author.toC()
+ if err != nil {
+ return nil, err
}
+ defer C.git_signature_free(authorSig)
- var out *C.git_signature
-
- name := C.CString(sig.Name)
- defer C.free(unsafe.Pointer(name))
+ committerSig, err := committer.toC()
+ if err != nil {
+ return nil, err
+ }
+ defer C.git_signature_free(committerSig)
- email := C.CString(sig.Email)
- defer C.free(unsafe.Pointer(email))
+ oid := new(Oid)
- ret := C.git_signature_new(&out, name, email, C.git_time_t(sig.When.Unix()), C.int(sig.Offset()))
- if ret < 0 {
- return nil
+ cerr := C.git_commit_amend(oid.toC(), c.cast_ptr, cref, authorSig, committerSig, nil, cmsg, tree.cast_ptr)
+ if cerr < 0 {
+ return nil, MakeGitError(cerr)
}
- return out
+ return oid, nil
}