diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2018-09-08 09:31:20 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-08 09:31:20 +0200 |
commit | 208b3c3c32beaab14ebb7adf162fc136c939e99c (patch) | |
tree | 33e2e984150cebe2105d84479538128bfaf2ff93 /storage/filesystem/object.go | |
parent | a4b12e4161738af6f724776c0c8c55f90542f06f (diff) | |
parent | 8f6b3127c1ff7661113fff2662416c328971a285 (diff) | |
download | go-git-208b3c3c32beaab14ebb7adf162fc136c939e99c.tar.gz |
Merge pull request #949 from kuba--/custom-cache
Expose Storage cache.
Diffstat (limited to 'storage/filesystem/object.go')
-rw-r--r-- | storage/filesystem/object.go | 29 |
1 files changed, 10 insertions, 19 deletions
diff --git a/storage/filesystem/object.go b/storage/filesystem/object.go index 3545e27..9eb085f 100644 --- a/storage/filesystem/object.go +++ b/storage/filesystem/object.go @@ -27,24 +27,18 @@ type ObjectStorage struct { index map[plumbing.Hash]idxfile.Index } -// NewObjectStorage creates a new ObjectStorage with the given .git directory. -func NewObjectStorage(dir *dotgit.DotGit) (ObjectStorage, error) { - return NewObjectStorageWithOptions(dir, Options{}) -} - -// NewObjectStorageWithOptions creates a new ObjectStorage with the given .git -// directory and sets its options. -func NewObjectStorageWithOptions( - dir *dotgit.DotGit, - ops Options, -) (ObjectStorage, error) { - s := ObjectStorage{ +// NewObjectStorage creates a new ObjectStorage with the given .git directory and cache. +func NewObjectStorage(dir *dotgit.DotGit, cache cache.Object) *ObjectStorage { + return NewObjectStorageWithOptions(dir, cache, Options{}) +} + +// NewObjectStorageWithOptions creates a new ObjectStorage with the given .git directory, cache and extra options +func NewObjectStorageWithOptions(dir *dotgit.DotGit, cache cache.Object, ops Options) *ObjectStorage { + return &ObjectStorage{ options: ops, - deltaBaseCache: cache.NewObjectLRUDefault(), + deltaBaseCache: cache, dir: dir, } - - return s, nil } func (s *ObjectStorage) requireIndex() error { @@ -182,10 +176,7 @@ func (s *ObjectStorage) EncodedObject(t plumbing.ObjectType, h plumbing.Hash) (p // Create a new object storage with the DotGit(s) and check for the // required hash object. Skip when not found. for _, dg := range dotgits { - o, oe := NewObjectStorage(dg) - if oe != nil { - continue - } + o := NewObjectStorage(dg, s.deltaBaseCache) enobj, enerr := o.EncodedObject(t, h) if enerr != nil { continue |