diff options
author | Paulo Gomes <pjbgf@linux.com> | 2023-07-02 14:42:34 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-02 14:42:34 +0100 |
commit | dd4e2b7f4b01e2aaafcf182d2884a186a6f37d21 (patch) | |
tree | 9eb4595171862dbbf92c88de57bc410bdbc7b12c /plumbing | |
parent | 99ccca6bc543f88a18df50763d5fc13808e053e4 (diff) | |
parent | 025e1311f8473f65facf8cffeccc11e39466db4a (diff) | |
download | go-git-dd4e2b7f4b01e2aaafcf182d2884a186a6f37d21.tar.gz |
Merge pull request #792 from AriehSchneier/empty-fetch-with-shallows
plumbing: packp, A request is not empty if it contains shallows. Fixes #328
Diffstat (limited to 'plumbing')
-rw-r--r-- | plumbing/protocol/packp/uppackreq.go | 6 | ||||
-rw-r--r-- | plumbing/protocol/packp/uppackreq_test.go | 7 | ||||
-rw-r--r-- | plumbing/transport/internal/common/common.go | 2 |
3 files changed, 11 insertions, 4 deletions
diff --git a/plumbing/protocol/packp/uppackreq.go b/plumbing/protocol/packp/uppackreq.go index de2206b..48f4438 100644 --- a/plumbing/protocol/packp/uppackreq.go +++ b/plumbing/protocol/packp/uppackreq.go @@ -38,10 +38,10 @@ func NewUploadPackRequestFromCapabilities(adv *capability.List) *UploadPackReque } } -// IsEmpty a request if empty if Haves are contained in the Wants, or if Wants -// length is zero +// IsEmpty returns whether a request is empty - it is empty if Haves are contained +// in the Wants, or if Wants length is zero, and we don't have any shallows func (r *UploadPackRequest) IsEmpty() bool { - return isSubset(r.Wants, r.Haves) + return isSubset(r.Wants, r.Haves) && len(r.Shallows) == 0 } func isSubset(needle []plumbing.Hash, haystack []plumbing.Hash) bool { diff --git a/plumbing/protocol/packp/uppackreq_test.go b/plumbing/protocol/packp/uppackreq_test.go index 5a6eb2c..ad38565 100644 --- a/plumbing/protocol/packp/uppackreq_test.go +++ b/plumbing/protocol/packp/uppackreq_test.go @@ -41,6 +41,13 @@ func (s *UploadPackRequestSuite) TestIsEmpty(c *C) { r.Haves = append(r.Haves, plumbing.NewHash("d82f291cde9987322c8a0c81a325e1ba6159684c")) c.Assert(r.IsEmpty(), Equals, true) + + r = NewUploadPackRequest() + r.Wants = append(r.Wants, plumbing.NewHash("d82f291cde9987322c8a0c81a325e1ba6159684c")) + r.Haves = append(r.Haves, plumbing.NewHash("d82f291cde9987322c8a0c81a325e1ba6159684c")) + r.Shallows = append(r.Shallows, plumbing.NewHash("2b41ef280fdb67a9b250678686a0c3e03b0a9989")) + + c.Assert(r.IsEmpty(), Equals, false) } type UploadHavesSuite struct{} diff --git a/plumbing/transport/internal/common/common.go b/plumbing/transport/internal/common/common.go index 99e0850..5fdf425 100644 --- a/plumbing/transport/internal/common/common.go +++ b/plumbing/transport/internal/common/common.go @@ -232,7 +232,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 } |