This repository was archived by the owner on Sep 11, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +21
-5
lines changed Expand file tree Collapse file tree 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,
307307}
308308
309309func (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-
314310 f , err := s .dir .Object (h )
315311 if err != nil {
316312 if os .IsNotExist (err ) {
@@ -319,9 +315,12 @@ func (s *ObjectStorage) getFromUnpacked(h plumbing.Hash) (obj plumbing.EncodedOb
319315
320316 return nil , err
321317 }
322-
323318 defer ioutil .CheckClose (f , & err )
324319
320+ if cacheObj , found := s .objectCache .Get (h ); found {
321+ return cacheObj , nil
322+ }
323+
325324 obj = s .NewEncodedObject ()
326325 r , err := objfile .NewReader (f )
327326 if err != nil {
Original file line number Diff line number Diff line change @@ -297,6 +297,23 @@ func (s *FsSuite) TestPackfileIterKeepDescriptors(c *C) {
297297 })
298298}
299299
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+
300317func BenchmarkPackfileIter (b * testing.B ) {
301318 if err := fixtures .Init (); err != nil {
302319 b .Fatal (err )
You can’t perform that action at this time.
0 commit comments