aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/format/packfile
diff options
context:
space:
mode:
authorSantiago M. Mola <santi@mola.io>2016-12-14 23:12:44 +0100
committerMáximo Cuadros <mcuadros@gmail.com>2016-12-14 23:12:44 +0100
commit0af572dd21c0aa79d13745b633ee24ba6c4d6cf1 (patch)
tree49e81e74e82d84fd88b2fc1e4b0dc7c7bfe9c40f /plumbing/format/packfile
parentdf0f38af83f972f026d7e14150f3d37b95f13484 (diff)
downloadgo-git-0af572dd21c0aa79d13745b633ee24ba6c4d6cf1.tar.gz
move plumbing from top level package to plumbing (#183)
* plumbing: rename Object -> EncodedObject. * plumbing/storer: rename ObjectStorer -> EncodedObjectStorer. * move difftree to plumbing/difftree. * move diff -> utils/diff * make Object/Tag/Blob/Tree/Commit/File depend on storer. * Object and its implementations now depend only on storer.EncodedObjectStorer, not git.Repository. * Tests are decoupled accordingly. * move Object/Commit/File/Tag/Tree to plumbing/object. * move Object/Commit/File/Tag/Tree to plumbing/object. * move checkClose to utils/ioutil. * move RevListObjects to plumbing/revlist.Objects. * move DiffTree to plumbing/difftree package. * rename files with plural nouns to singular * plumbing/object: add GetBlob/GetCommit/GetTag/GetTree.
Diffstat (limited to 'plumbing/format/packfile')
-rw-r--r--plumbing/format/packfile/decoder.go34
-rw-r--r--plumbing/format/packfile/decoder_test.go12
-rw-r--r--plumbing/format/packfile/diff_delta.go6
-rw-r--r--plumbing/format/packfile/encoder.go6
-rw-r--r--plumbing/format/packfile/encoder_test.go34
-rw-r--r--plumbing/format/packfile/object_pack.go11
-rw-r--r--plumbing/format/packfile/patch_delta.go2
7 files changed, 53 insertions, 52 deletions
diff --git a/plumbing/format/packfile/decoder.go b/plumbing/format/packfile/decoder.go
index 4ab8eb0..59a2f8d 100644
--- a/plumbing/format/packfile/decoder.go
+++ b/plumbing/format/packfile/decoder.go
@@ -52,7 +52,7 @@ var (
// ObjectStorer was provided or not.
type Decoder struct {
s *Scanner
- o storer.ObjectStorer
+ o storer.EncodedObjectStorer
tx storer.Transaction
isDecoded bool
@@ -71,7 +71,7 @@ type Decoder struct {
//
// If the ObjectStorer implements storer.Transactioner, a transaction is created
// during the Decode execution, if something fails the Rollback is called
-func NewDecoder(s *Scanner, o storer.ObjectStorer) (*Decoder, error) {
+func NewDecoder(s *Scanner, o storer.EncodedObjectStorer) (*Decoder, error) {
if !canResolveDeltas(s, o) {
return nil, ErrResolveDeltasNotSupported
}
@@ -86,7 +86,7 @@ func NewDecoder(s *Scanner, o storer.ObjectStorer) (*Decoder, error) {
}, nil
}
-func canResolveDeltas(s *Scanner, o storer.ObjectStorer) bool {
+func canResolveDeltas(s *Scanner, o storer.EncodedObjectStorer) bool {
return s.IsSeekable || o != nil
}
@@ -140,7 +140,7 @@ func (d *Decoder) decodeObjectsWithObjectStorer(count int) error {
return err
}
- if _, err := d.o.SetObject(obj); err != nil {
+ if _, err := d.o.SetEncodedObject(obj); err != nil {
return err
}
}
@@ -157,7 +157,7 @@ func (d *Decoder) decodeObjectsWithObjectStorerTx(count int) error {
return err
}
- if _, err := d.tx.SetObject(obj); err != nil {
+ if _, err := d.tx.SetEncodedObject(obj); err != nil {
if rerr := d.tx.Rollback(); rerr != nil {
return ErrRollback.AddDetails(
"error: %s, during tx.Set error: %s", rerr, err,
@@ -175,7 +175,7 @@ func (d *Decoder) decodeObjectsWithObjectStorerTx(count int) error {
// DecodeObject reads the next object from the scanner and returns it. This
// method can be used in replacement of the Decode method, to work in a
// interative way
-func (d *Decoder) DecodeObject() (plumbing.Object, error) {
+func (d *Decoder) DecodeObject() (plumbing.EncodedObject, error) {
h, err := d.s.NextObjectHeader()
if err != nil {
return nil, err
@@ -207,17 +207,17 @@ func (d *Decoder) DecodeObject() (plumbing.Object, error) {
return obj, nil
}
-func (d *Decoder) newObject() plumbing.Object {
+func (d *Decoder) newObject() plumbing.EncodedObject {
if d.o == nil {
return &plumbing.MemoryObject{}
}
- return d.o.NewObject()
+ return d.o.NewEncodedObject()
}
// DecodeObjectAt reads an object at the given location, if Decode wasn't called
// previously objects offset should provided using the SetOffsets method
-func (d *Decoder) DecodeObjectAt(offset int64) (plumbing.Object, error) {
+func (d *Decoder) DecodeObjectAt(offset int64) (plumbing.EncodedObject, error) {
if !d.s.IsSeekable {
return nil, ErrNonSeekable
}
@@ -237,7 +237,7 @@ func (d *Decoder) DecodeObjectAt(offset int64) (plumbing.Object, error) {
return d.DecodeObject()
}
-func (d *Decoder) fillRegularObjectContent(obj plumbing.Object) (uint32, error) {
+func (d *Decoder) fillRegularObjectContent(obj plumbing.EncodedObject) (uint32, error) {
w, err := obj.Writer()
if err != nil {
return 0, err
@@ -247,7 +247,7 @@ func (d *Decoder) fillRegularObjectContent(obj plumbing.Object) (uint32, error)
return crc, err
}
-func (d *Decoder) fillREFDeltaObjectContent(obj plumbing.Object, ref plumbing.Hash) (uint32, error) {
+func (d *Decoder) fillREFDeltaObjectContent(obj plumbing.EncodedObject, ref plumbing.Hash) (uint32, error) {
buf := bytes.NewBuffer(nil)
_, crc, err := d.s.NextObject(buf)
if err != nil {
@@ -263,7 +263,7 @@ func (d *Decoder) fillREFDeltaObjectContent(obj plumbing.Object, ref plumbing.Ha
return crc, ApplyDelta(obj, base, buf.Bytes())
}
-func (d *Decoder) fillOFSDeltaObjectContent(obj plumbing.Object, offset int64) (uint32, error) {
+func (d *Decoder) fillOFSDeltaObjectContent(obj plumbing.EncodedObject, offset int64) (uint32, error) {
buf := bytes.NewBuffer(nil)
_, crc, err := d.s.NextObject(buf)
if err != nil {
@@ -288,7 +288,7 @@ func (d *Decoder) setCRC(h plumbing.Hash, crc uint32) {
d.crcs[h] = crc
}
-func (d *Decoder) recallByOffset(o int64) (plumbing.Object, error) {
+func (d *Decoder) recallByOffset(o int64) (plumbing.EncodedObject, error) {
if d.s.IsSeekable {
return d.DecodeObjectAt(o)
}
@@ -300,7 +300,7 @@ func (d *Decoder) recallByOffset(o int64) (plumbing.Object, error) {
return nil, plumbing.ErrObjectNotFound
}
-func (d *Decoder) recallByHash(h plumbing.Hash) (plumbing.Object, error) {
+func (d *Decoder) recallByHash(h plumbing.Hash) (plumbing.EncodedObject, error) {
if d.s.IsSeekable {
if o, ok := d.hashToOffset[h]; ok {
return d.DecodeObjectAt(o)
@@ -312,11 +312,11 @@ func (d *Decoder) recallByHash(h plumbing.Hash) (plumbing.Object, error) {
// recallByHashNonSeekable if we are in a transaction the objects are read from
// the transaction, if not are directly read from the ObjectStorer
-func (d *Decoder) recallByHashNonSeekable(h plumbing.Hash) (obj plumbing.Object, err error) {
+func (d *Decoder) recallByHashNonSeekable(h plumbing.Hash) (obj plumbing.EncodedObject, err error) {
if d.tx != nil {
- obj, err = d.tx.Object(plumbing.AnyObject, h)
+ obj, err = d.tx.EncodedObject(plumbing.AnyObject, h)
} else {
- obj, err = d.o.Object(plumbing.AnyObject, h)
+ obj, err = d.o.EncodedObject(plumbing.AnyObject, h)
}
if err != plumbing.ErrObjectNotFound {
diff --git a/plumbing/format/packfile/decoder_test.go b/plumbing/format/packfile/decoder_test.go
index 865cdae..fdf4c96 100644
--- a/plumbing/format/packfile/decoder_test.go
+++ b/plumbing/format/packfile/decoder_test.go
@@ -95,7 +95,7 @@ func (s *ReaderSuite) TestDecodeNoSeekableWithTxStorer(c *C) {
scanner := packfile.NewScanner(reader)
- var storage storer.ObjectStorer = memory.NewStorage()
+ var storage storer.EncodedObjectStorer = memory.NewStorage()
_, isTxStorer := storage.(storer.Transactioner)
c.Assert(isTxStorer, Equals, true)
@@ -119,7 +119,7 @@ func (s *ReaderSuite) TestDecodeNoSeekableWithoutTxStorer(c *C) {
scanner := packfile.NewScanner(reader)
- var storage storer.ObjectStorer
+ var storage storer.EncodedObjectStorer
storage, _ = filesystem.NewStorage(fs.New())
_, isTxStorer := storage.(storer.Transactioner)
c.Assert(isTxStorer, Equals, false)
@@ -236,18 +236,18 @@ func (s *ReaderSuite) TestSetOffsets(c *C) {
c.Assert(o[h], Equals, int64(42))
}
-func assertObjects(c *C, s storer.ObjectStorer, expects []string) {
+func assertObjects(c *C, s storer.EncodedObjectStorer, expects []string) {
- i, err := s.IterObjects(plumbing.AnyObject)
+ i, err := s.IterEncodedObjects(plumbing.AnyObject)
c.Assert(err, IsNil)
var count int
- err = i.ForEach(func(plumbing.Object) error { count++; return nil })
+ err = i.ForEach(func(plumbing.EncodedObject) error { count++; return nil })
c.Assert(err, IsNil)
c.Assert(count, Equals, len(expects))
for _, exp := range expects {
- obt, err := s.Object(plumbing.AnyObject, plumbing.NewHash(exp))
+ obt, err := s.EncodedObject(plumbing.AnyObject, plumbing.NewHash(exp))
c.Assert(err, IsNil)
c.Assert(obt.Hash().String(), Equals, exp)
}
diff --git a/plumbing/format/packfile/diff_delta.go b/plumbing/format/packfile/diff_delta.go
index fb05a79..bc4fafa 100644
--- a/plumbing/format/packfile/diff_delta.go
+++ b/plumbing/format/packfile/diff_delta.go
@@ -17,17 +17,17 @@ const (
// GetOFSDelta returns an offset delta that knows the way of how to transform
// base object to target object
-func GetOFSDelta(base, target plumbing.Object) (plumbing.Object, error) {
+func GetOFSDelta(base, target plumbing.EncodedObject) (plumbing.EncodedObject, error) {
return getDelta(base, target, plumbing.OFSDeltaObject)
}
// GetRefDelta returns a reference delta that knows the way of how to transform
// base object to target object
-func GetRefDelta(base, target plumbing.Object) (plumbing.Object, error) {
+func GetRefDelta(base, target plumbing.EncodedObject) (plumbing.EncodedObject, error) {
return getDelta(base, target, plumbing.REFDeltaObject)
}
-func getDelta(base, target plumbing.Object, t plumbing.ObjectType) (plumbing.Object, error) {
+func getDelta(base, target plumbing.EncodedObject, t plumbing.ObjectType) (plumbing.EncodedObject, error) {
if t != plumbing.OFSDeltaObject && t != plumbing.REFDeltaObject {
return nil, fmt.Errorf("Type not supported: %v", t)
}
diff --git a/plumbing/format/packfile/encoder.go b/plumbing/format/packfile/encoder.go
index eb1c532..847e9e1 100644
--- a/plumbing/format/packfile/encoder.go
+++ b/plumbing/format/packfile/encoder.go
@@ -14,7 +14,7 @@ import (
// Encoder gets the data from the storage and write it into the writer in PACK
// format
type Encoder struct {
- storage storer.ObjectStorer
+ storage storer.EncodedObjectStorer
w *offsetWriter
zw *zlib.Writer
hasher plumbing.Hasher
@@ -23,7 +23,7 @@ type Encoder struct {
// NewEncoder creates a new packfile encoder using a specific Writer and
// ObjectStorer
-func NewEncoder(w io.Writer, s storer.ObjectStorer) *Encoder {
+func NewEncoder(w io.Writer, s storer.EncodedObjectStorer) *Encoder {
h := plumbing.Hasher{
Hash: sha1.New(),
}
@@ -44,7 +44,7 @@ func NewEncoder(w io.Writer, s storer.ObjectStorer) *Encoder {
func (e *Encoder) Encode(hashes []plumbing.Hash) (plumbing.Hash, error) {
var objects []*ObjectToPack
for _, h := range hashes {
- o, err := e.storage.Object(plumbing.AnyObject, h)
+ o, err := e.storage.EncodedObject(plumbing.AnyObject, h)
if err != nil {
return plumbing.ZeroHash, err
}
diff --git a/plumbing/format/packfile/encoder_test.go b/plumbing/format/packfile/encoder_test.go
index b07e2f4..1a94d16 100644
--- a/plumbing/format/packfile/encoder_test.go
+++ b/plumbing/format/packfile/encoder_test.go
@@ -44,7 +44,7 @@ func (s *EncoderSuite) TestCorrectPackWithOneEmptyObject(c *C) {
o := &plumbing.MemoryObject{}
o.SetType(plumbing.CommitObject)
o.SetSize(0)
- _, err := s.store.SetObject(o)
+ _, err := s.store.SetEncodedObject(o)
c.Assert(err, IsNil)
hash, err := s.enc.Encode([]plumbing.Hash{o.Hash()})
@@ -69,10 +69,10 @@ func (s *EncoderSuite) TestCorrectPackWithOneEmptyObject(c *C) {
}
func (s *EncoderSuite) TestMaxObjectSize(c *C) {
- o := s.store.NewObject()
+ o := s.store.NewEncodedObject()
o.SetSize(9223372036854775807)
o.SetType(plumbing.CommitObject)
- _, err := s.store.SetObject(o)
+ _, err := s.store.SetEncodedObject(o)
c.Assert(err, IsNil)
hash, err := s.enc.Encode([]plumbing.Hash{o.Hash()})
c.Assert(err, IsNil)
@@ -98,14 +98,14 @@ func (s *EncoderSuite) TestDecodeEncodeDecode(c *C) {
c.Assert(err, IsNil)
c.Assert(ch, Equals, f.PackfileHash)
- objIter, err := d.o.IterObjects(plumbing.AnyObject)
+ objIter, err := d.o.IterEncodedObjects(plumbing.AnyObject)
c.Assert(err, IsNil)
- objects := []plumbing.Object{}
+ objects := []plumbing.EncodedObject{}
hashes := []plumbing.Hash{}
- err = objIter.ForEach(func(o plumbing.Object) error {
+ err = objIter.ForEach(func(o plumbing.EncodedObject) error {
objects = append(objects, o)
- hash, err := s.store.SetObject(o)
+ hash, err := s.store.SetEncodedObject(o)
c.Assert(err, IsNil)
hashes = append(hashes, hash)
@@ -124,10 +124,10 @@ func (s *EncoderSuite) TestDecodeEncodeDecode(c *C) {
_, err = d.Decode()
c.Assert(err, IsNil)
- objIter, err = d.o.IterObjects(plumbing.AnyObject)
+ objIter, err = d.o.IterEncodedObjects(plumbing.AnyObject)
c.Assert(err, IsNil)
- obtainedObjects := []plumbing.Object{}
- err = objIter.ForEach(func(o plumbing.Object) error {
+ obtainedObjects := []plumbing.EncodedObject{}
+ err = objIter.ForEach(func(o plumbing.EncodedObject) error {
obtainedObjects = append(obtainedObjects, o)
return nil
@@ -187,11 +187,11 @@ func (s *EncoderSuite) simpleDeltaTest(c *C, t plumbing.ObjectType) {
_, err = d.Decode()
c.Assert(err, IsNil)
- decSrc, err := storage.Object(srcObject.Type(), srcObject.Hash())
+ decSrc, err := storage.EncodedObject(srcObject.Type(), srcObject.Hash())
c.Assert(err, IsNil)
c.Assert(decSrc, DeepEquals, srcObject)
- decTarget, err := storage.Object(targetObject.Type(), targetObject.Hash())
+ decTarget, err := storage.EncodedObject(targetObject.Type(), targetObject.Hash())
c.Assert(err, IsNil)
c.Assert(decTarget, DeepEquals, targetObject)
}
@@ -226,20 +226,20 @@ func (s *EncoderSuite) deltaOverDeltaTest(c *C, t plumbing.ObjectType) {
_, err = d.Decode()
c.Assert(err, IsNil)
- decSrc, err := storage.Object(srcObject.Type(), srcObject.Hash())
+ decSrc, err := storage.EncodedObject(srcObject.Type(), srcObject.Hash())
c.Assert(err, IsNil)
c.Assert(decSrc, DeepEquals, srcObject)
- decTarget, err := storage.Object(targetObject.Type(), targetObject.Hash())
+ decTarget, err := storage.EncodedObject(targetObject.Type(), targetObject.Hash())
c.Assert(err, IsNil)
c.Assert(decTarget, DeepEquals, targetObject)
- decOtherTarget, err := storage.Object(otherTargetObject.Type(), otherTargetObject.Hash())
+ decOtherTarget, err := storage.EncodedObject(otherTargetObject.Type(), otherTargetObject.Hash())
c.Assert(err, IsNil)
c.Assert(decOtherTarget, DeepEquals, otherTargetObject)
}
-func delta(base, target plumbing.Object, t plumbing.ObjectType) (plumbing.Object, error) {
+func delta(base, target plumbing.EncodedObject, t plumbing.ObjectType) (plumbing.EncodedObject, error) {
switch t {
case plumbing.OFSDeltaObject:
return GetOFSDelta(base, target)
@@ -250,7 +250,7 @@ func delta(base, target plumbing.Object, t plumbing.ObjectType) (plumbing.Object
}
}
-func newObject(t plumbing.ObjectType, cont []byte) plumbing.Object {
+func newObject(t plumbing.ObjectType, cont []byte) plumbing.EncodedObject {
o := plumbing.MemoryObject{}
o.SetType(t)
o.SetSize(int64(len(cont)))
diff --git a/plumbing/format/packfile/object_pack.go b/plumbing/format/packfile/object_pack.go
index dc5a3c7..dfe9bb2 100644
--- a/plumbing/format/packfile/object_pack.go
+++ b/plumbing/format/packfile/object_pack.go
@@ -6,20 +6,21 @@ import "gopkg.in/src-d/go-git.v4/plumbing"
// pack file.
type ObjectToPack struct {
// The main object to pack, it could be any object, including deltas
- Object plumbing.Object
+ Object plumbing.EncodedObject
// Base is the object that a delta is based on (it could be also another delta).
// If the main object is not a delta, Base will be null
Base *ObjectToPack
// Original is the object that we can generate applying the delta to
- // Base, or the same object as Object in the case of a non-delta object.
- Original plumbing.Object
+ // Base, or the same object as EncodedObject in the case of a non-delta
+ // object.
+ Original plumbing.EncodedObject
// Depth is the amount of deltas needed to resolve to obtain Original
// (delta based on delta based on ...)
Depth int
}
// newObjectToPack creates a correct ObjectToPack based on a non-delta object
-func newObjectToPack(o plumbing.Object) *ObjectToPack {
+func newObjectToPack(o plumbing.EncodedObject) *ObjectToPack {
return &ObjectToPack{
Object: o,
Original: o,
@@ -29,7 +30,7 @@ func newObjectToPack(o plumbing.Object) *ObjectToPack {
// newDeltaObjectToPack creates a correct ObjectToPack for a delta object, based on
// his base (could be another delta), the delta target (in this case called original),
// and the delta Object itself
-func newDeltaObjectToPack(base *ObjectToPack, original, delta plumbing.Object) *ObjectToPack {
+func newDeltaObjectToPack(base *ObjectToPack, original, delta plumbing.EncodedObject) *ObjectToPack {
return &ObjectToPack{
Object: delta,
Base: base,
diff --git a/plumbing/format/packfile/patch_delta.go b/plumbing/format/packfile/patch_delta.go
index 2493a39..36219bb 100644
--- a/plumbing/format/packfile/patch_delta.go
+++ b/plumbing/format/packfile/patch_delta.go
@@ -14,7 +14,7 @@ import (
const deltaSizeMin = 4
// ApplyDelta writes to taget the result of applying the modification deltas in delta to base.
-func ApplyDelta(target, base plumbing.Object, delta []byte) error {
+func ApplyDelta(target, base plumbing.EncodedObject, delta []byte) error {
r, err := base.Reader()
if err != nil {
return err