本文整理匯總了Golang中github.com/libgit2/git2go.Tree.EntryByIndex方法的典型用法代碼示例。如果您正苦於以下問題:Golang Tree.EntryByIndex方法的具體用法?Golang Tree.EntryByIndex怎麽用?Golang Tree.EntryByIndex使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/libgit2/git2go.Tree
的用法示例。
在下文中一共展示了Tree.EntryByIndex方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: ReadDir
func (fs *gitFSLibGit2) ReadDir(path string) ([]os.FileInfo, error) {
fs.repoEditLock.RLock()
defer fs.repoEditLock.RUnlock()
path = filepath.Clean(internal.Rel(path))
var subtree *git2go.Tree
if path == "." {
subtree = fs.tree
} else {
e, err := fs.getEntry(path)
if err != nil {
return nil, err
}
subtree, err = fs.repo.LookupTree(e.Id)
if err != nil {
return nil, err
}
}
fis := make([]os.FileInfo, int(subtree.EntryCount()))
for i := uint64(0); i < subtree.EntryCount(); i++ {
e := subtree.EntryByIndex(i)
fi, err := fs.makeFileInfo(filepath.Join(path, e.Name), e)
if err != nil {
return nil, err
}
fis[i] = fi
}
return fis, nil
}
示例2: recurse
func (t *treeFS) recurse(tree *git.Tree, n nodefs.Node) error {
for i := uint64(0); ; i++ {
e := tree.EntryByIndex(i)
if e == nil {
break
}
isdir := e.Filemode&syscall.S_IFDIR != 0
var chNode nodefs.Node
if isdir {
chNode = t.newDirNode(e.Id)
} else if e.Filemode&^07777 == syscall.S_IFLNK {
l, err := t.newLinkNode(e.Id)
if err != nil {
return err
}
chNode = l
} else if e.Filemode&^07777 == syscall.S_IFREG {
b, err := t.newBlobNode(e.Id, e.Filemode)
if err != nil {
return err
}
chNode = b
} else {
panic(e)
}
n.Inode().NewChild(e.Name, isdir, chNode)
if isdir {
tree, err := t.repo.LookupTree(e.Id)
if err != nil {
return err
}
if err := t.recurse(tree, chNode); err != nil {
return nil
}
}
}
return nil
}