示例#1
0
文件: trees.go 项目: themihai/ggit
func flatten(r api.Repository, base string, treeEntry *objects.TreeEntry) (result []*objects.TreeEntry, err error) {
	result = make([]*objects.TreeEntry, 0)
	var object objects.Object
	object, err = r.ObjectFromOid(treeEntry.ObjectId())
	if err != nil {
		return nil, err
	}
	tree, _ := object.(*objects.Tree)
	for _, entry := range tree.Entries() {
		result = append(result, objects.NewTreeEntry(entry.Mode(), entry.ObjectType(), base+entry.Name(), entry.ObjectId()))
	}
	return result, nil
}
示例#2
0
文件: trees.go 项目: themihai/ggit
// parseTree performs the parsing of binary data into a Tree
// object, or panics with panicErr if there is a problem parsing.
// For this reason, it should be called as a parameter to
// safeParse().
func (p *objectParser) parseTree() *objects.Tree {
	entries := make([]*objects.TreeEntry, 0)
	p.ResetCount()
	for !p.EOF() {
		mode := p.ParseFileMode(token.SP)
		name := p.ReadString(token.NUL)
		oid := p.ParseOidBytes()
		t := deduceObjectType(mode)
		entry := objects.NewTreeEntry(mode, t, name, oid)
		entries = append(entries, entry)
	}

	if p.Count() != p.hdr.Size() {
		util.PanicErrf("payload of size %d isn't of expected size %d", p.Count(), p.hdr.Size())
	}
	return objects.NewTree(p.oid, p.hdr, entries)
}