diff options
author | Joshua Sjoding <joshua.sjoding@scjalliance.com> | 2016-02-19 15:42:00 -0800 |
---|---|---|
committer | Joshua Sjoding <joshua.sjoding@scjalliance.com> | 2016-02-19 15:42:00 -0800 |
commit | 916755f7652d4a3189aa717c7f2668c9aa0b1373 (patch) | |
tree | b32c906cef4779c9cec73749400e1a48eff10bf5 /repository.go | |
parent | 5e100bdb6c60e961730af19ab1691a0d3605de12 (diff) | |
download | go-git-916755f7652d4a3189aa717c7f2668c9aa0b1373.tar.gz |
Improved support for Blob objects
Diffstat (limited to 'repository.go')
-rw-r--r-- | repository.go | 38 |
1 files changed, 26 insertions, 12 deletions
diff --git a/repository.go b/repository.go index a553f91..cce7097 100644 --- a/repository.go +++ b/repository.go @@ -110,8 +110,8 @@ func (r *Repository) Commits() *CommitIter { return NewCommitIter(r, r.Storage.Iter(core.CommitObject)) } -// Tag returns a tag with the given hash. -func (r *Repository) Tag(h core.Hash) (*Tag, error) { +// Tree return the tree with the given hash +func (r *Repository) Tree(h core.Hash) (*Tree, error) { obj, err := r.Storage.Get(h) if err != nil { if err == core.ObjectNotFoundErr { @@ -120,18 +120,26 @@ func (r *Repository) Tag(h core.Hash) (*Tag, error) { return nil, err } - tag := &Tag{r: r} - return tag, tag.Decode(obj) + tree := &Tree{r: r} + return tree, tree.Decode(obj) } -// Tags returns a TagIter that can step through all of the annotated tags -// in the repository. -func (r *Repository) Tags() *TagIter { - return NewTagIter(r, r.Storage.Iter(core.TagObject)) +// Blob returns the blob with the given hash +func (r *Repository) Blob(h core.Hash) (*Blob, error) { + obj, err := r.Storage.Get(h) + if err != nil { + if err == core.ObjectNotFoundErr { + return nil, ObjectNotFoundErr + } + return nil, err + } + + blob := &Blob{} + return blob, blob.Decode(obj) } -// Tree return the tree with the given hash -func (r *Repository) Tree(h core.Hash) (*Tree, error) { +// Tag returns a tag with the given hash. +func (r *Repository) Tag(h core.Hash) (*Tag, error) { obj, err := r.Storage.Get(h) if err != nil { if err == core.ObjectNotFoundErr { @@ -140,6 +148,12 @@ func (r *Repository) Tree(h core.Hash) (*Tree, error) { return nil, err } - tree := &Tree{r: r} - return tree, tree.Decode(obj) + tag := &Tag{r: r} + return tag, tag.Decode(obj) +} + +// Tags returns a TagIter that can step through all of the annotated tags +// in the repository. +func (r *Repository) Tags() *TagIter { + return NewTagIter(r, r.Storage.Iter(core.TagObject)) } |