aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/transport/internal
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2016-12-06 15:46:09 +0100
committerGitHub <noreply@github.com>2016-12-06 15:46:09 +0100
commit22fe81f342538ae51442a72356036768f7f1a2f9 (patch)
treeccfe9fcd48d3c8f349b42413f71f26ba23a4cba9 /plumbing/transport/internal
parent4b5849db76905830e0124b6b9f4294ee13308e0f (diff)
downloadgo-git-22fe81f342538ae51442a72356036768f7f1a2f9.tar.gz
protocol/packp: UploadPackResponse implementation (#161)
* plumbing/protocol: paktp avoid duplication of haves, wants and shallow * protocol/pakp: UploadPackResponse implementation * changes * changes * changes * debug * changes
Diffstat (limited to 'plumbing/transport/internal')
-rw-r--r--plumbing/transport/internal/common/common.go32
1 files changed, 11 insertions, 21 deletions
diff --git a/plumbing/transport/internal/common/common.go b/plumbing/transport/internal/common/common.go
index 8b2f9f3..f6aa204 100644
--- a/plumbing/transport/internal/common/common.go
+++ b/plumbing/transport/internal/common/common.go
@@ -7,7 +7,6 @@ package common
import (
"bufio"
- "bytes"
"errors"
"fmt"
"io"
@@ -193,7 +192,7 @@ func (s *session) AdvertisedReferences() (*packp.AdvRefs, error) {
// FetchPack 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) FetchPack(req *packp.UploadPackRequest) (io.ReadCloser, error) {
+func (s *session) FetchPack(req *packp.UploadPackRequest) (*packp.UploadPackResponse, error) {
if req.IsEmpty() {
return nil, transport.ErrEmptyUploadPackRequest
}
@@ -230,7 +229,7 @@ func (s *session) FetchPack(req *packp.UploadPackRequest) (io.ReadCloser, error)
wc := &waitCloser{s.Command}
rc := ioutil.NewReadCloser(r, wc)
- return rc, nil
+ return DecodeUploadPackResponse(rc, req)
}
func (s *session) finish() error {
@@ -314,9 +313,7 @@ var (
// TODO support multi_ack_detailed mode
// TODO support acks for common objects
// TODO build a proper state machine for all these processing options
-func fetchPack(w io.WriteCloser, r io.Reader,
- req *packp.UploadPackRequest) error {
-
+func fetchPack(w io.WriteCloser, r io.Reader, req *packp.UploadPackRequest) error {
if err := req.UploadRequest.Encode(w); err != nil {
return fmt.Errorf("sending upload-req message: %s", err)
}
@@ -333,10 +330,6 @@ func fetchPack(w io.WriteCloser, r io.Reader,
return fmt.Errorf("closing input: %s", err)
}
- if err := readNAK(r); err != nil {
- return fmt.Errorf("reading NAK: %s", err)
- }
-
return nil
}
@@ -346,19 +339,16 @@ func sendDone(w io.Writer) error {
return e.Encodef("done\n")
}
-func readNAK(r io.Reader) error {
- s := pktline.NewScanner(r)
- if !s.Scan() {
- return s.Err()
+// DecodeUploadPackResponse decodes r into a new packp.UploadPackResponse
+func DecodeUploadPackResponse(r io.ReadCloser, req *packp.UploadPackRequest) (
+ *packp.UploadPackResponse, error,
+) {
+ res := packp.NewUploadPackResponse(req)
+ if err := res.Decode(r); err != nil {
+ return nil, fmt.Errorf("error decoding upload-pack response: %s", err)
}
- b := s.Bytes()
- b = bytes.TrimSuffix(b, eol)
- if !bytes.Equal(b, nak) {
- return fmt.Errorf("expecting NAK, found %q instead", string(b))
- }
-
- return nil
+ return res, nil
}
type waitCloser struct {