diff options
author | Javi Fontan <jfontan@gmail.com> | 2017-12-20 16:39:45 +0100 |
---|---|---|
committer | Javi Fontan <jfontan@gmail.com> | 2017-12-20 16:39:45 +0100 |
commit | 8f82387beb7ae4ac8936d893f58c6a29992a7050 (patch) | |
tree | 82efa6fafb6f3b4d04da88612eb56558f1c3752e | |
parent | 2787bd71e6564e21cf225971376ba9b62b6d451b (diff) | |
download | go-git-8f82387beb7ae4ac8936d893f58c6a29992a7050.tar.gz |
Make DeltaBaseCache private
Signed-off-by: Javi Fontan <jfontan@gmail.com>
-rw-r--r-- | plumbing/format/packfile/decoder.go | 19 | ||||
-rw-r--r-- | storage/filesystem/object.go | 12 |
2 files changed, 19 insertions, 12 deletions
diff --git a/plumbing/format/packfile/decoder.go b/plumbing/format/packfile/decoder.go index dc39bf1..cb78701 100644 --- a/plumbing/format/packfile/decoder.go +++ b/plumbing/format/packfile/decoder.go @@ -52,7 +52,7 @@ var ( // is destroyed. The Offsets and CRCs are calculated whether an // ObjectStorer was provided or not. type Decoder struct { - DeltaBaseCache cache.Object + deltaBaseCache cache.Object s *Scanner o storer.EncodedObjectStorer @@ -84,6 +84,13 @@ func NewDecoder(s *Scanner, o storer.EncodedObjectStorer) (*Decoder, error) { cache.NewObjectLRUDefault()) } +// NewDecoderWithCache is a version of NewDecoder where cache can be specified. +func NewDecoderWithCache(s *Scanner, o storer.EncodedObjectStorer, + cacheObject cache.Object) (*Decoder, error) { + + return NewDecoderForType(s, o, plumbing.AnyObject, cacheObject) +} + // NewDecoderForType returns a new Decoder but in this case for a specific object type. // When an object is read using this Decoder instance and it is not of the same type of // the specified one, nil will be returned. This is intended to avoid the content @@ -108,7 +115,7 @@ func NewDecoderForType(s *Scanner, o storer.EncodedObjectStorer, return &Decoder{ s: s, o: o, - DeltaBaseCache: cacheObject, + deltaBaseCache: cacheObject, idx: NewIndex(0), offsetToType: make(map[int64]plumbing.ObjectType), @@ -410,19 +417,19 @@ func (d *Decoder) fillOFSDeltaObjectContent(obj plumbing.EncodedObject, offset i } func (d *Decoder) cacheGet(h plumbing.Hash) (plumbing.EncodedObject, bool) { - if d.DeltaBaseCache == nil { + if d.deltaBaseCache == nil { return nil, false } - return d.DeltaBaseCache.Get(h) + return d.deltaBaseCache.Get(h) } func (d *Decoder) cachePut(obj plumbing.EncodedObject) { - if d.DeltaBaseCache == nil { + if d.deltaBaseCache == nil { return } - d.DeltaBaseCache.Put(obj) + d.deltaBaseCache.Put(obj) } func (d *Decoder) recallByOffset(o int64) (plumbing.EncodedObject, error) { diff --git a/storage/filesystem/object.go b/storage/filesystem/object.go index 9c5ca21..3ec7304 100644 --- a/storage/filesystem/object.go +++ b/storage/filesystem/object.go @@ -19,8 +19,8 @@ import ( ) type ObjectStorage struct { - // DeltaBaseCache is an object cache uses to cache delta's bases when - DeltaBaseCache cache.Object + // deltaBaseCache is an object cache uses to cache delta's bases when + deltaBaseCache cache.Object dir *dotgit.DotGit index map[plumbing.Hash]*packfile.Index @@ -28,7 +28,7 @@ type ObjectStorage struct { func newObjectStorage(dir *dotgit.DotGit) (ObjectStorage, error) { s := ObjectStorage{ - DeltaBaseCache: cache.NewObjectLRUDefault(), + deltaBaseCache: cache.NewObjectLRUDefault(), dir: dir, } @@ -285,13 +285,13 @@ func (s *ObjectStorage) decodeObjectAt( p := packfile.NewScanner(f) - d, err := packfile.NewDecoder(p, memory.NewStorage()) + d, err := packfile.NewDecoderWithCache(p, memory.NewStorage(), + s.deltaBaseCache) if err != nil { return nil, err } d.SetIndex(idx) - d.DeltaBaseCache = s.DeltaBaseCache obj, err := d.DecodeObjectAt(offset) return obj, err } @@ -398,7 +398,7 @@ func (s *ObjectStorage) buildPackfileIters(t plumbing.ObjectType, seen map[plumb return nil, err } - iter, err := newPackfileIter(pack, t, seen, s.index[h], s.DeltaBaseCache) + iter, err := newPackfileIter(pack, t, seen, s.index[h], s.deltaBaseCache) if err != nil { return nil, err } |