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)
| 17 | // over which strings containing git sha1s will be sent. It returns a channel |
| 18 | // from which sha1 strings can be read. |
| 19 | func 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 | |
| 63 | type catFileBatchCheckScanner struct { |
| 64 | s *bufio.Scanner |
no test coverage detected