aboutsummaryrefslogtreecommitdiffstats
path: root/repository.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2015-10-27 01:49:58 +0100
committerMáximo Cuadros <mcuadros@gmail.com>2015-10-27 01:49:58 +0100
commit7d6c5a56c0b63705378f125523876de1a97fd1ce (patch)
tree8945a8a02d53f36a64304beaf006c4f46d61da48 /repository.go
parenta2e49a59782a50a9ff116c6d17c6e3888502f2ad (diff)
downloadgo-git-7d6c5a56c0b63705378f125523876de1a97fd1ce.tar.gz
tree and commit
Diffstat (limited to 'repository.go')
-rw-r--r--repository.go40
1 files changed, 40 insertions, 0 deletions
diff --git a/repository.go b/repository.go
index 2dadcb6..c732d0f 100644
--- a/repository.go
+++ b/repository.go
@@ -1,6 +1,7 @@
package git
import (
+ "errors"
"fmt"
"gopkg.in/src-d/go-git.v2/clients/common"
@@ -8,6 +9,10 @@ import (
"gopkg.in/src-d/go-git.v2/internal"
)
+var (
+ ObjectNotFoundErr = errors.New("object not found")
+)
+
const (
DefaultRemoteName = "origin"
)
@@ -66,3 +71,38 @@ func (r *Repository) Pull(remoteName, branch string) error {
return nil
}
+
+// Commit return the commit with the given hash
+func (r *Repository) Commit(h internal.Hash) (*Commit, error) {
+ obj, ok := r.Storage.Get(h)
+ if !ok {
+ return nil, ObjectNotFoundErr
+ }
+
+ commit := &Commit{r: r}
+ return commit, commit.Decode(obj)
+}
+
+// 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
+}
+
+// Tree return the tree with the given hash
+func (r *Repository) Tree(h internal.Hash) (*Tree, error) {
+ obj, ok := r.Storage.Get(h)
+ if !ok {
+ return nil, ObjectNotFoundErr
+ }
+
+ tree := &Tree{r: r}
+ return tree, tree.Decode(obj)
+}