Example #1
0
func (p *Project) mapFromTree(tree *git.Tree) (docs map[string]*pb.Document, err error) {
	var walkErr error
	docs = make(map[string]*pb.Document, tree.EntryCount())
	err = tree.Walk(func(path string, entry *git.TreeEntry) int {
		// add objects to deployment
		if entry.Type == git.ObjectBlob {
			doc, err := p.getDocument(entry.Id)
			if err != nil {
				walkErr = err
				return -1
			}

			path = path + entry.Name
			docs[path] = doc
			if walkErr != nil {
				return -1
			}
		}
		return 0
	})

	if err != nil {
		err = fmt.Errorf("error starting walk: %v", err)
	} else if walkErr != nil {
		err = fmt.Errorf("error during walk: %v", walkErr)
	}
	return
}
Example #2
0
func (gitfs *GitFs) treeEntryCount(tree *libgit2.Tree, repoPath string) (count uint32) {
	count = 0
	for i := uint64(0); i < tree.EntryCount(); i++ {
		entry := tree.EntryByIndex(i)
		if entry == nil {
			gitfs.logger.Errorf("Failed to get tree entry by index %d from tree %s of Git Repository %s", i, tree.Id().String(), repoPath)
			return
		}
		if entry.Type == libgit2.ObjectTree {
			count++
		}
	}
	return
}