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

plumbing: packfile, apply small object reading optimization also for delta objects #1121

Merged
merged 12 commits into from
Apr 24, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Rename functions
Signed-off-by: Filip Navara <[email protected]>
  • Loading branch information
filipnavara committed Apr 23, 2019
commit 38c061e66678b4e6b92798796973b6f9335df10e
16 changes: 9 additions & 7 deletions plumbing/format/packfile/packfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,16 +196,16 @@ func (p *Packfile) objectAtOffset(offset int64, hash plumbing.Hash) (plumbing.En
return nil, err
}

return p.getNextObjectLazy(h, hash)
return p.getNextObject(h, hash)
}

func (p *Packfile) getNextObjectLazy(h *ObjectHeader, hash plumbing.Hash) (plumbing.EncodedObject, error) {
func (p *Packfile) getNextObject(h *ObjectHeader, hash plumbing.Hash) (plumbing.EncodedObject, error) {
var err error

// If we have no filesystem, we will return a MemoryObject instead
// of an FSObject.
if p.fs == nil {
return p.getNextObject(h)
return p.getNextMemoryObject(h)
}

// If the object is small enough then read it completely into memory now since
Expand All @@ -215,7 +215,7 @@ func (p *Packfile) getNextObjectLazy(h *ObjectHeader, hash plumbing.Hash) (plumb
var size int64
if h.Length <= smallObjectThreshold {
if h.Type != plumbing.OFSDeltaObject && h.Type != plumbing.REFDeltaObject {
return p.getNextObject(h)
return p.getNextMemoryObject(h)
}

// For delta objects we read the delta data and apply the small object
Expand Down Expand Up @@ -284,15 +284,17 @@ func (p *Packfile) getObjectContent(offset int64) (io.ReadCloser, error) {
return nil, err
}

obj, err := p.getNextObject(h)
// getObjectContent is called from FSObject, so we have to explicitly
// get memory object here to avoid recursive cycle
obj, err := p.getNextMemoryObject(h)
if err != nil {
return nil, err
}

return obj.Reader()
}

func (p *Packfile) getNextObject(h *ObjectHeader) (plumbing.EncodedObject, error) {
func (p *Packfile) getNextMemoryObject(h *ObjectHeader) (plumbing.EncodedObject, error) {
var obj = new(plumbing.MemoryObject)
obj.SetSize(h.Length)
obj.SetType(h.Type)
Expand Down Expand Up @@ -498,7 +500,7 @@ func (i *objectIter) Next() (plumbing.EncodedObject, error) {
continue
}

return i.p.getNextObjectLazy(h, e.Hash)
return i.p.getNextObject(h, e.Hash)
}
}

Expand Down