From dce75a89747947db36b255025b743b2dc216ddd6 Mon Sep 17 00:00:00 2001 From: Carlos Martín Nieto Date: Tue, 5 Mar 2013 23:18:07 +0100 Subject: Introduce Signature It brings the data into go-land so we don't have to worry about the commit being there. It stores the data we get from git and provides a Time() function to get a time.Time struct. --- commit.go | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) (limited to 'commit.go') 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) } -*/ -- cgit v1.2.3