extract ls tree parser
This commit is contained in:
parent
a2781ff9cd
commit
9088cc364f
@ -595,29 +595,38 @@ func lsTreeBlobs(ref string) (chan TreeBlob, error) {
|
|||||||
blobs := make(chan TreeBlob, chanBufSize)
|
blobs := make(chan TreeBlob, chanBufSize)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
scanner := bufio.NewScanner(cmd.Stdout)
|
parseLsTree(cmd.Stdout, blobs)
|
||||||
regex := regexp.MustCompile(`^\d+\s+blob\s+([0-9a-zA-Z]{40})\s+(\d+)\s+(.*)$`)
|
cmd.Wait()
|
||||||
for scanner.Scan() {
|
|
||||||
line := strings.TrimSpace(scanner.Text())
|
|
||||||
if match := regex.FindStringSubmatch(line); match != nil {
|
|
||||||
sz, err := strconv.ParseInt(match[2], 10, 64)
|
|
||||||
if err != nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
sha1 := match[1]
|
|
||||||
filename := match[3]
|
|
||||||
if sz < blobSizeCutoff {
|
|
||||||
blobs <- TreeBlob{sha1, filename}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
close(blobs)
|
close(blobs)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
return blobs, nil
|
return blobs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var lsTreeRE = regexp.MustCompile(`^\d+\s+blob\s+([0-9a-zA-Z]{40})\s+(\d+)\s+(.*)$`)
|
||||||
|
|
||||||
|
func parseLsTree(reader io.Reader, output chan TreeBlob) {
|
||||||
|
scanner := bufio.NewScanner(reader)
|
||||||
|
for scanner.Scan() {
|
||||||
|
line := strings.TrimSpace(scanner.Text())
|
||||||
|
match := lsTreeRE.FindStringSubmatch(line)
|
||||||
|
if match == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
sz, err := strconv.ParseInt(match[2], 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
sha1 := match[1]
|
||||||
|
filename := match[3]
|
||||||
|
if sz < blobSizeCutoff {
|
||||||
|
output <- TreeBlob{sha1, filename}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ScanUnpushed scans history for all LFS pointers which have been added but not
|
// ScanUnpushed scans history for all LFS pointers which have been added but not
|
||||||
// pushed to the named remote. remoteName can be left blank to mean 'any remote'
|
// pushed to the named remote. remoteName can be left blank to mean 'any remote'
|
||||||
func ScanUnpushed(remoteName string) ([]*WrappedPointer, error) {
|
func ScanUnpushed(remoteName string) ([]*WrappedPointer, error) {
|
||||||
|
Loading…
Reference in New Issue
Block a user