diff --git a/commit.go b/commit.go index bba02e8..855ed87 100644 --- a/commit.go +++ b/commit.go @@ -9,6 +9,7 @@ extern int _go_git_treewalk(git_tree *tree, git_treewalk_mode mode, void *ptr); import "C" import ( + "time" ) // Commit @@ -38,15 +39,35 @@ func (c *Commit) TreeId() *Oid { return newOidFromC(C.git_commit_tree_id(c.ptr)) } -/* TODO */ -/* func (c *Commit) Author() *Signature { ptr := C.git_commit_author(c.ptr) - return &Signature{ptr} + return newSignatureFromC(ptr) } func (c *Commit) Committer() *Signature { ptr := C.git_commit_committer(c.ptr) - return &Signature{ptr} + return newSignatureFromC(ptr) +} + +// Signature + +type Signature struct { + Name string + Email string + UnixTime int64 + Offset int +} + +func newSignatureFromC(sig *C.git_signature) *Signature { + return &Signature{ + C.GoString(sig.name), + C.GoString(sig.email), + int64(sig.when.time), + int(sig.when.offset), + } +} + +func (sig *Signature) Time() time.Time { + loc := time.FixedZone("", sig.Offset*60) + return time.Unix(sig.UnixTime, 0).In(loc) } -*/