aboutsummaryrefslogtreecommitdiffstats
path: root/_examples/open
diff options
context:
space:
mode:
authorAntonio Jesus Navarro Perez <antonio@sourced.tech>2017-04-10 17:00:27 +0200
committerAntonio Jesus Navarro Perez <antonio@sourced.tech>2017-04-11 11:25:42 +0200
commitefef1479b7948e4f9f310446cfdf360f2cb09596 (patch)
tree0e513815f1ef3765538c19b893ab4990264ae46d /_examples/open
parentbe8d19438ada078a8598e366ab74aa09e4c521cd (diff)
downloadgo-git-efef1479b7948e4f9f310446cfdf360f2cb09596.tar.gz
Modify examples
Diffstat (limited to '_examples/open')
-rw-r--r--_examples/open/main.go16
1 files changed, 11 insertions, 5 deletions
diff --git a/_examples/open/main.go b/_examples/open/main.go
index 0000f5e..b890423 100644
--- a/_examples/open/main.go
+++ b/_examples/open/main.go
@@ -6,6 +6,7 @@ import (
"gopkg.in/src-d/go-git.v4"
. "gopkg.in/src-d/go-git.v4/_examples"
+ "gopkg.in/src-d/go-git.v4/plumbing/object"
)
// Open an existing repository in a specific folder.
@@ -24,13 +25,18 @@ func main() {
ref, err := r.Head()
CheckIfError(err)
- // ... retrieving the commit object
- commit, err := r.CommitObject(ref.Hash())
+ // ... retrieves the commit history
+ cIter, err := r.Log(&git.LogOptions{From: ref.Hash()})
CheckIfError(err)
- // ... calculating the commit history
- commits, err := commit.History()
+ // ... just iterates over the commits
+ var cCount int
+ err = cIter.ForEach(func(c *object.Commit) error {
+ cCount++
+
+ return nil
+ })
CheckIfError(err)
- fmt.Println(len(commits))
+ fmt.Println(cCount)
}