aboutsummaryrefslogtreecommitdiffstats
path: root/repository.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2016-09-12 02:22:08 +0200
committerMáximo Cuadros <mcuadros@gmail.com>2016-09-12 02:22:08 +0200
commitd57f90b78eeb6b09b15e3fe57609ede66df4edac (patch)
tree961aa929391c0e804f32d26016f9e385f6e70ecb /repository.go
parent58fe211f1b0e4863b425542d2fad15803276fd66 (diff)
downloadgo-git-d57f90b78eeb6b09b15e3fe57609ede66df4edac.tar.gz
fixtures: new fixture package being use in all packages
Diffstat (limited to 'repository.go')
-rw-r--r--repository.go34
1 files changed, 9 insertions, 25 deletions
diff --git a/repository.go b/repository.go
index cc76107..11b7fae 100644
--- a/repository.go
+++ b/repository.go
@@ -226,16 +226,12 @@ 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(core.CommitObject, h)
+ commit, err := r.Object(core.CommitObject, h)
if err != nil {
- if err == core.ErrObjectNotFound {
- return nil, ErrObjectNotFound
- }
return nil, err
}
- commit := &Commit{r: r}
- return commit, commit.Decode(obj)
+ return commit.(*Commit), nil
}
// Commits decode the objects into commits
@@ -250,44 +246,32 @@ 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(core.TreeObject, h)
+ tree, err := r.Object(core.TreeObject, h)
if err != nil {
- if err == core.ErrObjectNotFound {
- return nil, ErrObjectNotFound
- }
return nil, err
}
- tree := &Tree{r: r}
- return tree, tree.Decode(obj)
+ return tree.(*Tree), nil
}
// Blob returns the blob with the given hash
func (r *Repository) Blob(h core.Hash) (*Blob, error) {
- obj, err := r.s.ObjectStorage().Get(core.BlobObject, h)
+ blob, err := r.Object(core.BlobObject, h)
if err != nil {
- if err == core.ErrObjectNotFound {
- return nil, ErrObjectNotFound
- }
return nil, err
}
- blob := &Blob{}
- return blob, blob.Decode(obj)
+ return blob.(*Blob), nil
}
// Tag returns a tag with the given hash.
func (r *Repository) Tag(h core.Hash) (*Tag, error) {
- obj, err := r.s.ObjectStorage().Get(core.TagObject, h)
+ tag, err := r.Object(core.TagObject, h)
if err != nil {
- if err == core.ErrObjectNotFound {
- return nil, ErrObjectNotFound
- }
return nil, err
}
- t := &Tag{r: r}
- return t, t.Decode(obj)
+ return tag.(*Tag), nil
}
// Tags returns a TagIter that can step through all of the annotated tags
@@ -302,7 +286,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) {
+func (r *Repository) Object(t core.ObjectType, h core.Hash) (Object, error) {
obj, err := r.s.ObjectStorage().Get(t, h)
if err != nil {
if err == core.ErrObjectNotFound {