5 Star 11 Fork 7

Gitee 极速下载/go-git

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/src-d/go-git
克隆/下载
objects.go 1.66 KB
一键复制 编辑 原始数据 按行查看 历史
Alex Guerrieri 提交于 2015-11-23 18:04 . Timezone fixes
package git
import (
"fmt"
"io"
"strconv"
"time"
"gopkg.in/src-d/go-git.v2/core"
)
// Blob is used to store file data - it is generally a file.
type Blob struct {
Hash core.Hash
Size int64
obj core.Object
}
// Decode transform an core.Object into a Blob struct
func (b *Blob) Decode(o core.Object) error {
b.Hash = o.Hash()
b.Size = o.Size()
b.obj = o
return nil
}
// Reader returns a reader allow the access to the content of the blob
func (b *Blob) Reader() io.Reader {
return b.obj.Reader()
}
// Signature represents an action signed by a person
type Signature struct {
Name string
Email string
When time.Time
}
// Decode decodes a byte slice into a signature
func (s *Signature) Decode(b []byte) {
if len(b) == 0 {
return
}
from := 0
state := 'n' // n: name, e: email, t: timestamp, z: timezone
for i := 0; ; i++ {
var c byte
var end bool
if i < len(b) {
c = b[i]
} else {
end = true
}
switch state {
case 'n':
if c == '<' || end {
if i == 0 {
break
}
s.Name = string(b[from : i-1])
state = 'e'
from = i + 1
}
case 'e':
if c == '>' || end {
s.Email = string(b[from:i])
i++
state = 't'
from = i + 1
}
case 't':
if c == ' ' || end {
t, err := strconv.ParseInt(string(b[from:i]), 10, 64)
if err == nil {
loc := time.UTC
ts := time.Unix(t, 0)
if len(b[i:]) >= 6 {
tl, err := time.Parse(" -0700", string(b[i:i+6]))
if err == nil {
loc = tl.Location()
}
}
s.When = ts.In(loc)
}
end = true
}
}
if end {
break
}
}
}
func (s *Signature) String() string {
return fmt.Sprintf("%s <%s>", s.Name, s.Email)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/mirrors/go-git.git
git@gitee.com:mirrors/go-git.git
mirrors
go-git
go-git
v2.1.0

搜索帮助