I am working on an application that lists all files in a .git repository. I have a working way to turn a tree into a flat list but it is very slow (300ms)
This is the source code for a Tree object https://github.com/go-git/go-git/blob/master/plumbing/object/tree.go
My working solution:
repo, err := git.PlainOpen("./repository")
commit, err := repo.CommitObject(ref.Hash())
tree, err := commit.Tree()
var files []string
tree.Files().ForEach(func(f *object.File) error {
files = append(files, f.Name)
return nil
})
return files
However, as mentioned before this takes ~300ms to run. While doing git ls-files
takes < 50ms. As someone starting out with Go, am I missing something obvious?