aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/format/packfile/common.go
diff options
context:
space:
mode:
authorMiguel Molina <miguel@erizocosmi.co>2018-08-08 16:56:20 +0200
committerMiguel Molina <miguel@erizocosmi.co>2018-08-08 16:56:20 +0200
commit5889a3b669f0f515ff445aa040afc1e7eeb2bbd1 (patch)
tree1a7e2bbe9ba7c2ae1111120ed84fe7850a934375 /plumbing/format/packfile/common.go
parent6a24b4c1f0cb9e5daf30fa7979f2643a967af1ad (diff)
downloadgo-git-5889a3b669f0f515ff445aa040afc1e7eeb2bbd1.tar.gz
plumbing: packfile, allow non-seekable sources on Parser
Signed-off-by: Miguel Molina <miguel@erizocosmi.co>
Diffstat (limited to 'plumbing/format/packfile/common.go')
-rw-r--r--plumbing/format/packfile/common.go63
1 files changed, 6 insertions, 57 deletions
diff --git a/plumbing/format/packfile/common.go b/plumbing/format/packfile/common.go
index 76254f0..2b4aceb 100644
--- a/plumbing/format/packfile/common.go
+++ b/plumbing/format/packfile/common.go
@@ -2,11 +2,9 @@ package packfile
import (
"bytes"
- "errors"
"io"
"sync"
- "gopkg.in/src-d/go-git.v4/plumbing"
"gopkg.in/src-d/go-git.v4/plumbing/storer"
"gopkg.in/src-d/go-git.v4/utils/ioutil"
)
@@ -32,8 +30,12 @@ func UpdateObjectStorage(s storer.Storer, packfile io.Reader) error {
return WritePackfileToObjectStorage(pw, packfile)
}
- updater := newPackfileStorageUpdater(s)
- _, err := NewParser(NewScanner(packfile), updater).Parse()
+ p, err := NewParserWithStorage(NewScanner(packfile), s)
+ if err != nil {
+ return err
+ }
+
+ _, err = p.Parse()
return err
}
@@ -58,56 +60,3 @@ var bufPool = sync.Pool{
return bytes.NewBuffer(nil)
},
}
-
-var errMissingObjectContent = errors.New("missing object content")
-
-type packfileStorageUpdater struct {
- storer.Storer
- lastSize int64
- lastType plumbing.ObjectType
-}
-
-func newPackfileStorageUpdater(s storer.Storer) *packfileStorageUpdater {
- return &packfileStorageUpdater{Storer: s}
-}
-
-func (p *packfileStorageUpdater) OnHeader(count uint32) error {
- return nil
-}
-
-func (p *packfileStorageUpdater) OnInflatedObjectHeader(
- t plumbing.ObjectType,
- objSize int64,
- pos int64,
-) error {
- if p.lastSize > 0 || p.lastType != plumbing.InvalidObject {
- return errMissingObjectContent
- }
-
- p.lastType = t
- p.lastSize = objSize
- return nil
-}
-
-func (p *packfileStorageUpdater) OnInflatedObjectContent(
- h plumbing.Hash,
- pos int64,
- crc uint32,
- content []byte,
-) error {
- obj := new(plumbing.MemoryObject)
- obj.SetSize(p.lastSize)
- obj.SetType(p.lastType)
- if _, err := obj.Write(content); err != nil {
- return err
- }
-
- _, err := p.SetEncodedObject(obj)
- p.lastSize = 0
- p.lastType = plumbing.InvalidObject
- return err
-}
-
-func (p *packfileStorageUpdater) OnFooter(h plumbing.Hash) error {
- return nil
-}