| 1 | package lfsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/ |
| 2 | |
| 3 | import ( |
| 4 | "bufioscip-go gomod github.com/golang/go/src go1.25.0 bufio/" |
| 5 | "ioscip-go gomod github.com/golang/go/src go1.25.0 io/" |
| 6 | "strconvscip-go gomod github.com/golang/go/src go1.25.0 strconv/" |
| 7 | "stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/" |
| 8 | |
| 9 | "github.com/git-lfs/git-lfs/v3/errorsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/errors`/" |
| 10 | "github.com/git-lfs/git-lfs/v3/gitscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/" |
| 11 | "github.com/git-lfs/git-lfs/v3/trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/" |
| 12 | ) |
| 13 | |
| 14 | // runCatFileBatchCheck uses 'git cat-file --batch-check' to get the type and |
| 15 | // size of a git object. Any object that isn't of type blob and under the |
| 16 | // BlobSizeCutoff will be ignored, unless it's a locked file. revs is a channel |
| 17 | // over which strings containing git sha1s will be sent. It returns a channel |
| 18 | // from which sha1 strings can be read. |
| 19 | func runCatFileBatchCheckscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/runCatFileBatchCheck().(smallRevCh chan string, lockableCh chan string, lockableSet *lockableNameSetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/lockableNameSet#, revs *StringChannelWrapperscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/StringChannelWrapper#, errCh chan error) error { |
| 20 | cmd, err := gitscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/.CatFilescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/CatFile().() |
| 21 | if err != nil { |
| 22 | return err |
| 23 | } |
| 24 | |
| 25 | go func() { |
| 26 | scanner := &catFileBatchCheckScannerscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/catFileBatchCheckScanner#{sscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/catFileBatchCheckScanner#s.: bufioscip-go gomod github.com/golang/go/src go1.25.0 bufio/.NewScannerscip-go gomod github.com/golang/go/src go1.25.0 bufio/NewScanner().(cmd.Stdoutscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/subprocess`/BufferedCmd#Stdout.), limitscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/catFileBatchCheckScanner#limit.: BlobSizeCutoffscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/BlobSizeCutoff.} |
| 27 | for r := range revs.Resultsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/StringChannelWrapper#Results. { |
| 28 | cmd.Stdinscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/subprocess`/BufferedCmd#Stdin..Writescip-go gomod github.com/golang/go/src go1.25.0 io/Writer#Write().([]byte(r + "\n")) |
| 29 | hasNext := scanner.Scanscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/catFileBatchCheckScanner#Scan().() |
| 30 | if err := scanner.Errscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/catFileBatchCheckScanner#Err().(); err != nil { |
| 31 | errCh <- err |
| 32 | } else if b := scanner.LFSBlobOIDscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/catFileBatchCheckScanner#LFSBlobOID().(); len(b) > 0 { |
| 33 | smallRevCh <- b |
| 34 | } else if b := scanner.GitBlobOIDscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/catFileBatchCheckScanner#GitBlobOID().(); len(b) > 0 { |
| 35 | if name, ok := lockableSet.Checkscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/lockableNameSet#Check().(b); ok { |
| 36 | lockableCh <- name |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | if !hasNext { |
| 41 | break |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | if err := revs.Waitscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/BaseChannelWrapper#Wait().(); err != nil { |
| 46 | errCh <- err |
| 47 | } |
| 48 | cmd.Stdinscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/subprocess`/BufferedCmd#Stdin..Closescip-go gomod github.com/golang/go/src go1.25.0 io/Closer#Close().() |
| 49 | |
| 50 | stderr, _ := ioscip-go gomod github.com/golang/go/src go1.25.0 io/.ReadAllscip-go gomod github.com/golang/go/src go1.25.0 io/ReadAll().(cmd.Stderrscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/subprocess`/BufferedCmd#Stderr.) |
| 51 | err := cmd.Waitscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/subprocess`/Cmd#Wait().() |
| 52 | if err != nil { |
| 53 | errCh <- errorsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/errors`/.Newscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/errors`/New().(trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/.Trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/Tr..Getscip-go gomod github.com/leonelquinteros/gotext v1.7.2 `github.com/leonelquinteros/gotext`/Locale#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 catFileBatchCheckScannerscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/catFileBatchCheckScanner# struct { |
| 64 | sscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/catFileBatchCheckScanner#s. *bufioscip-go gomod github.com/golang/go/src go1.25.0 bufio/.Scannerscip-go gomod github.com/golang/go/src go1.25.0 bufio/Scanner# |
| 65 | limitscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/catFileBatchCheckScanner#limit. int |
| 66 | lfsBlobOIDscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/catFileBatchCheckScanner#lfsBlobOID. string |
| 67 | gitBlobOIDscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/catFileBatchCheckScanner#gitBlobOID. string |
| 68 | } |
| 69 | |
| 70 | func (s *catFileBatchCheckScannerscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/catFileBatchCheckScanner#) LFSBlobOIDscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/catFileBatchCheckScanner#LFSBlobOID().() string { |
| 71 | return s.lfsBlobOIDscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/catFileBatchCheckScanner#lfsBlobOID. |
| 72 | } |
| 73 | |
| 74 | func (s *catFileBatchCheckScannerscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/catFileBatchCheckScanner#) GitBlobOIDscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/catFileBatchCheckScanner#GitBlobOID().() string { |
| 75 | return s.gitBlobOIDscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/catFileBatchCheckScanner#gitBlobOID. |
| 76 | } |
| 77 | |
| 78 | func (s *catFileBatchCheckScannerscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/catFileBatchCheckScanner#) Errscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/catFileBatchCheckScanner#Err().() error { |
| 79 | return s.sscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/catFileBatchCheckScanner#s..Errscip-go gomod github.com/golang/go/src go1.25.0 bufio/Scanner#Err().() |
| 80 | } |
| 81 | |
| 82 | func (s *catFileBatchCheckScannerscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/catFileBatchCheckScanner#) Scanscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/catFileBatchCheckScanner#Scan().() bool { |
| 83 | lfsBlobSha, gitBlobSha, hasNext := s.nextscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/catFileBatchCheckScanner#next().() |
| 84 | s.lfsBlobOIDscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/catFileBatchCheckScanner#lfsBlobOID. = lfsBlobSha |
| 85 | s.gitBlobOIDscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/catFileBatchCheckScanner#gitBlobOID. = gitBlobSha |
| 86 | return hasNext |
| 87 | } |
| 88 | |
| 89 | func (s *catFileBatchCheckScannerscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/catFileBatchCheckScanner#) nextscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/catFileBatchCheckScanner#next().() (string, string, bool) { |
| 90 | hasNext := s.sscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/catFileBatchCheckScanner#s..Scanscip-go gomod github.com/golang/go/src go1.25.0 bufio/Scanner#Scan().() |
| 91 | line := s.sscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/catFileBatchCheckScanner#s..Textscip-go gomod github.com/golang/go/src go1.25.0 bufio/Scanner#Text().() |
| 92 | lineLen := len(line) |
| 93 | |
| 94 | oidLen := stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.IndexBytescip-go gomod github.com/golang/go/src go1.25.0 strings/IndexByte().(line, ' ') |
| 95 | |
| 96 | // Format is: |
| 97 | // <hash> <type> <size> |
| 98 | // type is at a fixed spot, if we see that it's "blob", we can avoid |
| 99 | // splitting the line just to get the size. |
| 100 | if oidLen == -1 || lineLen < oidLen+6 { |
| 101 | return "", "", hasNext |
| 102 | } |
| 103 | |
| 104 | if line[oidLen+1:oidLen+5] != "blob" { |
| 105 | return "", "", hasNext |
| 106 | } |
| 107 | |
| 108 | size, err := strconvscip-go gomod github.com/golang/go/src go1.25.0 strconv/.Atoiscip-go gomod github.com/golang/go/src go1.25.0 strconv/Atoi().(line[oidLen+6 : lineLen]) |
| 109 | if err != nil { |
| 110 | return "", "", hasNext |
| 111 | } |
| 112 | |
| 113 | blobSha := line[0:oidLen] |
| 114 | if size >= s.limitscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/catFileBatchCheckScanner#limit. { |
| 115 | return "", blobSha, hasNext |
| 116 | } |
| 117 | |
| 118 | return blobSha, "", hasNext |
| 119 | } |