diff options
author | Joshua Sjoding <joshua.sjoding@scjalliance.com> | 2016-03-03 00:33:00 -0800 |
---|---|---|
committer | Joshua Sjoding <joshua.sjoding@scjalliance.com> | 2016-03-08 13:09:54 -0800 |
commit | 9e6a03b7956464ccd9d2fbacedd8e5cc23572d02 (patch) | |
tree | 0282f20de8279db354233d1d67e3743e08509020 /repository.go | |
parent | 9c9cdff966cc181296f400769d3c8596f17e743a (diff) | |
download | go-git-9e6a03b7956464ccd9d2fbacedd8e5cc23572d02.tar.gz |
Added Object interface for Commit, Tree, Blob and Tag
* New Object interface is distinct from core.Object
* New Object interface is used in places where returned object could be of any type
* Object is implemented by Commit, Tree, Blob, File and Tag
* Added Repository.Object function for retrieving objects of any type
* Tag.Object now returns Object instead of core.Object
* Tag target hash is now publicly accessible
* Renamed Tag.Type field to Tag.TargetType, making it distinct from Tag.Type function
* Fixed infinite recursive loop in TagIter.Close
* TreeWalker.Next now returns Object instead of core.Object
* Removed some duplicate test setup code
Diffstat (limited to 'repository.go')
-rw-r--r-- | repository.go | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/repository.go b/repository.go index 451bb8f..ae583fd 100644 --- a/repository.go +++ b/repository.go @@ -75,6 +75,8 @@ func (r *Repository) Pull(remoteName, branch string) (err error) { req := &common.GitUploadPackRequest{} req.Want(ref) + // TODO: Provide "haves" for what's already in the repository's storage + reader, err := remote.Fetch(req) if err != nil { return err @@ -155,3 +157,31 @@ func (r *Repository) Tag(h core.Hash) (*Tag, error) { func (r *Repository) Tags() *TagIter { return NewTagIter(r, r.Storage.Iter(core.TagObject)) } + +// Object returns an object with the given hash. +func (r *Repository) Object(h core.Hash) (Object, error) { + obj, err := r.Storage.Get(h) + if err != nil { + if err == core.ObjectNotFoundErr { + return nil, ObjectNotFoundErr + } + return nil, err + } + + switch obj.Type() { + case core.CommitObject: + commit := &Commit{r: r} + return commit, commit.Decode(obj) + case core.TreeObject: + tree := &Tree{r: r} + return tree, tree.Decode(obj) + case core.BlobObject: + blob := &Blob{} + return blob, blob.Decode(obj) + case core.TagObject: + tag := &Tag{r: r} + return tag, tag.Decode(obj) + default: + return nil, core.ErrInvalidType + } +} |