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 }
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 }