Skip to content

Commit

Permalink
plumbing: packp, A request is not empty if it contains shallows. Fixes
Browse files Browse the repository at this point in the history
…#328

Signed-off-by: Arieh Schneier <15041913+AriehSchneier@users.noreply.github.com>
  • Loading branch information
AriehSchneier committed Jun 15, 2023
1 parent 35f7e67 commit bdede12
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
6 changes: 3 additions & 3 deletions plumbing/protocol/packp/uppackreq.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 7 additions & 0 deletions plumbing/protocol/packp/uppackreq_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down
2 changes: 1 addition & 1 deletion plumbing/transport/internal/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit bdede12

Please sign in to comment.