diff options
-rw-r--r-- | plumbing/object/commit_walker_test.go | 28 | ||||
-rw-r--r-- | plumbing/revlist/revlist.go | 39 | ||||
-rw-r--r-- | remote.go | 12 | ||||
-rw-r--r-- | repository.go | 6 | ||||
-rw-r--r-- | repository_test.go | 45 |
5 files changed, 83 insertions, 47 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 @@ -104,6 +104,7 @@ func (r *Remote) Push(o *PushOptions) (err error) { req := packp.NewReferenceUpdateRequestFromCapabilities(ar.Capabilities) if err := r.addReferencesToUpdate(o.RefSpecs, remoteRefs, req); err != nil { + return err } @@ -121,6 +122,15 @@ func (r *Remote) Push(o *PushOptions) (err error) { return err } + stop, err := r.s.Shallow() + if err != nil { + return err + } + + // if we have shallow we should include this as part of the objects that + // we are aware. + haves = append(haves, stop...) + hashesToPush, err := revlist.Objects(r.s, objects, haves) if err != nil { return err @@ -486,7 +496,7 @@ func isFastForward(s storer.EncodedObjectStorer, old, new plumbing.Hash) (bool, } found := false - iter := object.NewCommitPreorderIter(c) + iter := object.NewCommitPreorderIter(c, nil) return found, iter.ForEach(func(c *object.Commit) error { if c.Hash != old { return nil diff --git a/repository.go b/repository.go index 17f0dff..ec9f254 100644 --- a/repository.go +++ b/repository.go @@ -689,7 +689,7 @@ func (r *Repository) Log(o *LogOptions) (object.CommitIter, error) { return nil, err } - return object.NewCommitPreorderIter(commit), nil + return object.NewCommitPreorderIter(commit, nil), nil } // Tags returns all the References from Tags. This method returns all the tag @@ -918,7 +918,7 @@ func (r *Repository) ResolveRevision(rev plumbing.Revision) (*plumbing.Hash, err commit = c } case revision.CaretReg: - history := object.NewCommitPreorderIter(commit) + history := object.NewCommitPreorderIter(commit, nil) re := item.(revision.CaretReg).Regexp negate := item.(revision.CaretReg).Negate @@ -948,7 +948,7 @@ func (r *Repository) ResolveRevision(rev plumbing.Revision) (*plumbing.Hash, err commit = c case revision.AtDate: - history := object.NewCommitPreorderIter(commit) + history := object.NewCommitPreorderIter(commit, nil) date := item.(revision.AtDate).Date diff --git a/repository_test.go b/repository_test.go index f622007..f31cd1d 100644 --- a/repository_test.go +++ b/repository_test.go @@ -20,6 +20,7 @@ import ( . "gopkg.in/check.v1" "gopkg.in/src-d/go-billy.v3/memfs" "gopkg.in/src-d/go-billy.v3/osfs" + "gopkg.in/src-d/go-billy.v3/util" ) type RepositorySuite struct { @@ -767,6 +768,50 @@ func (s *RepositorySuite) TestPushToEmptyRepository(c *C) { c.Assert(err, IsNil) } +func (s *RepositorySuite) TestPushDepth(c *C) { + dir, err := ioutil.TempDir("", "push-depth") + defer os.RemoveAll(dir) + + origin, err := PlainClone(c.MkDir(), true, &CloneOptions{ + URL: fixtures.Basic().One().DotGit().Root(), + }) + + c.Assert(err, IsNil) + fs := origin.Storer.(*filesystem.Storage).Filesystem() + + r, err := Clone(memory.NewStorage(), memfs.New(), &CloneOptions{ + URL: fs.Root(), + Depth: 1, + }) + c.Assert(err, IsNil) + + err = util.WriteFile(r.wt, "foo", nil, 0755) + c.Assert(err, IsNil) + + w, err := r.Worktree() + c.Assert(err, IsNil) + + _, err = w.Add("foo") + c.Assert(err, IsNil) + + hash, err := w.Commit("foo", &CommitOptions{ + Author: defaultSignature(), + Committer: defaultSignature(), + }) + c.Assert(err, IsNil) + + err = r.Push(&PushOptions{}) + c.Assert(err, IsNil) + + remote, err := origin.Head() + c.Assert(err, IsNil) + c.Assert(remote.Hash(), Equals, hash) + + local, err := r.Head() + c.Assert(err, IsNil) + c.Assert(local.Hash(), Equals, remote.Hash()) +} + func (s *RepositorySuite) TestPushNonExistentRemote(c *C) { srcFs := fixtures.Basic().One().DotGit() sto, err := filesystem.NewStorage(srcFs) |