9 "github.com/git-lfs/git-lfs/git"
12 // runCatFileBatchCheck uses 'git cat-file --batch-check' to get the type and
13 // size of a git object. Any object that isn't of type blob and under the
14 // blobSizeCutoff will be ignored, unless it's a locked file. revs is a channel
15 // over which strings containing git sha1s will be sent. It returns a channel
16 // from which sha1 strings can be read.
17 func runCatFileBatchCheck(smallRevCh chan string, lockableCh chan string, lockableSet *lockableNameSet, revs *StringChannelWrapper, errCh chan error) error {
18 cmd, err := git.CatFile()
24 scanner := &catFileBatchCheckScanner{s: bufio.NewScanner(cmd.Stdout), limit: blobSizeCutoff}
25 for r := range revs.Results {
26 cmd.Stdin.Write([]byte(r + "\n"))
27 hasNext := scanner.Scan()
28 if err := scanner.Err(); err != nil {
30 } else if b := scanner.LFSBlobOID(); len(b) > 0 {
32 } else if b := scanner.GitBlobOID(); len(b) > 0 {
33 if name, ok := lockableSet.Check(b); ok {
43 if err := revs.Wait(); err != nil {
48 stderr, _ := ioutil.ReadAll(cmd.Stderr)
51 errCh <- fmt.Errorf("Error in git cat-file --batch-check: %v %v", err, string(stderr))
60 type catFileBatchCheckScanner struct {
67 func (s *catFileBatchCheckScanner) LFSBlobOID() string {
71 func (s *catFileBatchCheckScanner) GitBlobOID() string {
75 func (s *catFileBatchCheckScanner) Err() error {
79 func (s *catFileBatchCheckScanner) Scan() bool {
80 lfsBlobSha, gitBlobSha, hasNext := s.next()
81 s.lfsBlobOID = lfsBlobSha
82 s.gitBlobOID = gitBlobSha
86 func (s *catFileBatchCheckScanner) next() (string, string, bool) {
92 // <sha1> <type> <size>
93 // type is at a fixed spot, if we see that it's "blob", we can avoid
94 // splitting the line just to get the size.
96 return "", "", hasNext
99 if line[41:45] != "blob" {
100 return "", "", hasNext
103 size, err := strconv.Atoi(line[46:lineLen])
105 return "", "", hasNext
108 blobSha := line[0:40]
110 return "", blobSha, hasNext
113 return blobSha, "", hasNext