aboutsummaryrefslogtreecommitdiffstats
path: root/commit_walker.go
diff options
context:
space:
mode:
authorSantiago M. Mola <santi@mola.io>2016-12-14 23:12:44 +0100
committerMáximo Cuadros <mcuadros@gmail.com>2016-12-14 23:12:44 +0100
commit0af572dd21c0aa79d13745b633ee24ba6c4d6cf1 (patch)
tree49e81e74e82d84fd88b2fc1e4b0dc7c7bfe9c40f /commit_walker.go
parentdf0f38af83f972f026d7e14150f3d37b95f13484 (diff)
downloadgo-git-0af572dd21c0aa79d13745b633ee24ba6c4d6cf1.tar.gz
move plumbing from top level package to plumbing (#183)
* plumbing: rename Object -> EncodedObject. * plumbing/storer: rename ObjectStorer -> EncodedObjectStorer. * move difftree to plumbing/difftree. * move diff -> utils/diff * make Object/Tag/Blob/Tree/Commit/File depend on storer. * Object and its implementations now depend only on storer.EncodedObjectStorer, not git.Repository. * Tests are decoupled accordingly. * move Object/Commit/File/Tag/Tree to plumbing/object. * move Object/Commit/File/Tag/Tree to plumbing/object. * move checkClose to utils/ioutil. * move RevListObjects to plumbing/revlist.Objects. * move DiffTree to plumbing/difftree package. * rename files with plural nouns to singular * plumbing/object: add GetBlob/GetCommit/GetTag/GetTree.
Diffstat (limited to 'commit_walker.go')
-rw-r--r--commit_walker.go67
1 files changed, 0 insertions, 67 deletions
diff --git a/commit_walker.go b/commit_walker.go
deleted file mode 100644
index 8685801..0000000
--- a/commit_walker.go
+++ /dev/null
@@ -1,67 +0,0 @@
-package git
-
-import (
- "io"
-
- "gopkg.in/src-d/go-git.v4/plumbing"
-)
-
-type commitWalker struct {
- seen map[plumbing.Hash]bool
- stack []*CommitIter
- start *Commit
- cb func(*Commit) error
-}
-
-// WalkCommitHistory walks the commit history
-func WalkCommitHistory(c *Commit, cb func(*Commit) error) error {
- w := &commitWalker{
- seen: make(map[plumbing.Hash]bool),
- stack: make([]*CommitIter, 0),
- start: c,
- cb: cb,
- }
-
- return w.walk()
-}
-
-func (w *commitWalker) walk() error {
- var commit *Commit
-
- if w.start != nil {
- commit = w.start
- w.start = nil
- } else {
- current := len(w.stack) - 1
- if current < 0 {
- return nil
- }
-
- var err error
- commit, err = w.stack[current].Next()
- if err == io.EOF {
- w.stack = w.stack[:current]
- return w.walk()
- }
-
- if err != nil {
- return err
- }
- }
-
- // check and update seen
- if w.seen[commit.Hash] {
- return w.walk()
- }
-
- w.seen[commit.Hash] = true
- if commit.NumParents() > 0 {
- w.stack = append(w.stack, commit.Parents())
- }
-
- if err := w.cb(commit); err != nil {
- return err
- }
-
- return w.walk()
-}