summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--commit.go18
-rw-r--r--repository.go20
2 files changed, 32 insertions, 6 deletions
diff --git a/commit.go b/commit.go
index 779ebd7..93160ba 100644
--- a/commit.go
+++ b/commit.go
@@ -10,6 +10,7 @@ import "C"
import (
"runtime"
+ "unsafe"
"time"
)
@@ -74,3 +75,20 @@ func (sig *Signature) Time() time.Time {
loc := time.FixedZone("", sig.Offset*60)
return time.Unix(sig.UnixTime, 0).In(loc)
}
+
+func (sig *Signature) toC() (*C.git_signature) {
+ var out *C.git_signature
+
+ name := C.CString(sig.Name)
+ defer C.free(unsafe.Pointer(name))
+
+ email := C.CString(sig.Email)
+ defer C.free(unsafe.Pointer(email))
+
+ ret := C.git_signature_new(&out, name, email, C.git_time_t(sig.UnixTime), C.int(sig.Offset))
+ if ret < 0 {
+ return nil
+ }
+
+ return out
+}
diff --git a/repository.go b/repository.go
index 5313af3..0f5eff5 100644
--- a/repository.go
+++ b/repository.go
@@ -104,19 +104,22 @@ func (v *Repository) Walk() (*RevWalk, error) {
return walk, nil
}
-/* TODO
-func (v *Repository) Commit(
+func (v *Repository) CreateCommit(
refname string, author, committer *Signature,
message string, tree *Tree, parents ...*Commit) (*Oid, error) {
oid := new(Oid)
+
cref := C.CString(refname)
defer C.free(unsafe.Pointer(cref))
+
cmsg := C.CString(message)
defer C.free(unsafe.Pointer(cmsg))
- nparents := len(parents)
+
var cparents []*C.git_commit = nil
var parentsarg **C.git_commit = nil
+
+ nparents:= len(parents)
if nparents > 0 {
cparents = make([]*C.git_commit, nparents)
for i, v := range parents {
@@ -125,18 +128,23 @@ func (v *Repository) Commit(
parentsarg = &cparents[0]
}
+ authorSig := author.toC()
+ defer C.git_signature_free(authorSig)
+
+ committerSig := committer.toC()
+ defer C.git_signature_free(committerSig)
+
ret := C.git_commit_create(
oid.toC(), v.ptr, cref,
- author.git_signature, committer.git_signature,
+ authorSig, committerSig,
nil, cmsg, tree.ptr, C.int(nparents), parentsarg)
- if ret < GIT_SUCCESS {
+ if ret < 0 {
return nil, LastError()
}
return oid, nil
}
-*/
func (v *Odb) Free() {
runtime.SetFinalizer(v, nil)