Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

Commit 930ff6a

Browse files
committed
Combine deltaBaseCache and simpleObjectCache into one objectCache.
Signed-off-by: Filip Navara <[email protected]>
1 parent 08b8c74 commit 930ff6a

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

storage/filesystem/object.go

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,25 @@ import (
2020
type ObjectStorage struct {
2121
options Options
2222

23-
// deltaBaseCache is an object cache uses to cache delta's bases when
24-
deltaBaseCache cache.Object
25-
26-
simpleObjectCache cache.Object
23+
// objectCache is an object cache uses to cache delta's bases and also recently
24+
// loaded loose objects
25+
objectCache cache.Object
2726

2827
dir *dotgit.DotGit
2928
index map[plumbing.Hash]idxfile.Index
3029
}
3130

3231
// NewObjectStorage creates a new ObjectStorage with the given .git directory and cache.
33-
func NewObjectStorage(dir *dotgit.DotGit, deltaBaseCache cache.Object) *ObjectStorage {
34-
return NewObjectStorageWithOptions(dir, deltaBaseCache, Options{})
32+
func NewObjectStorage(dir *dotgit.DotGit, objectCache cache.Object) *ObjectStorage {
33+
return NewObjectStorageWithOptions(dir, objectCache, Options{})
3534
}
3635

3736
// NewObjectStorageWithOptions creates a new ObjectStorage with the given .git directory, cache and extra options
38-
func NewObjectStorageWithOptions(dir *dotgit.DotGit, deltaBaseCache cache.Object, ops Options) *ObjectStorage {
37+
func NewObjectStorageWithOptions(dir *dotgit.DotGit, objectCache cache.Object, ops Options) *ObjectStorage {
3938
return &ObjectStorage{
40-
options: ops,
41-
deltaBaseCache: deltaBaseCache,
42-
simpleObjectCache: cache.NewObjectLRU(cache.MiByte),
43-
dir: dir,
39+
options: ops,
40+
objectCache: objectCache,
41+
dir: dir,
4442
}
4543
}
4644

@@ -189,7 +187,7 @@ func (s *ObjectStorage) EncodedObject(t plumbing.ObjectType, h plumbing.Hash) (p
189187
// Create a new object storage with the DotGit(s) and check for the
190188
// required hash object. Skip when not found.
191189
for _, dg := range dotgits {
192-
o := NewObjectStorage(dg, s.deltaBaseCache)
190+
o := NewObjectStorage(dg, s.objectCache)
193191
enobj, enerr := o.EncodedObject(t, h)
194192
if enerr != nil {
195193
continue
@@ -231,7 +229,7 @@ func (s *ObjectStorage) DeltaObject(t plumbing.ObjectType,
231229
}
232230

233231
func (s *ObjectStorage) getFromUnpacked(h plumbing.Hash) (obj plumbing.EncodedObject, err error) {
234-
if cacheObj, found := s.simpleObjectCache.Get(h); found {
232+
if cacheObj, found := s.objectCache.Get(h); found {
235233
return cacheObj, nil
236234
}
237235

@@ -266,7 +264,7 @@ func (s *ObjectStorage) getFromUnpacked(h plumbing.Hash) (obj plumbing.EncodedOb
266264
return nil, err
267265
}
268266

269-
s.simpleObjectCache.Put(obj);
267+
s.objectCache.Put(obj);
270268

271269
_, err = io.Copy(w, r)
272270
return obj, err
@@ -310,7 +308,7 @@ func (s *ObjectStorage) decodeObjectAt(
310308
) (plumbing.EncodedObject, error) {
311309
hash, err := idx.FindHash(offset)
312310
if err == nil {
313-
obj, ok := s.deltaBaseCache.Get(hash)
311+
obj, ok := s.objectCache.Get(hash)
314312
if ok {
315313
return obj, nil
316314
}
@@ -321,8 +319,8 @@ func (s *ObjectStorage) decodeObjectAt(
321319
}
322320

323321
var p *packfile.Packfile
324-
if s.deltaBaseCache != nil {
325-
p = packfile.NewPackfileWithCache(idx, s.dir.Fs(), f, s.deltaBaseCache)
322+
if s.objectCache != nil {
323+
p = packfile.NewPackfileWithCache(idx, s.dir.Fs(), f, s.objectCache)
326324
} else {
327325
p = packfile.NewPackfile(idx, s.dir.Fs(), f)
328326
}
@@ -432,7 +430,7 @@ func (s *ObjectStorage) buildPackfileIters(
432430
}
433431
return newPackfileIter(
434432
s.dir.Fs(), pack, t, seen, s.index[h],
435-
s.deltaBaseCache, s.options.KeepDescriptors,
433+
s.objectCache, s.options.KeepDescriptors,
436434
)
437435
},
438436
}, nil

0 commit comments

Comments
 (0)