diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2018-08-23 01:23:23 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-23 01:23:23 +0200 |
commit | 005d5dc961a7053d88da53536f4a5eb4c305529b (patch) | |
tree | d73393383d45b3769c1fb63903a6cf2b02b8d1aa /plumbing/format | |
parent | cdfa0bb8d987272b5729e565dbcc64f07963d77d (diff) | |
parent | 790191ef92ec6382ce65cc30286c901863b3b7a3 (diff) | |
download | go-git-005d5dc961a7053d88da53536f4a5eb4c305529b.tar.gz |
Merge pull request #929 from jfontan/fix/reuse-base-cache
plumbing, storage: add bases to the common cache
Diffstat (limited to 'plumbing/format')
-rw-r--r-- | plumbing/format/packfile/fsobject.go | 10 | ||||
-rw-r--r-- | plumbing/format/packfile/packfile.go | 15 |
2 files changed, 25 insertions, 0 deletions
diff --git a/plumbing/format/packfile/fsobject.go b/plumbing/format/packfile/fsobject.go index 6fd3ca5..330cb73 100644 --- a/plumbing/format/packfile/fsobject.go +++ b/plumbing/format/packfile/fsobject.go @@ -47,6 +47,16 @@ func NewFSObject( // Reader implements the plumbing.EncodedObject interface. func (o *FSObject) Reader() (io.ReadCloser, error) { + obj, ok := o.cache.Get(o.hash) + if ok { + reader, err := obj.Reader() + if err != nil { + return nil, err + } + + return reader, nil + } + f, err := o.fs.Open(o.path) if err != nil { return nil, err diff --git a/plumbing/format/packfile/packfile.go b/plumbing/format/packfile/packfile.go index 18fcca7..852a834 100644 --- a/plumbing/format/packfile/packfile.go +++ b/plumbing/format/packfile/packfile.go @@ -258,6 +258,19 @@ func (p *Packfile) nextObject() (plumbing.EncodedObject, error) { } func (p *Packfile) getObjectContent(offset int64) (io.ReadCloser, error) { + ref, err := p.FindHash(offset) + if err == nil { + obj, ok := p.cacheGet(ref) + if ok { + reader, err := obj.Reader() + if err != nil { + return nil, err + } + + return reader, nil + } + } + if _, err := p.s.SeekFromStart(offset); err != nil { return nil, err } @@ -306,6 +319,8 @@ func (p *Packfile) fillRegularObjectContent(obj plumbing.EncodedObject) error { } _, _, err = p.s.NextObject(w) + p.cachePut(obj) + return err } |