diff options
author | Santiago M. Mola <santi@mola.io> | 2016-12-09 14:44:03 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-12-09 14:44:03 +0100 |
commit | 0e1a52757a3938e97cf7d31e0dff3c9949001763 (patch) | |
tree | 8b998fdc3eaaf6b2d6c69a125759a778664207a5 /plumbing/protocol/packp/updreq_decode.go | |
parent | 4f16cc925238aae81586e917d26b8ff6b6a340bd (diff) | |
download | go-git-0e1a52757a3938e97cf7d31e0dff3c9949001763.tar.gz |
transport: add git-send-pack support to local/ssh. (#163)
* protocol/packp: add Packfile field to ReferenceUpdateRequest.
* protocol/packp: add NewReferenceUpdateRequestFromCapabilities.
* NewReferenceUpdateRequestFromCapabilities can be used to create
a ReferenceUpdateRequest with initial capabilities compatible with
the server.
* protocol/packp: fix new line handling on report status.
* transport/file: test error on unexisting command.
Diffstat (limited to 'plumbing/protocol/packp/updreq_decode.go')
-rw-r--r-- | plumbing/protocol/packp/updreq_decode.go | 36 |
1 files changed, 26 insertions, 10 deletions
diff --git a/plumbing/protocol/packp/updreq_decode.go b/plumbing/protocol/packp/updreq_decode.go index 0740871..2ebe2a3 100644 --- a/plumbing/protocol/packp/updreq_decode.go +++ b/plumbing/protocol/packp/updreq_decode.go @@ -6,6 +6,7 @@ import ( "errors" "fmt" "io" + "io/ioutil" "gopkg.in/src-d/go-git.v4/plumbing" "gopkg.in/src-d/go-git.v4/plumbing/format/pktline" @@ -76,23 +77,32 @@ func errMalformedCommand(err error) error { // Decode reads the next update-request message form the reader and wr func (req *ReferenceUpdateRequest) Decode(r io.Reader) error { - d := &updReqDecoder{s: pktline.NewScanner(r)} + var rc io.ReadCloser + var ok bool + rc, ok = r.(io.ReadCloser) + if !ok { + rc = ioutil.NopCloser(r) + } + + d := &updReqDecoder{r: rc, s: pktline.NewScanner(r)} return d.Decode(req) } type updReqDecoder struct { - s *pktline.Scanner - r *ReferenceUpdateRequest + r io.ReadCloser + s *pktline.Scanner + req *ReferenceUpdateRequest } -func (d *updReqDecoder) Decode(r *ReferenceUpdateRequest) error { - d.r = r +func (d *updReqDecoder) Decode(req *ReferenceUpdateRequest) error { + d.req = req funcs := []func() error{ d.scanLine, d.decodeShallow, d.decodeCommandAndCapabilities, d.decodeCommands, - r.validate, + d.setPackfile, + req.validate, } for _, f := range funcs { @@ -132,7 +142,7 @@ func (d *updReqDecoder) decodeShallow() error { return d.scanErrorOr(errNoCommands) } - d.r.Shallow = &h + d.req.Shallow = &h return nil } @@ -149,7 +159,7 @@ func (d *updReqDecoder) decodeCommands() error { return err } - d.r.Commands = append(d.r.Commands, c) + d.req.Commands = append(d.req.Commands, c) if ok := d.s.Scan(); !ok { return d.s.Err() @@ -173,9 +183,9 @@ func (d *updReqDecoder) decodeCommandAndCapabilities() error { return err } - d.r.Commands = append(d.r.Commands, cmd) + d.req.Commands = append(d.req.Commands, cmd) - if err := d.r.Capabilities.Decode(b[i+1:]); err != nil { + if err := d.req.Capabilities.Decode(b[i+1:]); err != nil { return err } @@ -186,6 +196,12 @@ func (d *updReqDecoder) decodeCommandAndCapabilities() error { return nil } +func (d *updReqDecoder) setPackfile() error { + d.req.Packfile = d.r + + return nil +} + func parseCommand(b []byte) (*Command, error) { if len(b) < minCommandLength { return nil, errInvalidCommandLineLength(len(b)) |