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