| 248 | } |
| 249 | |
| 250 | func (s *ObjectStorage) storePackfileInCache(hash plumbing.Hash, p *packfile.Packfile) error { |
| 251 | if s.options.KeepDescriptors { |
| 252 | s.packfiles[hash] = p |
| 253 | return nil |
| 254 | } |
| 255 | |
| 256 | if s.options.MaxOpenDescriptors <= 0 { |
| 257 | return nil |
| 258 | } |
| 259 | |
| 260 | // start over as the limit of packList is hit |
| 261 | if s.packListIdx >= len(s.packList) { |
| 262 | s.packListIdx = 0 |
| 263 | } |
| 264 | |
| 265 | // close the existing packfile if open |
| 266 | if next := s.packList[s.packListIdx]; !next.IsZero() { |
| 267 | open := s.packfiles[next] |
| 268 | delete(s.packfiles, next) |
| 269 | if open != nil { |
| 270 | if err := open.Close(); err != nil { |
| 271 | return err |
| 272 | } |
| 273 | } |
| 274 | } |
| 275 | |
| 276 | // cache newly open packfile |
| 277 | s.packList[s.packListIdx] = hash |
| 278 | s.packfiles[hash] = p |
| 279 | s.packListIdx++ |
| 280 | |
| 281 | return nil |
| 282 | } |
| 283 | |
| 284 | func (s *ObjectStorage) encodedObjectSizeFromPackfile(h plumbing.Hash) ( |
| 285 | size int64, err error, |