Skip to content

Commit

Permalink
Revert "git: Add support for deepening shallow clones (go-git#311)"
Browse files Browse the repository at this point in the history
This reverts commit 320db9a.

Signed-off-by: Rohan Kumar <rohankmr414@gmail.com>
  • Loading branch information
marwatk authored and rohankmr414 committed Nov 3, 2022
1 parent 3f18a50 commit 2f7a191
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 70 deletions.
2 changes: 1 addition & 1 deletion plumbing/transport/internal/common/common.go
Expand Up @@ -233,7 +233,7 @@ func (s *session) handleAdvRefDecodeError(err error) error {
// UploadPack performs a request to the server to fetch a packfile. A reader is
// returned with the packfile content. The reader must be closed after reading.
func (s *session) UploadPack(ctx context.Context, req *packp.UploadPackRequest) (*packp.UploadPackResponse, error) {
if req.IsEmpty() && len(req.Shallows) == 0 {
if req.IsEmpty() {
return nil, transport.ErrEmptyUploadPackRequest
}

Expand Down
44 changes: 1 addition & 43 deletions remote.go
Expand Up @@ -446,13 +446,6 @@ func (r *Remote) fetch(ctx context.Context, o *FetchOptions) (sto storer.Referen
return nil, err
}

if !req.Depth.IsZero() {
req.Shallows, err = r.s.Shallow()
if err != nil {
return nil, fmt.Errorf("existing checkout is not shallow")
}
}

req.Wants, err = getWants(r.s, refs)
if len(req.Wants) > 0 {
req.Haves, err = getHaves(localRefs, remoteRefs, r.s)
Expand All @@ -470,43 +463,13 @@ func (r *Remote) fetch(ctx context.Context, o *FetchOptions) (sto storer.Referen
return nil, err
}

if !updated {
updated, err = depthChanged(req.Shallows, r.s)
if err != nil {
return nil, fmt.Errorf("error checking depth change: %v", err)
}
}

if !updated {
return remoteRefs, NoErrAlreadyUpToDate
}

return remoteRefs, nil
}

func depthChanged(before []plumbing.Hash, s storage.Storer) (bool, error) {
after, err := s.Shallow()
if err != nil {
return false, err
}

if len(before) != len(after) {
return true, nil
}

bm := make(map[plumbing.Hash]bool, len(before))
for _, b := range before {
bm[b] = true
}
for _, a := range after {
if _, ok := bm[a]; !ok {
return true, nil
}
}

return false, nil
}

func newUploadPackSession(url string, auth transport.AuthMethod, insecure bool, cabundle []byte) (transport.UploadPackSession, error) {
c, ep, err := newClient(url, auth, insecure, cabundle)
if err != nil {
Expand Down Expand Up @@ -983,11 +946,6 @@ func doCalculateRefs(
}

func getWants(localStorer storage.Storer, refs memory.ReferenceStorage) ([]plumbing.Hash, error) {
shallow := false
if s, _ := localStorer.Shallow(); len(s) > 0 {
shallow = true
}

wants := map[plumbing.Hash]bool{}
for _, ref := range refs {
hash := ref.Hash()
Expand All @@ -996,7 +954,7 @@ func getWants(localStorer storage.Storer, refs memory.ReferenceStorage) ([]plumb
return nil, err
}

if !exists || shallow {
if !exists {
wants[hash] = true
}
}
Expand Down
26 changes: 0 additions & 26 deletions remote_test.go
Expand Up @@ -243,32 +243,6 @@ func (s *RemoteSuite) TestFetchWithDepth(c *C) {
c.Assert(r.s.(*memory.Storage).Objects, HasLen, 18)
}

func (s *RemoteSuite) TestFetchWithDepthChange(c *C) {
r := NewRemote(memory.NewStorage(), &config.RemoteConfig{
URLs: []string{s.GetBasicLocalRepositoryURL()},
})

s.testFetch(c, r, &FetchOptions{
Depth: 1,
RefSpecs: []config.RefSpec{
config.RefSpec("refs/heads/master:refs/heads/master"),
},
}, []*plumbing.Reference{
plumbing.NewReferenceFromStrings("refs/heads/master", "6ecf0ef2c2dffb796033e5a02219af86ec6584e5"),
})
c.Assert(r.s.(*memory.Storage).Commits, HasLen, 1)

s.testFetch(c, r, &FetchOptions{
Depth: 3,
RefSpecs: []config.RefSpec{
config.RefSpec("refs/heads/master:refs/heads/master"),
},
}, []*plumbing.Reference{
plumbing.NewReferenceFromStrings("refs/heads/master", "6ecf0ef2c2dffb796033e5a02219af86ec6584e5"),
})
c.Assert(r.s.(*memory.Storage).Commits, HasLen, 3)
}

func (s *RemoteSuite) testFetch(c *C, r *Remote, o *FetchOptions, expected []*plumbing.Reference) {
err := r.Fetch(o)
c.Assert(err, IsNil)
Expand Down

0 comments on commit 2f7a191

Please sign in to comment.