| 1 | package lfsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/ |
| 2 | |
| 3 | import ( |
| 4 | "stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/" |
| 5 | "syncscip-go gomod github.com/golang/go/src go1.25.0 sync/" |
| 6 | |
| 7 | "github.com/git-lfs/git-lfs/v3/configscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/" |
| 8 | "github.com/git-lfs/git-lfs/v3/filepathfilterscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/filepathfilter`/" |
| 9 | ) |
| 10 | |
| 11 | // ScanIndex returns a slice of WrappedPointer objects for all Git LFS pointers |
| 12 | // it finds in the index. |
| 13 | // |
| 14 | // Ref is the ref at which to scan, which may be "HEAD" if there is at least one |
| 15 | // commit. |
| 16 | func scanIndexscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/scanIndex().(cb GitScannerFoundPointerscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/GitScannerFoundPointer#, ref string, workingDir string, f *filepathfilterscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/filepathfilter`/.Filterscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/filepathfilter`/Filter#, gitEnv, osEnv configscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/.Environmentscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/Environment#) error { |
| 17 | indexMap := &indexFileMapscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/indexFileMap#{ |
| 18 | nameMapscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/indexFileMap#nameMap.: make(map[string][]*indexFilescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/indexFile#), |
| 19 | nameShaPairsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/indexFileMap#nameShaPairs.: make(map[string]bool), |
| 20 | mutexscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/indexFileMap#mutex.: &syncscip-go gomod github.com/golang/go/src go1.25.0 sync/.Mutexscip-go gomod github.com/golang/go/src go1.25.0 sync/Mutex#{}, |
| 21 | } |
| 22 | |
| 23 | revs, err := revListIndexscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/revListIndex().(ref, false, indexMap, workingDir) |
| 24 | if err != nil { |
| 25 | return err |
| 26 | } |
| 27 | |
| 28 | cachedRevs, err := revListIndexscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/revListIndex().(ref, true, indexMap, workingDir) |
| 29 | if err != nil { |
| 30 | return err |
| 31 | } |
| 32 | |
| 33 | allRevsErr := make(chan error, 5) // can be multiple errors below |
| 34 | allRevsChan := make(chan string, 1) |
| 35 | allRevs := NewStringChannelWrapperscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/NewStringChannelWrapper().(allRevsChan, allRevsErr) |
| 36 | go func() { |
| 37 | seenRevs := make(map[string]bool, 0) |
| 38 | |
| 39 | for rev := range cachedRevs.Resultsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/StringChannelWrapper#Results. { |
| 40 | if !seenRevs[rev] { |
| 41 | allRevsChan <- rev |
| 42 | seenRevs[rev] = true |
| 43 | } |
| 44 | } |
| 45 | err = cachedRevs.Waitscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/BaseChannelWrapper#Wait().() |
| 46 | if err != nil { |
| 47 | allRevsErr <- err |
| 48 | } |
| 49 | |
| 50 | for rev := range revs.Resultsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/StringChannelWrapper#Results. { |
| 51 | if !seenRevs[rev] { |
| 52 | allRevsChan <- rev |
| 53 | seenRevs[rev] = true |
| 54 | } |
| 55 | } |
| 56 | err := revs.Waitscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/BaseChannelWrapper#Wait().() |
| 57 | if err != nil { |
| 58 | allRevsErr <- err |
| 59 | } |
| 60 | close(allRevsChan) |
| 61 | close(allRevsErr) |
| 62 | }() |
| 63 | |
| 64 | smallShas, _, err := catFileBatchCheckscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/catFileBatchCheck().(allRevs, nil) |
| 65 | if err != nil { |
| 66 | return err |
| 67 | } |
| 68 | |
| 69 | ch := make(chan gitscannerResultscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/gitscannerResult#, chanBufSizescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/chanBufSize.) |
| 70 | |
| 71 | barePointerCh, _, err := catFileBatchscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/catFileBatch().(smallShas, nil, gitEnv, osEnv) |
| 72 | if err != nil { |
| 73 | return err |
| 74 | } |
| 75 | |
| 76 | go func() { |
| 77 | for p := range barePointerCh.Resultsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/PointerChannelWrapper#Results. { |
| 78 | for _, file := range indexMap.FilesForscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/indexFileMap#FilesFor().(p.Sha1scip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/WrappedPointer#Sha1.) { |
| 79 | // Append a new *WrappedPointer that combines the data |
| 80 | // from the index file, and the pointer "p". |
| 81 | ch <- gitscannerResultscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/gitscannerResult#{ |
| 82 | Pointerscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/gitscannerResult#Pointer.: &WrappedPointerscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/WrappedPointer#{ |
| 83 | Sha1scip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/WrappedPointer#Sha1.: p.Sha1scip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/WrappedPointer#Sha1., |
| 84 | Namescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/WrappedPointer#Name.: file.Namescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/indexFile#Name., |
| 85 | SrcNamescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/WrappedPointer#SrcName.: file.SrcNamescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/indexFile#SrcName., |
| 86 | Statusscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/WrappedPointer#Status.: file.Statusscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/indexFile#Status., |
| 87 | Pointerscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/WrappedPointer#Pointer.: p.Pointerscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/WrappedPointer#Pointer., |
| 88 | }, |
| 89 | } |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | if err := barePointerCh.Waitscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/BaseChannelWrapper#Wait().(); err != nil { |
| 94 | ch <- gitscannerResultscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/gitscannerResult#{Errscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/gitscannerResult#Err.: err} |
| 95 | } |
| 96 | |
| 97 | close(ch) |
| 98 | }() |
| 99 | |
| 100 | for result := range ch { |
| 101 | if f.Allowsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/filepathfilter`/Filter#Allows().(result.Pointerscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/gitscannerResult#Pointer..Namescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/WrappedPointer#Name.) { |
| 102 | cb(result.Pointerscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/gitscannerResult#Pointer., result.Errscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/gitscannerResult#Err.) |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | return nil |
| 107 | } |
| 108 | |
| 109 | // revListIndex uses git diff-index to return the list of object sha1s |
| 110 | // for in the indexf. It returns a channel from which sha1 strings can be read. |
| 111 | // The namMap will be filled indexFile pointers mapping sha1s to indexFiles. |
| 112 | func revListIndexscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/revListIndex().(atRef string, cache bool, indexMap *indexFileMapscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/indexFileMap#, workingDir string) (*StringChannelWrapperscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/StringChannelWrapper#, error) { |
| 113 | scanner, err := NewDiffIndexScannerscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/NewDiffIndexScanner().(atRef, cache, false, workingDir) |
| 114 | if err != nil { |
| 115 | return nil, err |
| 116 | } |
| 117 | |
| 118 | revs := make(chan string, chanBufSizescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/chanBufSize.) |
| 119 | errs := make(chan error, 1) |
| 120 | |
| 121 | go func() { |
| 122 | for scanner.Scanscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/DiffIndexScanner#Scan().() { |
| 123 | var name string = scanner.Entryscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/DiffIndexScanner#Entry().().DstNamescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/DiffIndexEntry#DstName. |
| 124 | if len(name) == 0 { |
| 125 | name = scanner.Entryscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/DiffIndexScanner#Entry().().SrcNamescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/DiffIndexEntry#SrcName. |
| 126 | } |
| 127 | |
| 128 | indexMap.Addscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/indexFileMap#Add().(scanner.Entryscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/DiffIndexScanner#Entry().().DstShascip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/DiffIndexEntry#DstSha., &indexFilescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/indexFile#{ |
| 129 | Namescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/indexFile#Name.: name, |
| 130 | SrcNamescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/indexFile#SrcName.: scanner.Entryscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/DiffIndexScanner#Entry().().SrcNamescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/DiffIndexEntry#SrcName., |
| 131 | Statusscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/indexFile#Status.: string(scanner.Entryscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/DiffIndexScanner#Entry().().Statusscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/DiffIndexEntry#Status.), |
| 132 | }) |
| 133 | |
| 134 | revs <- scanner.Entryscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/DiffIndexScanner#Entry().().DstShascip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/DiffIndexEntry#DstSha. |
| 135 | } |
| 136 | |
| 137 | if err := scanner.Errscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/DiffIndexScanner#Err().(); err != nil { |
| 138 | errs <- err |
| 139 | } |
| 140 | |
| 141 | close(revs) |
| 142 | close(errs) |
| 143 | }() |
| 144 | |
| 145 | return NewStringChannelWrapperscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/NewStringChannelWrapper().(revs, errs), nil |
| 146 | } |
| 147 | |
| 148 | // indexFile is used when scanning the index. It stores the name of |
| 149 | // the file, the status of the file in the index, and, in the case of |
| 150 | // a moved or copied file, the original name of the file. |
| 151 | type indexFilescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/indexFile# struct { |
| 152 | Namescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/indexFile#Name. string |
| 153 | SrcNamescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/indexFile#SrcName. string |
| 154 | Statusscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/indexFile#Status. string |
| 155 | } |
| 156 | |
| 157 | type indexFileMapscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/indexFileMap# struct { |
| 158 | // mutex guards nameMap and nameShaPairs |
| 159 | mutexscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/indexFileMap#mutex. *syncscip-go gomod github.com/golang/go/src go1.25.0 sync/.Mutexscip-go gomod github.com/golang/go/src go1.25.0 sync/Mutex# |
| 160 | // nameMap maps SHA1s to a slice of `*indexFile`s |
| 161 | nameMapscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/indexFileMap#nameMap. map[string][]*indexFilescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/indexFile# |
| 162 | // nameShaPairs maps "sha1:name" -> bool |
| 163 | nameShaPairsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/indexFileMap#nameShaPairs. map[string]bool |
| 164 | } |
| 165 | |
| 166 | // FilesFor returns all `*indexFile`s that match the given `sha`. |
| 167 | func (m *indexFileMapscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/indexFileMap#) FilesForscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/indexFileMap#FilesFor().(sha string) []*indexFilescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/indexFile# { |
| 168 | m.mutexscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/indexFileMap#mutex..Lockscip-go gomod github.com/golang/go/src go1.25.0 sync/Mutex#Lock().() |
| 169 | defer m.mutexscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/indexFileMap#mutex..Unlockscip-go gomod github.com/golang/go/src go1.25.0 sync/Mutex#Unlock().() |
| 170 | |
| 171 | return m.nameMapscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/indexFileMap#nameMap.[sha] |
| 172 | } |
| 173 | |
| 174 | // Add appends unique index files to the given SHA, "sha". A file is considered |
| 175 | // unique if its combination of SHA and current filename have not yet been seen |
| 176 | // by this instance "m" of *indexFileMap. |
| 177 | func (m *indexFileMapscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/indexFileMap#) Addscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/indexFileMap#Add().(sha string, index *indexFilescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/indexFile#) { |
| 178 | m.mutexscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/indexFileMap#mutex..Lockscip-go gomod github.com/golang/go/src go1.25.0 sync/Mutex#Lock().() |
| 179 | defer m.mutexscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/indexFileMap#mutex..Unlockscip-go gomod github.com/golang/go/src go1.25.0 sync/Mutex#Unlock().() |
| 180 | |
| 181 | pairKey := stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Joinscip-go gomod github.com/golang/go/src go1.25.0 strings/Join().([]string{sha, index.Namescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/indexFile#Name.}, ":") |
| 182 | if m.nameShaPairsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/indexFileMap#nameShaPairs.[pairKey] { |
| 183 | return |
| 184 | } |
| 185 | |
| 186 | m.nameMapscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/indexFileMap#nameMap.[sha] = append(m.nameMapscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/indexFileMap#nameMap.[sha], index) |
| 187 | m.nameShaPairsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/indexFileMap#nameShaPairs.[pairKey] = true |
| 188 | } |