aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2017-07-19 14:15:34 +0200
committerMáximo Cuadros <mcuadros@gmail.com>2017-07-19 14:15:34 +0200
commitd851b90f5e832fa1edeb0d408bd56ed6c1fd5e7a (patch)
treeab25942ff243173a27979bc357d6bc516dda65d1 /plumbing
parent95bfc7e1c1b7101f2cd605cda58c1fb43d501d35 (diff)
downloadgo-git-d851b90f5e832fa1edeb0d408bd56ed6c1fd5e7a.tar.gz
repository: allow push from shallow repositories
Diffstat (limited to 'plumbing')
-rw-r--r--plumbing/object/commit_walker_test.go28
-rw-r--r--plumbing/revlist/revlist.go39
2 files changed, 24 insertions, 43 deletions
diff --git a/plumbing/object/commit_walker_test.go b/plumbing/object/commit_walker_test.go
index 81795f3..48b504d 100644
--- a/plumbing/object/commit_walker_test.go
+++ b/plumbing/object/commit_walker_test.go
@@ -1,7 +1,10 @@
package object
-import . "gopkg.in/check.v1"
-import "gopkg.in/src-d/go-git.v4/plumbing"
+import (
+ "gopkg.in/src-d/go-git.v4/plumbing"
+
+ . "gopkg.in/check.v1"
+)
type CommitWalkerSuite struct {
BaseObjectsSuite
@@ -57,27 +60,6 @@ func (s *CommitWalkerSuite) TestCommitPreIteratorWithIgnore(c *C) {
}
}
-func (s *CommitWalkerSuite) TestCommitPreIteratorWithIgnoreFirst(c *C) {
- commit := s.commit(c, s.Fixture.Head)
-
- var commits []*Commit
- NewCommitPreorderIter(commit, []plumbing.Hash{
- plumbing.NewHash("6ecf0ef2c2dffb796033e5a02219af86ec6584e5"),
- }).ForEach(func(c *Commit) error {
- commits = append(commits, c)
- return nil
- })
-
- c.Assert(commits, HasLen, 2)
-
- expected := []string{
- "6ecf0ef2c2dffb796033e5a02219af86ec6584e5",
- }
- for i, commit := range commits {
- c.Assert(commit.Hash.String(), Equals, expected[i])
- }
-}
-
func (s *CommitWalkerSuite) TestCommitPostIterator(c *C) {
commit := s.commit(c, s.Fixture.Head)
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