This repository was archived by the owner on Sep 11, 2020. It is now read-only.
File tree 2 files changed +21
-5
lines changed
2 files changed +21
-5
lines changed Original file line number Diff line number Diff line change @@ -307,10 +307,6 @@ func (s *ObjectStorage) DeltaObject(t plumbing.ObjectType,
307
307
}
308
308
309
309
func (s * ObjectStorage ) getFromUnpacked (h plumbing.Hash ) (obj plumbing.EncodedObject , err error ) {
310
- if cacheObj , found := s .objectCache .Get (h ); found {
311
- return cacheObj , nil
312
- }
313
-
314
310
f , err := s .dir .Object (h )
315
311
if err != nil {
316
312
if os .IsNotExist (err ) {
@@ -319,9 +315,12 @@ func (s *ObjectStorage) getFromUnpacked(h plumbing.Hash) (obj plumbing.EncodedOb
319
315
320
316
return nil , err
321
317
}
322
-
323
318
defer ioutil .CheckClose (f , & err )
324
319
320
+ if cacheObj , found := s .objectCache .Get (h ); found {
321
+ return cacheObj , nil
322
+ }
323
+
325
324
obj = s .NewEncodedObject ()
326
325
r , err := objfile .NewReader (f )
327
326
if err != nil {
Original file line number Diff line number Diff line change @@ -297,6 +297,23 @@ func (s *FsSuite) TestPackfileIterKeepDescriptors(c *C) {
297
297
})
298
298
}
299
299
300
+ func (s * FsSuite ) TestGetFromObjectFileSharedCache (c * C ) {
301
+ f1 := fixtures .ByTag ("worktree" ).One ().DotGit ()
302
+ f2 := fixtures .ByTag ("worktree" ).ByTag ("submodule" ).One ().DotGit ()
303
+
304
+ ch := cache .NewObjectLRUDefault ()
305
+ o1 := NewObjectStorage (dotgit .New (f1 ), ch )
306
+ o2 := NewObjectStorage (dotgit .New (f2 ), ch )
307
+
308
+ expected := plumbing .NewHash ("af2d6a6954d532f8ffb47615169c8fdf9d383a1a" )
309
+ obj , err := o1 .EncodedObject (plumbing .CommitObject , expected )
310
+ c .Assert (err , IsNil )
311
+ c .Assert (obj .Hash (), Equals , expected )
312
+
313
+ obj , err = o2 .EncodedObject (plumbing .CommitObject , expected )
314
+ c .Assert (err , Equals , plumbing .ErrObjectNotFound )
315
+ }
316
+
300
317
func BenchmarkPackfileIter (b * testing.B ) {
301
318
if err := fixtures .Init (); err != nil {
302
319
b .Fatal (err )
You can’t perform that action at this time.
0 commit comments