Ai
1 Star 0 Fork 0

timesp/go-git

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
file.go 1.33 KB
一键复制 编辑 原始数据 按行查看 历史
package fsnoder
import (
"bytes"
"fmt"
"hash/fnv"
"gopkg.in/src-d/go-git.v4/utils/merkletrie/noder"
)
// file values represent file-like noders in a merkle trie.
type file struct {
name string // relative
contents string
hash []byte // memoized
}
// newFile returns a noder representing a file with the given contents.
func newFile(name, contents string) (*file, error) {
if name == "" {
return nil, fmt.Errorf("files cannot have empty names")
}
return &file{
name: name,
contents: contents,
}, nil
}
// The hash of a file is just its contents.
// Empty files will have the fnv64 basis offset as its hash.
func (f *file) Hash() []byte {
if f.hash == nil {
h := fnv.New64a()
h.Write([]byte(f.contents)) // it nevers returns an error.
f.hash = h.Sum(nil)
}
return f.hash
}
func (f *file) Name() string {
return f.name
}
func (f *file) IsDir() bool {
return false
}
func (f *file) Children() ([]noder.Noder, error) {
return noder.NoChildren, nil
}
func (f *file) NumChildren() (int, error) {
return 0, nil
}
const (
fileStartMark = '<'
fileEndMark = '>'
)
// String returns a string formated as: name<contents>.
func (f *file) String() string {
var buf bytes.Buffer
buf.WriteString(f.name)
buf.WriteRune(fileStartMark)
buf.WriteString(f.contents)
buf.WriteRune(fileEndMark)
return buf.String()
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/timesp/go-git.git
git@gitee.com:timesp/go-git.git
timesp
go-git
go-git
v4.7.0

搜索帮助