aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/transport/http/fetch_pack.go
diff options
context:
space:
mode:
authorSantiago M. Mola <santi@mola.io>2016-11-28 09:57:38 +0100
committerGitHub <noreply@github.com>2016-11-28 09:57:38 +0100
commit68893edf9ddc3de181431f1552e3b773cb66f080 (patch)
treef45e5fa18e10168a278b7d0ed7dea984ff9969f7 /plumbing/transport/http/fetch_pack.go
parentf9adb3565b36ba1573102f954d0ee916009efac2 (diff)
downloadgo-git-68893edf9ddc3de181431f1552e3b773cb66f080.tar.gz
remove old types from transport and use packp (#142)
* protocol: move UploadPackRequest to protocol. * UploadPackRequest is now defined as an embedding of UploadRequest and UploadHaves. * Move http encoding specific code from UploadPackRequest to transport/http. * rename UlReq to UploadRequest * packp: move AdvRefs Encoder/Decoder to Encode/Decode methods. * packp: move UploadRequest Encoder/Decoder to Encode/Decode methods. * packp: Remove transport.UploadPackInfo in favor of packp. AdvRefs.
Diffstat (limited to 'plumbing/transport/http/fetch_pack.go')
-rw-r--r--plumbing/transport/http/fetch_pack.go49
1 files changed, 41 insertions, 8 deletions
diff --git a/plumbing/transport/http/fetch_pack.go b/plumbing/transport/http/fetch_pack.go
index 29e385b..40c3a7f 100644
--- a/plumbing/transport/http/fetch_pack.go
+++ b/plumbing/transport/http/fetch_pack.go
@@ -31,8 +31,7 @@ func newFetchPackSession(c *http.Client,
}
}
-func (s *fetchPackSession) AdvertisedReferences() (*transport.UploadPackInfo,
- error) {
+func (s *fetchPackSession) AdvertisedReferences() (*packp.AdvRefs, error) {
if s.advRefsRun {
return nil, transport.ErrAdvertistedReferencesAlreadyCalled
}
@@ -62,19 +61,19 @@ func (s *fetchPackSession) AdvertisedReferences() (*transport.UploadPackInfo,
return nil, transport.ErrAuthorizationRequired
}
- i := transport.NewUploadPackInfo()
- if err := i.Decode(res.Body); err != nil {
- if err == packp.ErrEmpty {
+ ar := packp.NewAdvRefs()
+ if err := ar.Decode(res.Body); err != nil {
+ if err == packp.ErrEmptyAdvRefs {
err = transport.ErrEmptyRemoteRepository
}
return nil, err
}
- return i, nil
+ return ar, nil
}
-func (s *fetchPackSession) FetchPack(r *transport.UploadPackRequest) (io.ReadCloser, error) {
+func (s *fetchPackSession) FetchPack(r *packp.UploadPackRequest) (io.ReadCloser, error) {
if r.IsEmpty() {
return nil, transport.ErrEmptyUploadPackRequest
}
@@ -84,7 +83,12 @@ func (s *fetchPackSession) FetchPack(r *transport.UploadPackRequest) (io.ReadClo
s.endpoint.String(), transport.UploadPackServiceName,
)
- res, err := s.doRequest("POST", url, r.Reader())
+ content, err := uploadPackRequestToReader(r)
+ if err != nil {
+ return nil, err
+ }
+
+ res, err := s.doRequest("POST", url, content)
if err != nil {
return nil, err
}
@@ -161,3 +165,32 @@ func (s *fetchPackSession) applyHeadersToRequest(req *http.Request, content *str
req.Header.Add("Content-Length", string(content.Len()))
}
}
+
+func uploadPackRequestToReader(r *packp.UploadPackRequest) (*strings.Reader, error) {
+ var buf bytes.Buffer
+ e := pktline.NewEncoder(&buf)
+
+ for _, want := range r.Wants {
+ _ = e.Encodef("want %s\n", want)
+ }
+
+ for _, have := range r.Haves {
+ _ = e.Encodef("have %s\n", have)
+ }
+
+ if r.Depth != nil {
+ depth, ok := r.Depth.(packp.DepthCommits)
+ if !ok {
+ return nil, fmt.Errorf("only commit depth is supported")
+ }
+
+ if depth != 0 {
+ _ = e.Encodef("deepen %d\n", depth)
+ }
+ }
+
+ _ = e.Flush()
+ _ = e.EncodeString("done\n")
+
+ return strings.NewReader(buf.String()), nil
+}