lfs: make lsTreeBlobs more generic

Right now, this function lets us check whether a file is a pointer or
not.  However, in the future, we'll also want to use this function to
find all of the .gitattributes files as well as pointers.  Let's make
the function take an arbitrary predicate so we can reuse it for both
purposes.
This commit is contained in:
brian m. carlson 2021-06-03 18:18:59 +00:00
parent 1e41bbffbb
commit 4c0e51ff70
No known key found for this signature in database
GPG Key ID: 2D0C9BC12F82B3A1

@ -12,7 +12,9 @@ import (
func runScanTree(cb GitScannerFoundPointer, ref string, filter *filepathfilter.Filter, gitEnv, osEnv config.Environment) error {
// We don't use the nameMap approach here since that's imprecise when >1 file
// can be using the same content
treeShas, err := lsTreeBlobs(ref, filter)
treeShas, err := lsTreeBlobs(ref, func(t *git.TreeBlob) bool {
return t != nil && t.Size < blobSizeCutoff && filter.Allows(t.Filename)
})
if err != nil {
return err
}
@ -88,7 +90,7 @@ func catFileBatchTree(treeblobs *TreeBlobChannelWrapper, gitEnv, osEnv config.En
// Use ls-tree at ref to find a list of candidate tree blobs which might be lfs files
// The returned channel will be sent these blobs which should be sent to catFileBatchTree
// for final check & conversion to Pointer
func lsTreeBlobs(ref string, filter *filepathfilter.Filter) (*TreeBlobChannelWrapper, error) {
func lsTreeBlobs(ref string, predicate func(*git.TreeBlob) bool) (*TreeBlobChannelWrapper, error) {
cmd, err := git.LsTree(ref)
if err != nil {
return nil, err
@ -102,7 +104,7 @@ func lsTreeBlobs(ref string, filter *filepathfilter.Filter) (*TreeBlobChannelWra
go func() {
scanner := git.NewLsTreeScanner(cmd.Stdout)
for scanner.Scan() {
if t := scanner.TreeBlob(); t != nil && t.Size < blobSizeCutoff && filter.Allows(t.Filename) {
if t := scanner.TreeBlob(); predicate(t) {
blobs <- *t
}
}