MCPcopy
hub / github.com/git-lfs/git-lfs / runCatFileBatchCheck

Function runCatFileBatchCheck

lfs/gitscanner_catfilebatchcheck.go:19–61  ·  view source on GitHub ↗

runCatFileBatchCheck uses 'git cat-file --batch-check' to get the type and size of a git object. Any object that isn't of type blob and under the blobSizeCutoff will be ignored, unless it's a locked file. revs is a channel over which strings containing git sha1s will be sent. It returns a channel fr

(smallRevCh chan string, lockableCh chan string, lockableSet *lockableNameSet, revs *StringChannelWrapper, errCh chan error)

Source from the content-addressed store, hash-verified

17// over which strings containing git sha1s will be sent. It returns a channel
18// from which sha1 strings can be read.
19func runCatFileBatchCheck(smallRevCh chan string, lockableCh chan string, lockableSet *lockableNameSet, revs *StringChannelWrapper, errCh chan error) error {
20 cmd, err := git.CatFile()
21 if err != nil {
22 return err
23 }
24
25 go func() {
26 scanner := &catFileBatchCheckScanner{s: bufio.NewScanner(cmd.Stdout), limit: blobSizeCutoff}
27 for r := range revs.Results {
28 cmd.Stdin.Write([]byte(r + "\n"))
29 hasNext := scanner.Scan()
30 if err := scanner.Err(); err != nil {
31 errCh <- err
32 } else if b := scanner.LFSBlobOID(); len(b) > 0 {
33 smallRevCh <- b
34 } else if b := scanner.GitBlobOID(); len(b) > 0 {
35 if name, ok := lockableSet.Check(b); ok {
36 lockableCh <- name
37 }
38 }
39
40 if !hasNext {
41 break
42 }
43 }
44
45 if err := revs.Wait(); err != nil {
46 errCh <- err
47 }
48 cmd.Stdin.Close()
49
50 stderr, _ := io.ReadAll(cmd.Stderr)
51 err := cmd.Wait()
52 if err != nil {
53 errCh <- errors.New(tr.Tr.Get("error in `git cat-file --batch-check`: %v %v", err, string(stderr)))
54 }
55 close(smallRevCh)
56 close(errCh)
57 close(lockableCh)
58 }()
59
60 return nil
61}
62
63type catFileBatchCheckScanner struct {
64 s *bufio.Scanner

Callers 1

catFileBatchCheckFunction · 0.85

Calls 11

ScanMethod · 0.95
ErrMethod · 0.95
LFSBlobOIDMethod · 0.95
GitBlobOIDMethod · 0.95
CatFileFunction · 0.92
NewFunction · 0.92
CheckMethod · 0.80
WaitMethod · 0.65
CloseMethod · 0.65
GetMethod · 0.65
WriteMethod · 0.45

Tested by

no test coverage detected