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.
This commit is contained in:
Carlos Martín Nieto 2013-03-05 23:18:07 +01:00
parent dd2ad2bf6b
commit dce75a8974
1 changed files with 26 additions and 5 deletions

View File

@ -9,6 +9,7 @@ extern int _go_git_treewalk(git_tree *tree, git_treewalk_mode mode, void *ptr);
import "C" import "C"
import ( import (
"time"
) )
// Commit // Commit
@ -38,15 +39,35 @@ func (c *Commit) TreeId() *Oid {
return newOidFromC(C.git_commit_tree_id(c.ptr)) return newOidFromC(C.git_commit_tree_id(c.ptr))
} }
/* TODO */
/*
func (c *Commit) Author() *Signature { func (c *Commit) Author() *Signature {
ptr := C.git_commit_author(c.ptr) ptr := C.git_commit_author(c.ptr)
return &Signature{ptr} return newSignatureFromC(ptr)
} }
func (c *Commit) Committer() *Signature { func (c *Commit) Committer() *Signature {
ptr := C.git_commit_committer(c.ptr) 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)
} }
*/