diff options
author | Antonio Navarro Perez <antnavper@gmail.com> | 2017-01-25 00:30:09 +0100 |
---|---|---|
committer | Máximo Cuadros <mcuadros@gmail.com> | 2017-01-25 00:30:09 +0100 |
commit | dc45de29f87a43078356a5be4c4b5aa24f626ee0 (patch) | |
tree | a36e94fedc5d82155c67857f8e8a8632fb15ff1e | |
parent | e549c1819773fd8ab302ecd1b7650c25aafaba43 (diff) | |
download | go-git-dc45de29f87a43078356a5be4c4b5aa24f626ee0.tar.gz |
transport/http: fix partial request with haves. Fix #216. (#221)
-rw-r--r-- | plumbing/protocol/packp/uppackreq.go | 7 | ||||
-rw-r--r-- | plumbing/protocol/packp/uppackreq_test.go | 2 | ||||
-rw-r--r-- | plumbing/transport/http/upload_pack.go | 7 | ||||
-rw-r--r-- | plumbing/transport/http/upload_pack_test.go | 2 | ||||
-rw-r--r-- | plumbing/transport/internal/common/common.go | 2 | ||||
-rw-r--r-- | plumbing/transport/server/upload_pack_test.go | 5 | ||||
-rw-r--r-- | plumbing/transport/test/upload_pack.go | 15 |
7 files changed, 32 insertions, 8 deletions
diff --git a/plumbing/protocol/packp/uppackreq.go b/plumbing/protocol/packp/uppackreq.go index 84e2b4e..4bb22d0 100644 --- a/plumbing/protocol/packp/uppackreq.go +++ b/plumbing/protocol/packp/uppackreq.go @@ -68,8 +68,9 @@ type UploadHaves struct { Haves []plumbing.Hash } -// Encode encodes the UploadHaves into the Writer. -func (u *UploadHaves) Encode(w io.Writer) error { +// Encode encodes the UploadHaves into the Writer. If flush is true, a flush +// command will be encoded at the end of the writer content. +func (u *UploadHaves) Encode(w io.Writer, flush bool) error { e := pktline.NewEncoder(w) plumbing.HashesSort(u.Haves) @@ -87,7 +88,7 @@ func (u *UploadHaves) Encode(w io.Writer) error { last = have } - if len(u.Haves) != 0 { + if flush && len(u.Haves) != 0 { if err := e.Flush(); err != nil { return fmt.Errorf("sending flush-pkt after haves: %s", err) } diff --git a/plumbing/protocol/packp/uppackreq_test.go b/plumbing/protocol/packp/uppackreq_test.go index 273f916..f776c07 100644 --- a/plumbing/protocol/packp/uppackreq_test.go +++ b/plumbing/protocol/packp/uppackreq_test.go @@ -58,7 +58,7 @@ func (s *UploadHavesSuite) TestEncode(c *C) { ) buf := bytes.NewBuffer(nil) - err := uh.Encode(buf) + err := uh.Encode(buf, true) c.Assert(err, IsNil) c.Assert(buf.String(), Equals, ""+ "0032have 1111111111111111111111111111111111111111\n"+ diff --git a/plumbing/transport/http/upload_pack.go b/plumbing/transport/http/upload_pack.go index e828857..fd1787c 100644 --- a/plumbing/transport/http/upload_pack.go +++ b/plumbing/transport/http/upload_pack.go @@ -171,10 +171,13 @@ func uploadPackRequestToReader(req *packp.UploadPackRequest) (*bytes.Buffer, err return nil, fmt.Errorf("sending upload-req message: %s", err) } - if err := req.UploadHaves.Encode(buf); err != nil { + if err := req.UploadHaves.Encode(buf, false); err != nil { return nil, fmt.Errorf("sending haves message: %s", err) } - _ = e.EncodeString("done\n") + if err := e.EncodeString("done\n"); err != nil { + return nil, err + } + return buf, nil } diff --git a/plumbing/transport/http/upload_pack_test.go b/plumbing/transport/http/upload_pack_test.go index 13b7f75..a793efb 100644 --- a/plumbing/transport/http/upload_pack_test.go +++ b/plumbing/transport/http/upload_pack_test.go @@ -54,7 +54,7 @@ func (s *UploadPackSuite) TestuploadPackRequestToReader(c *C) { c.Assert(string(b), Equals, "0032want 2b41ef280fdb67a9b250678686a0c3e03b0a9989\n"+ "0032want d82f291cde9987322c8a0c81a325e1ba6159684c\n0000"+ - "0032have 6ecf0ef2c2dffb796033e5a02219af86ec6584e5\n0000"+ + "0032have 6ecf0ef2c2dffb796033e5a02219af86ec6584e5\n"+ "0009done\n", ) } diff --git a/plumbing/transport/internal/common/common.go b/plumbing/transport/internal/common/common.go index 2285e26..b459198 100644 --- a/plumbing/transport/internal/common/common.go +++ b/plumbing/transport/internal/common/common.go @@ -371,7 +371,7 @@ func uploadPack(w io.WriteCloser, r io.Reader, req *packp.UploadPackRequest) err return fmt.Errorf("sending upload-req message: %s", err) } - if err := req.UploadHaves.Encode(w); err != nil { + if err := req.UploadHaves.Encode(w, true); err != nil { return fmt.Errorf("sending haves message: %s", err) } diff --git a/plumbing/transport/server/upload_pack_test.go b/plumbing/transport/server/upload_pack_test.go index 137f887..7ba1e74 100644 --- a/plumbing/transport/server/upload_pack_test.go +++ b/plumbing/transport/server/upload_pack_test.go @@ -38,3 +38,8 @@ func (s *UploadPackSuite) TestAdvertisedReferencesNotExists(c *C) { c.Assert(err, Equals, transport.ErrRepositoryNotFound) c.Assert(r, IsNil) } + +// TODO revList implementation is returning more objects than expected. +func (s *UploadPackSuite) TestUploadPackPartial(c *C) { + c.Skip("Fix revList implementation") +} diff --git a/plumbing/transport/test/upload_pack.go b/plumbing/transport/test/upload_pack.go index c1a9050..06ae893 100644 --- a/plumbing/transport/test/upload_pack.go +++ b/plumbing/transport/test/upload_pack.go @@ -168,6 +168,21 @@ func (s *UploadPackSuite) TestUploadPackMulti(c *C) { s.checkObjectNumber(c, reader, 31) } +func (s *UploadPackSuite) TestUploadPackPartial(c *C) { + r, err := s.Client.NewUploadPackSession(s.Endpoint, s.EmptyAuth) + c.Assert(err, IsNil) + defer func() { c.Assert(r.Close(), IsNil) }() + + req := packp.NewUploadPackRequest() + req.Wants = append(req.Wants, plumbing.NewHash("6ecf0ef2c2dffb796033e5a02219af86ec6584e5")) + req.Haves = append(req.Haves, plumbing.NewHash("918c48b83bd081e863dbe1b80f8998f058cd8294")) + + reader, err := r.UploadPack(req) + c.Assert(err, IsNil) + + s.checkObjectNumber(c, reader, 4) +} + func (s *UploadPackSuite) TestFetchError(c *C) { r, err := s.Client.NewUploadPackSession(s.Endpoint, s.EmptyAuth) c.Assert(err, IsNil) |