aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--commit_test.go2
-rw-r--r--core/object.go5
-rw-r--r--core/storage.go2
-rw-r--r--examples/object_storage/storage.go2
-rw-r--r--formats/packfile/decoder_test.go2
-rw-r--r--remote.go2
-rw-r--r--repository.go10
-rw-r--r--storage/filesystem/object.go4
-rw-r--r--storage/filesystem/object_test.go4
-rw-r--r--storage/memory/storage.go2
-rw-r--r--storage/test/storage_suite.go9
-rw-r--r--tree.go4
-rw-r--r--tree_test.go2
14 files changed, 27 insertions, 24 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..2d83068
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+coverage.out
diff --git a/commit_test.go b/commit_test.go
index c7fc333..744d6f3 100644
--- a/commit_test.go
+++ b/commit_test.go
@@ -28,7 +28,7 @@ func (s *SuiteCommit) SetUpSuite(c *C) {
func (s *SuiteCommit) TestDecodeNonCommit(c *C) {
hash := core.NewHash("9a48f23120e880dfbe41f7c9b7b708e9ee62a492")
- blob, err := s.Repository.s.ObjectStorage().Get(hash, core.AnyObject)
+ blob, err := s.Repository.s.ObjectStorage().Get(core.AnyObject, hash)
c.Assert(err, IsNil)
commit := &Commit{}
diff --git a/core/object.go b/core/object.go
index 7e021cb..6a22122 100644
--- a/core/object.go
+++ b/core/object.go
@@ -137,10 +137,11 @@ func (iter *ObjectLookupIter) Next() (Object, error) {
return nil, io.EOF
}
hash := iter.series[iter.pos]
- obj, err := iter.storage.Get(hash, AnyObject)
+ obj, err := iter.storage.Get(AnyObject, hash)
if err == nil {
iter.pos++
}
+
return obj, err
}
@@ -151,7 +152,7 @@ func (iter *ObjectLookupIter) ForEach(cb func(Object) error) error {
defer iter.Close()
for _, hash := range iter.series {
- obj, err := iter.storage.Get(hash, AnyObject)
+ obj, err := iter.storage.Get(AnyObject, hash)
if err != nil {
return err
}
diff --git a/core/storage.go b/core/storage.go
index f3ec52b..15d988a 100644
--- a/core/storage.go
+++ b/core/storage.go
@@ -18,7 +18,7 @@ type ObjectStorage interface {
// and AnyObject.
//
// If AnyObject is given, the object must be looked up regardless of its type.
- Get(Hash, ObjectType) (Object, error)
+ Get(ObjectType, Hash) (Object, error)
Iter(ObjectType) (ObjectIter, error)
}
diff --git a/examples/object_storage/storage.go b/examples/object_storage/storage.go
index 0513654..eef294c 100644
--- a/examples/object_storage/storage.go
+++ b/examples/object_storage/storage.go
@@ -86,7 +86,7 @@ func (o *AerospikeObjectStorage) Set(obj core.Object) (core.Hash, error) {
return obj.Hash(), err
}
-func (o *AerospikeObjectStorage) Get(h core.Hash, t core.ObjectType) (core.Object, error) {
+func (o *AerospikeObjectStorage) Get(t core.ObjectType, h core.Hash) (core.Object, error) {
key, err := keyFromObject(h, t)
if err != nil {
return nil, err
diff --git a/formats/packfile/decoder_test.go b/formats/packfile/decoder_test.go
index 5c8807d..fe25ee4 100644
--- a/formats/packfile/decoder_test.go
+++ b/formats/packfile/decoder_test.go
@@ -104,7 +104,7 @@ func AssertObjects(c *C, s *memory.Storage, expects []string) {
c.Assert(len(expects), Equals, len(o.Objects))
for _, exp := range expects {
- obt, err := o.Get(core.NewHash(exp), core.AnyObject)
+ obt, err := o.Get(core.AnyObject, core.NewHash(exp))
c.Assert(err, IsNil)
c.Assert(obt.Hash().String(), Equals, exp)
}
diff --git a/remote.go b/remote.go
index 3af713b..f388d87 100644
--- a/remote.go
+++ b/remote.go
@@ -123,7 +123,7 @@ func (r *Remote) getWantedReferences(spec []config.RefSpec) ([]*core.Reference,
return nil
}
- _, err := r.s.ObjectStorage().Get(ref.Hash(), core.CommitObject)
+ _, err := r.s.ObjectStorage().Get(core.CommitObject, ref.Hash())
if err == core.ErrObjectNotFound {
refs = append(refs, ref)
return nil
diff --git a/repository.go b/repository.go
index 1a5f4a7..049c7db 100644
--- a/repository.go
+++ b/repository.go
@@ -226,7 +226,7 @@ func (r *Repository) Pull(o *PullOptions) error {
// Commit return the commit with the given hash
func (r *Repository) Commit(h core.Hash) (*Commit, error) {
- obj, err := r.s.ObjectStorage().Get(h, core.CommitObject)
+ obj, err := r.s.ObjectStorage().Get(core.CommitObject, h)
if err != nil {
if err == core.ErrObjectNotFound {
return nil, ErrObjectNotFound
@@ -250,7 +250,7 @@ func (r *Repository) Commits() (*CommitIter, error) {
// Tree return the tree with the given hash
func (r *Repository) Tree(h core.Hash) (*Tree, error) {
- obj, err := r.s.ObjectStorage().Get(h, core.TreeObject)
+ obj, err := r.s.ObjectStorage().Get(core.TreeObject, h)
if err != nil {
if err == core.ErrObjectNotFound {
return nil, ErrObjectNotFound
@@ -264,7 +264,7 @@ func (r *Repository) Tree(h core.Hash) (*Tree, error) {
// Blob returns the blob with the given hash
func (r *Repository) Blob(h core.Hash) (*Blob, error) {
- obj, err := r.s.ObjectStorage().Get(h, core.BlobObject)
+ obj, err := r.s.ObjectStorage().Get(core.BlobObject, h)
if err != nil {
if err == core.ErrObjectNotFound {
return nil, ErrObjectNotFound
@@ -278,7 +278,7 @@ func (r *Repository) Blob(h core.Hash) (*Blob, error) {
// Tag returns a tag with the given hash.
func (r *Repository) Tag(h core.Hash) (*Tag, error) {
- obj, err := r.s.ObjectStorage().Get(h, core.TagObject)
+ obj, err := r.s.ObjectStorage().Get(core.TagObject, h)
if err != nil {
if err == core.ErrObjectNotFound {
return nil, ErrObjectNotFound
@@ -303,7 +303,7 @@ func (r *Repository) Tags() (*TagIter, error) {
// Object returns an object with the given hash.
func (r *Repository) Object(h core.Hash, t core.ObjectType) (Object, error) {
- obj, err := r.s.ObjectStorage().Get(h, t)
+ obj, err := r.s.ObjectStorage().Get(t, h)
if err != nil {
if err == core.ErrObjectNotFound {
return nil, ErrObjectNotFound
diff --git a/storage/filesystem/object.go b/storage/filesystem/object.go
index 6024ae0..1b1ce9d 100644
--- a/storage/filesystem/object.go
+++ b/storage/filesystem/object.go
@@ -38,7 +38,7 @@ func (s *ObjectStorage) Set(core.Object) (core.Hash, error) {
// Get returns the object with the given hash, by searching for it in
// the packfile.
-func (s *ObjectStorage) Get(h core.Hash, t core.ObjectType) (core.Object, error) {
+func (s *ObjectStorage) Get(t core.ObjectType, h core.Hash) (core.Object, error) {
offset, err := s.index.Get(h)
if err != nil {
return nil, err
@@ -87,7 +87,7 @@ func (s *ObjectStorage) Iter(t core.ObjectType) (core.ObjectIter, error) {
var objects []core.Object
for hash := range s.index {
- object, err := s.Get(hash, core.AnyObject)
+ object, err := s.Get(core.AnyObject, hash)
if err != nil {
return nil, err
}
diff --git a/storage/filesystem/object_test.go b/storage/filesystem/object_test.go
index 956fdeb..361ae32 100644
--- a/storage/filesystem/object_test.go
+++ b/storage/filesystem/object_test.go
@@ -66,7 +66,7 @@ func (s *FsSuite) TestHashNotFound(c *C) {
sto := s.newObjectStorage(c, "binary-relations")
types := []core.ObjectType{core.AnyObject, core.TagObject, core.CommitObject, core.BlobObject, core.TreeObject}
for t := range types {
- _, err := sto.Get(core.ZeroHash, core.ObjectType(t))
+ _, err := sto.Get(core.ObjectType(t), core.ZeroHash)
c.Assert(err, Equals, core.ErrObjectNotFound)
}
}
@@ -158,7 +158,7 @@ func equalsStorages(a, b core.ObjectStorage) (bool, string, error) {
break
}
- bo, err := b.Get(ao.Hash(), core.AnyObject)
+ bo, err := b.Get(core.AnyObject, ao.Hash())
if err != nil {
return false, "", fmt.Errorf("getting object with hash %s: %s",
ao.Hash(), err)
diff --git a/storage/memory/storage.go b/storage/memory/storage.go
index 8033541..fa34c4d 100644
--- a/storage/memory/storage.go
+++ b/storage/memory/storage.go
@@ -130,7 +130,7 @@ func (o *ObjectStorage) Set(obj core.Object) (core.Hash, error) {
}
// Get returns a object with the given hash
-func (o *ObjectStorage) Get(h core.Hash, t core.ObjectType) (core.Object, error) {
+func (o *ObjectStorage) Get(t core.ObjectType, h core.Hash) (core.Object, error) {
obj, ok := o.Objects[h]
if !ok || (core.AnyObject != t && obj.Type() != t) {
return nil, core.ErrObjectNotFound
diff --git a/storage/test/storage_suite.go b/storage/test/storage_suite.go
index 2463d9d..4181e8c 100644
--- a/storage/test/storage_suite.go
+++ b/storage/test/storage_suite.go
@@ -1,9 +1,10 @@
package test
import (
+ "io"
+
. "gopkg.in/check.v1"
"gopkg.in/src-d/go-git.v4/core"
- "io"
)
type TestObject struct {
@@ -38,11 +39,11 @@ func RunObjectStorageSuite(c *C, os core.ObjectStorage) {
c.Assert(err, IsNil)
c.Assert(h.String(), Equals, to.Hash, comment)
- o, err := os.Get(h, to.Type)
+ o, err := os.Get(to.Type, h)
c.Assert(err, IsNil)
c.Assert(o, Equals, to.Object)
- o, err = os.Get(h, core.AnyObject)
+ o, err = os.Get(core.AnyObject, h)
c.Assert(err, IsNil)
c.Assert(o, Equals, to.Object)
@@ -50,7 +51,7 @@ func RunObjectStorageSuite(c *C, os core.ObjectStorage) {
if validType == to.Type {
continue
}
- o, err = os.Get(h, validType)
+ o, err = os.Get(validType, h)
c.Assert(o, IsNil)
c.Assert(err, Equals, core.ErrObjectNotFound)
}
diff --git a/tree.go b/tree.go
index de9765b..95fbcb5 100644
--- a/tree.go
+++ b/tree.go
@@ -47,7 +47,7 @@ func (t *Tree) File(path string) (*File, error) {
return nil, ErrFileNotFound
}
- obj, err := t.r.s.ObjectStorage().Get(e.Hash, core.BlobObject)
+ obj, err := t.r.s.ObjectStorage().Get(core.BlobObject, e.Hash)
if err != nil {
if err == core.ErrObjectNotFound {
return nil, ErrFileNotFound // a git submodule
@@ -87,7 +87,7 @@ func (t *Tree) dir(baseName string) (*Tree, error) {
return nil, errDirNotFound
}
- obj, err := t.r.s.ObjectStorage().Get(entry.Hash, core.TreeObject)
+ obj, err := t.r.s.ObjectStorage().Get(core.TreeObject, entry.Hash)
if err != nil {
if err == core.ErrObjectNotFound { // git submodule
return nil, errDirNotFound
diff --git a/tree_test.go b/tree_test.go
index bc9686d..0780ca9 100644
--- a/tree_test.go
+++ b/tree_test.go
@@ -37,7 +37,7 @@ func (s *SuiteTree) TestDecode(c *C) {
func (s *SuiteTree) TestDecodeNonTree(c *C) {
hash := core.NewHash("9a48f23120e880dfbe41f7c9b7b708e9ee62a492")
- blob, err := s.Repository.s.ObjectStorage().Get(hash, core.BlobObject)
+ blob, err := s.Repository.s.ObjectStorage().Get(core.BlobObject, hash)
c.Assert(err, IsNil)
tree := &Tree{}