aboutsummaryrefslogtreecommitdiffstats
path: root/repository.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2016-02-16 17:58:07 +0100
committerMáximo Cuadros <mcuadros@gmail.com>2016-02-16 17:58:07 +0100
commita9896315a1b37b66865a0eb7e94e768ef45ff3db (patch)
tree8c4012969e4a5f430d385aa908f369fa843e815e /repository.go
parent1931dfbf38508e790e9f129873bc073aacc6a50f (diff)
parente82d4918b403a641a5295b3f199586b0ab26b15c (diff)
downloadgo-git-a9896315a1b37b66865a0eb7e94e768ef45ff3db.tar.gz
Merge pull request #20 from scjalliance/generic-object-storage
Iterable ObjectStorage interface for use in Repository struct
Diffstat (limited to 'repository.go')
-rw-r--r--repository.go30
1 files changed, 14 insertions, 16 deletions
diff --git a/repository.go b/repository.go
index 8f1aac2..2532c8d 100644
--- a/repository.go
+++ b/repository.go
@@ -19,7 +19,7 @@ const (
type Repository struct {
Remotes map[string]*Remote
- Storage *core.RAWObjectStorage
+ Storage core.ObjectStorage
URL string
}
@@ -92,9 +92,12 @@ func (r *Repository) Pull(remoteName, branch string) (err error) {
// Commit return the commit with the given hash
func (r *Repository) Commit(h core.Hash) (*Commit, error) {
- obj, ok := r.Storage.Get(h)
- if !ok {
- return nil, ObjectNotFoundErr
+ obj, err := r.Storage.Get(h)
+ if err != nil {
+ if err == core.ObjectNotFoundErr {
+ return nil, ObjectNotFoundErr
+ }
+ return nil, err
}
commit := &Commit{r: r}
@@ -103,22 +106,17 @@ func (r *Repository) Commit(h core.Hash) (*Commit, error) {
// Commits decode the objects into commits
func (r *Repository) Commits() *CommitIter {
- i := NewCommitIter(r)
- go func() {
- defer i.Close()
- for _, obj := range r.Storage.Commits {
- i.Add(obj)
- }
- }()
-
- return i
+ return NewCommitIter(r, r.Storage.Iter(core.CommitObject))
}
// Tree return the tree with the given hash
func (r *Repository) Tree(h core.Hash) (*Tree, error) {
- obj, ok := r.Storage.Get(h)
- if !ok {
- return nil, ObjectNotFoundErr
+ obj, err := r.Storage.Get(h)
+ if err != nil {
+ if err == core.ObjectNotFoundErr {
+ return nil, ObjectNotFoundErr
+ }
+ return nil, err
}
tree := &Tree{r: r}