diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2017-07-19 15:31:20 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-19 15:31:20 +0200 |
commit | f0fb843efcf56c3df9dbbb47aaafe3e9c4815147 (patch) | |
tree | 812f17007612d2b45431f458e3e49442db53a7fb /plumbing/revlist/revlist.go | |
parent | 9775f829d6fb8026a2d73af89896a8f2cc5f7c50 (diff) | |
parent | d851b90f5e832fa1edeb0d408bd56ed6c1fd5e7a (diff) | |
download | go-git-f0fb843efcf56c3df9dbbb47aaafe3e9c4815147.tar.gz |
Merge pull request #489 from mcuadros/shallow-push
repository: allow push from shallow repositories
Diffstat (limited to 'plumbing/revlist/revlist.go')
-rw-r--r-- | plumbing/revlist/revlist.go | 39 |
1 files changed, 19 insertions, 20 deletions
diff --git a/plumbing/revlist/revlist.go b/plumbing/revlist/revlist.go index 20bc99d..1bda2fa 100644 --- a/plumbing/revlist/revlist.go +++ b/plumbing/revlist/revlist.go @@ -16,11 +16,7 @@ import ( // the reachable objects from the given objects. Ignore param are object hashes // that we want to ignore on the result. All that objects must be accessible // from the object storer. -func Objects( - s storer.EncodedObjectStorer, - objects []plumbing.Hash, - ignore []plumbing.Hash) ([]plumbing.Hash, error) { - +func Objects(s storer.EncodedObjectStorer, objects, ignore []plumbing.Hash) ([]plumbing.Hash, error) { seen := hashListToSet(ignore) result := make(map[plumbing.Hash]bool) @@ -32,7 +28,7 @@ func Objects( } for _, h := range objects { - if err := processObject(s, h, seen, walkerFunc); err != nil { + if err := processObject(s, h, seen, ignore, walkerFunc); err != nil { return nil, err } } @@ -45,6 +41,7 @@ func processObject( s storer.EncodedObjectStorer, h plumbing.Hash, seen map[plumbing.Hash]bool, + ignore []plumbing.Hash, walkerFunc func(h plumbing.Hash), ) error { o, err := s.EncodedObject(plumbing.AnyObject, h) @@ -59,12 +56,12 @@ func processObject( switch do := do.(type) { case *object.Commit: - return reachableObjects(do, seen, walkerFunc) + return reachableObjects(do, seen, ignore, walkerFunc) case *object.Tree: return iterateCommitTrees(seen, do, walkerFunc) case *object.Tag: walkerFunc(do.Hash) - return processObject(s, do.Target, seen, walkerFunc) + return processObject(s, do.Target, seen, ignore, walkerFunc) case *object.Blob: walkerFunc(do.Hash) default: @@ -82,22 +79,24 @@ func processObject( func reachableObjects( commit *object.Commit, seen map[plumbing.Hash]bool, + ignore []plumbing.Hash, cb func(h plumbing.Hash)) error { - return object.NewCommitPreorderIter(commit). - ForEach(func(commit *object.Commit) error { - if seen[commit.Hash] { - return nil - } - cb(commit.Hash) + i := object.NewCommitPreorderIter(commit, ignore) + return i.ForEach(func(commit *object.Commit) error { + if seen[commit.Hash] { + return nil + } + + cb(commit.Hash) - tree, err := commit.Tree() - if err != nil { - return err - } + tree, err := commit.Tree() + if err != nil { + return err + } - return iterateCommitTrees(seen, tree, cb) - }) + return iterateCommitTrees(seen, tree, cb) + }) } // iterateCommitTrees iterate all reachable trees from the given commit |