aboutsummaryrefslogtreecommitdiffstats
path: root/_examples
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2017-04-11 21:28:19 +0200
committerGitHub <noreply@github.com>2017-04-11 21:28:19 +0200
commit9b45f468c61a0756dd19d09b64c2b1a88cc99ec5 (patch)
tree0e513815f1ef3765538c19b893ab4990264ae46d /_examples
parent3daede53835e8572b2957a016f068781db646567 (diff)
parentefef1479b7948e4f9f310446cfdf360f2cb09596 (diff)
downloadgo-git-9b45f468c61a0756dd19d09b64c2b1a88cc99ec5.tar.gz
Merge pull request #337 from ajnavarro/repository-log
Add Repository.Log() method (fix #298)
Diffstat (limited to '_examples')
-rw-r--r--_examples/log/main.go14
-rw-r--r--_examples/open/main.go16
-rw-r--r--_examples/showcase/main.go9
3 files changed, 24 insertions, 15 deletions
diff --git a/_examples/log/main.go b/_examples/log/main.go
index e13df2c..714d58f 100644
--- a/_examples/log/main.go
+++ b/_examples/log/main.go
@@ -5,6 +5,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"
"gopkg.in/src-d/go-git.v4/storage/memory"
)
@@ -29,16 +30,15 @@ func main() {
ref, err := r.Head()
CheckIfError(err)
- // ... retrieves the commit object
- commit, err := r.CommitObject(ref.Hash())
- CheckIfError(err)
-
// ... retrieves the commit history
- history, err := commit.History()
+ cIter, err := r.Log(&git.LogOptions{From: ref.Hash()})
CheckIfError(err)
// ... just iterates over the commits, printing it
- for _, c := range history {
+ err = cIter.ForEach(func(c *object.Commit) error {
fmt.Println(c)
- }
+
+ return nil
+ })
+ CheckIfError(err)
}
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)
}
diff --git a/_examples/showcase/main.go b/_examples/showcase/main.go
index 0170cd8..aeeddb8 100644
--- a/_examples/showcase/main.go
+++ b/_examples/showcase/main.go
@@ -59,12 +59,15 @@ func main() {
// List the history of the repository
Info("git log --oneline")
- commits, err := commit.History()
+ commitIter, err := r.Log(&git.LogOptions{From: commit.Hash})
CheckIfError(err)
- for _, c := range commits {
+ err = commitIter.ForEach(func(c *object.Commit) error {
hash := c.Hash.String()
line := strings.Split(c.Message, "\n")
fmt.Println(hash[:7], line[0])
- }
+
+ return nil
+ })
+ CheckIfError(err)
}