aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/transport
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
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')
-rw-r--r--plumbing/transport/common.go7
-rw-r--r--plumbing/transport/fetch_pack.go177
-rw-r--r--plumbing/transport/fetch_pack_test.go119
-rw-r--r--plumbing/transport/http/fetch_pack.go49
-rw-r--r--plumbing/transport/http/fetch_pack_test.go21
-rw-r--r--plumbing/transport/http/send_pack.go6
-rw-r--r--plumbing/transport/ssh/fetch_pack.go44
-rw-r--r--plumbing/transport/ssh/send_pack.go4
-rw-r--r--plumbing/transport/test/common.go13
9 files changed, 87 insertions, 353 deletions
diff --git a/plumbing/transport/common.go b/plumbing/transport/common.go
index 8329069..2f6fcee 100644
--- a/plumbing/transport/common.go
+++ b/plumbing/transport/common.go
@@ -20,6 +20,7 @@ import (
"regexp"
"gopkg.in/src-d/go-git.v4/plumbing"
+ "gopkg.in/src-d/go-git.v4/plumbing/protocol/packp"
)
var (
@@ -63,10 +64,10 @@ type FetchPackSession interface {
// AdvertisedReferences retrieves the advertised references for a
// repository. It should be called before FetchPack, and it cannot be
// called after FetchPack.
- AdvertisedReferences() (*UploadPackInfo, error)
+ AdvertisedReferences() (*packp.AdvRefs, error)
// FetchPack takes a request and returns a reader for the packfile
// received from the server.
- FetchPack(req *UploadPackRequest) (io.ReadCloser, error)
+ FetchPack(req *packp.UploadPackRequest) (io.ReadCloser, error)
}
// FetchPackSession represents a git-send-pack session.
@@ -78,7 +79,7 @@ type SendPackSession interface {
// AdvertisedReferences retrieves the advertised references for a
// repository. It should be called before FetchPack, and it cannot be
// called after FetchPack.
- AdvertisedReferences() (*UploadPackInfo, error)
+ AdvertisedReferences() (*packp.AdvRefs, error)
// UpdateReferences sends an update references request and returns a
// writer to be used for packfile writing.
//TODO: Complete signature.
diff --git a/plumbing/transport/fetch_pack.go b/plumbing/transport/fetch_pack.go
deleted file mode 100644
index 14d3e19..0000000
--- a/plumbing/transport/fetch_pack.go
+++ /dev/null
@@ -1,177 +0,0 @@
-package transport
-
-import (
- "bytes"
- "fmt"
- "io"
- "io/ioutil"
- "strings"
-
- "gopkg.in/src-d/go-git.v4/plumbing"
- "gopkg.in/src-d/go-git.v4/plumbing/format/pktline"
- "gopkg.in/src-d/go-git.v4/plumbing/protocol/packp"
- "gopkg.in/src-d/go-git.v4/plumbing/storer"
- "gopkg.in/src-d/go-git.v4/storage/memory"
-)
-
-//TODO: Replace this by packpAdvRefs.
-type UploadPackInfo struct {
- Capabilities *packp.Capabilities
- Refs memory.ReferenceStorage
-}
-
-func NewUploadPackInfo() *UploadPackInfo {
- return &UploadPackInfo{
- Capabilities: packp.NewCapabilities(),
- Refs: make(memory.ReferenceStorage, 0),
- }
-}
-
-func (i *UploadPackInfo) Decode(r io.Reader) error {
- d := packp.NewAdvRefsDecoder(r)
- ar := packp.NewAdvRefs()
- if err := d.Decode(ar); err != nil {
- if err == packp.ErrEmpty {
- return err
- }
- return plumbing.NewUnexpectedError(err)
- }
-
- i.Capabilities = ar.Capabilities
-
- if err := i.addRefs(ar); err != nil {
- return plumbing.NewUnexpectedError(err)
- }
-
- return nil
-}
-
-func (i *UploadPackInfo) addRefs(ar *packp.AdvRefs) error {
- for name, hash := range ar.References {
- ref := plumbing.NewReferenceFromStrings(name, hash.String())
- i.Refs.SetReference(ref)
- }
-
- return i.addSymbolicRefs(ar)
-}
-
-func (i *UploadPackInfo) addSymbolicRefs(ar *packp.AdvRefs) error {
- if !hasSymrefs(ar) {
- return nil
- }
-
- for _, symref := range ar.Capabilities.Get("symref").Values {
- chunks := strings.Split(symref, ":")
- if len(chunks) != 2 {
- err := fmt.Errorf("bad number of `:` in symref value (%q)", symref)
- return plumbing.NewUnexpectedError(err)
- }
- name := plumbing.ReferenceName(chunks[0])
- target := plumbing.ReferenceName(chunks[1])
- ref := plumbing.NewSymbolicReference(name, target)
- i.Refs.SetReference(ref)
- }
-
- return nil
-}
-
-func hasSymrefs(ar *packp.AdvRefs) bool {
- return ar.Capabilities.Supports("symref")
-}
-
-func (i *UploadPackInfo) Head() *plumbing.Reference {
- ref, _ := storer.ResolveReference(i.Refs, plumbing.HEAD)
- return ref
-}
-
-func (i *UploadPackInfo) String() string {
- return string(i.Bytes())
-}
-
-func (i *UploadPackInfo) Bytes() []byte {
- var buf bytes.Buffer
- e := pktline.NewEncoder(&buf)
-
- _ = e.EncodeString("# service=git-upload-pack\n")
-
- // inserting a flush-pkt here violates the protocol spec, but some
- // servers do it, like Github.com
- e.Flush()
-
- _ = e.Encodef("%s HEAD\x00%s\n", i.Head().Hash(), i.Capabilities.String())
-
- for _, ref := range i.Refs {
- if ref.Type() != plumbing.HashReference {
- continue
- }
-
- _ = e.Encodef("%s %s\n", ref.Hash(), ref.Name())
- }
-
- e.Flush()
-
- return buf.Bytes()
-}
-
-type UploadPackRequest struct {
- Wants []plumbing.Hash
- Haves []plumbing.Hash
- Depth int
-}
-
-func (r *UploadPackRequest) Want(h ...plumbing.Hash) {
- r.Wants = append(r.Wants, h...)
-}
-
-func (r *UploadPackRequest) Have(h ...plumbing.Hash) {
- r.Haves = append(r.Haves, h...)
-}
-
-func (r *UploadPackRequest) IsEmpty() bool {
- return isSubset(r.Wants, r.Haves)
-}
-
-func isSubset(needle []plumbing.Hash, haystack []plumbing.Hash) bool {
- for _, h := range needle {
- found := false
- for _, oh := range haystack {
- if h == oh {
- found = true
- break
- }
- }
-
- if !found {
- return false
- }
- }
-
- return true
-}
-
-func (r *UploadPackRequest) String() string {
- b, _ := ioutil.ReadAll(r.Reader())
- return string(b)
-}
-
-func (r *UploadPackRequest) Reader() *strings.Reader {
- 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 != 0 {
- _ = e.Encodef("deepen %d\n", r.Depth)
- }
-
- _ = e.Flush()
- _ = e.EncodeString("done\n")
-
- return strings.NewReader(buf.String())
-}
diff --git a/plumbing/transport/fetch_pack_test.go b/plumbing/transport/fetch_pack_test.go
deleted file mode 100644
index fc77fe2..0000000
--- a/plumbing/transport/fetch_pack_test.go
+++ /dev/null
@@ -1,119 +0,0 @@
-package transport
-
-import (
- "bytes"
- "encoding/base64"
-
- "gopkg.in/src-d/go-git.v4/plumbing"
- "gopkg.in/src-d/go-git.v4/plumbing/protocol/packp"
-
- . "gopkg.in/check.v1"
-)
-
-type UploadPackSuite struct{}
-
-var _ = Suite(&UploadPackSuite{})
-
-const UploadPackInfoFixture = "MDAxZSMgc2VydmljZT1naXQtdXBsb2FkLXBhY2sKMDAwMDAxMGM2ZWNmMGVmMmMyZGZmYjc5NjAzM2U1YTAyMjE5YWY4NmVjNjU4NGU1IEhFQUQAbXVsdGlfYWNrIHRoaW4tcGFjayBzaWRlLWJhbmQgc2lkZS1iYW5kLTY0ayBvZnMtZGVsdGEgc2hhbGxvdyBuby1wcm9ncmVzcyBpbmNsdWRlLXRhZyBtdWx0aV9hY2tfZGV0YWlsZWQgbm8tZG9uZSBzeW1yZWY9SEVBRDpyZWZzL2hlYWRzL21hc3RlciBhZ2VudD1naXQvMjoyLjQuOH5kYnVzc2luay1maXgtZW50ZXJwcmlzZS10b2tlbnMtY29tcGlsYXRpb24tMTE2Ny1nYzcwMDZjZgowMDNmZThkM2ZmYWI1NTI4OTVjMTliOWZjZjdhYTI2NGQyNzdjZGUzMzg4MSByZWZzL2hlYWRzL2JyYW5jaAowMDNmNmVjZjBlZjJjMmRmZmI3OTYwMzNlNWEwMjIxOWFmODZlYzY1ODRlNSByZWZzL2hlYWRzL21hc3RlcgowMDNlYjhlNDcxZjU4YmNiY2E2M2IwN2JkYTIwZTQyODE5MDQwOWMyZGI0NyByZWZzL3B1bGwvMS9oZWFkCjAwMDA="
-
-func (s *UploadPackSuite) TestUploadPackInfo(c *C) {
- b, _ := base64.StdEncoding.DecodeString(UploadPackInfoFixture)
-
- i := NewUploadPackInfo()
- err := i.Decode(bytes.NewBuffer(b))
- c.Assert(err, IsNil)
-
- name := i.Capabilities.SymbolicReference("HEAD")
- c.Assert(name, Equals, "refs/heads/master")
- c.Assert(i.Refs, HasLen, 4)
-
- ref := i.Refs[plumbing.ReferenceName(name)]
- c.Assert(ref, NotNil)
- c.Assert(ref.Hash().String(), Equals, "6ecf0ef2c2dffb796033e5a02219af86ec6584e5")
-
- ref = i.Refs[plumbing.HEAD]
- c.Assert(ref, NotNil)
- c.Assert(ref.Target(), Equals, plumbing.ReferenceName(name))
-}
-
-const UploadPackInfoNoHEADFixture = "MDAxZSMgc2VydmljZT1naXQtdXBsb2FkLXBhY2sKMDAwMDAwYmNkN2UxZmVlMjYxMjM0YmIzYTQzYzA5NmY1NTg3NDhhNTY5ZDc5ZWZmIHJlZnMvaGVhZHMvdjQAbXVsdGlfYWNrIHRoaW4tcGFjayBzaWRlLWJhbmQgc2lkZS1iYW5kLTY0ayBvZnMtZGVsdGEgc2hhbGxvdyBuby1wcm9ncmVzcyBpbmNsdWRlLXRhZyBtdWx0aV9hY2tfZGV0YWlsZWQgbm8tZG9uZSBhZ2VudD1naXQvMS45LjEKMDAwMA=="
-
-func (s *UploadPackSuite) TestUploadPackInfoNoHEAD(c *C) {
- b, _ := base64.StdEncoding.DecodeString(UploadPackInfoNoHEADFixture)
-
- i := NewUploadPackInfo()
- err := i.Decode(bytes.NewBuffer(b))
- c.Assert(err, IsNil)
-
- name := i.Capabilities.SymbolicReference("HEAD")
- c.Assert(name, Equals, "")
- c.Assert(i.Refs, HasLen, 1)
-
- ref := i.Refs["refs/heads/v4"]
- c.Assert(ref, NotNil)
- c.Assert(ref.Hash().String(), Equals, "d7e1fee261234bb3a43c096f558748a569d79eff")
-}
-
-func (s *UploadPackSuite) TestUploadPackInfoEmpty(c *C) {
- b := bytes.NewBuffer(nil)
-
- i := NewUploadPackInfo()
- err := i.Decode(b)
- c.Assert(err, Equals, packp.ErrEmpty)
-}
-
-func (s *UploadPackSuite) TestUploadPackEncode(c *C) {
- info := NewUploadPackInfo()
- info.Capabilities.Add("symref", "HEAD:refs/heads/master")
-
- ref := plumbing.ReferenceName("refs/heads/master")
- hash := plumbing.NewHash("6ecf0ef2c2dffb796033e5a02219af86ec6584e5")
- info.Refs = map[plumbing.ReferenceName]*plumbing.Reference{
- plumbing.HEAD: plumbing.NewSymbolicReference(plumbing.HEAD, ref),
- ref: plumbing.NewHashReference(ref, hash),
- }
-
- c.Assert(info.Head(), NotNil)
- c.Assert(info.String(), Equals,
- "001e# service=git-upload-pack\n"+
- "000000506ecf0ef2c2dffb796033e5a02219af86ec6584e5 HEAD\x00symref=HEAD:refs/heads/master\n"+
- "003f6ecf0ef2c2dffb796033e5a02219af86ec6584e5 refs/heads/master\n"+
- "0000",
- )
-}
-
-func (s *UploadPackSuite) TestUploadPackRequest(c *C) {
- r := &UploadPackRequest{}
- r.Want(plumbing.NewHash("d82f291cde9987322c8a0c81a325e1ba6159684c"))
- r.Want(plumbing.NewHash("2b41ef280fdb67a9b250678686a0c3e03b0a9989"))
- r.Have(plumbing.NewHash("6ecf0ef2c2dffb796033e5a02219af86ec6584e5"))
-
- c.Assert(r.String(), Equals,
- "0032want d82f291cde9987322c8a0c81a325e1ba6159684c\n"+
- "0032want 2b41ef280fdb67a9b250678686a0c3e03b0a9989\n"+
- "0032have 6ecf0ef2c2dffb796033e5a02219af86ec6584e5\n0000"+
- "0009done\n",
- )
-}
-
-func (s *UploadPackSuite) TestUploadPackRequest_IsEmpty(c *C) {
- r := &UploadPackRequest{}
- r.Want(plumbing.NewHash("d82f291cde9987322c8a0c81a325e1ba6159684c"))
- r.Want(plumbing.NewHash("2b41ef280fdb67a9b250678686a0c3e03b0a9989"))
- r.Have(plumbing.NewHash("6ecf0ef2c2dffb796033e5a02219af86ec6584e5"))
-
- c.Assert(r.IsEmpty(), Equals, false)
-
- r = &UploadPackRequest{}
- r.Want(plumbing.NewHash("d82f291cde9987322c8a0c81a325e1ba6159684c"))
- r.Want(plumbing.NewHash("2b41ef280fdb67a9b250678686a0c3e03b0a9989"))
- r.Have(plumbing.NewHash("d82f291cde9987322c8a0c81a325e1ba6159684c"))
-
- c.Assert(r.IsEmpty(), Equals, false)
-
- r = &UploadPackRequest{}
- r.Want(plumbing.NewHash("d82f291cde9987322c8a0c81a325e1ba6159684c"))
- r.Have(plumbing.NewHash("d82f291cde9987322c8a0c81a325e1ba6159684c"))
-
- c.Assert(r.IsEmpty(), Equals, true)
-}
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
+}
diff --git a/plumbing/transport/http/fetch_pack_test.go b/plumbing/transport/http/fetch_pack_test.go
index c7666c8..7471208 100644
--- a/plumbing/transport/http/fetch_pack_test.go
+++ b/plumbing/transport/http/fetch_pack_test.go
@@ -1,6 +1,10 @@
package http
import (
+ "io/ioutil"
+
+ "gopkg.in/src-d/go-git.v4/plumbing"
+ "gopkg.in/src-d/go-git.v4/plumbing/protocol/packp"
"gopkg.in/src-d/go-git.v4/plumbing/transport"
"gopkg.in/src-d/go-git.v4/plumbing/transport/test"
@@ -36,3 +40,20 @@ func (s *FetchPackSuite) TestInfoNotExists(c *C) {
c.Assert(err, Equals, transport.ErrAuthorizationRequired)
c.Assert(info, IsNil)
}
+
+func (s *FetchPackSuite) TestuploadPackRequestToReader(c *C) {
+ r := packp.NewUploadPackRequest()
+ r.Want(plumbing.NewHash("d82f291cde9987322c8a0c81a325e1ba6159684c"))
+ r.Want(plumbing.NewHash("2b41ef280fdb67a9b250678686a0c3e03b0a9989"))
+ r.Have(plumbing.NewHash("6ecf0ef2c2dffb796033e5a02219af86ec6584e5"))
+
+ sr, err := uploadPackRequestToReader(r)
+ c.Assert(err, IsNil)
+ b, _ := ioutil.ReadAll(sr)
+ c.Assert(string(b), Equals,
+ "0032want d82f291cde9987322c8a0c81a325e1ba6159684c\n"+
+ "0032want 2b41ef280fdb67a9b250678686a0c3e03b0a9989\n"+
+ "0032have 6ecf0ef2c2dffb796033e5a02219af86ec6584e5\n0000"+
+ "0009done\n",
+ )
+}
diff --git a/plumbing/transport/http/send_pack.go b/plumbing/transport/http/send_pack.go
index 39be95c..5e3b2bb 100644
--- a/plumbing/transport/http/send_pack.go
+++ b/plumbing/transport/http/send_pack.go
@@ -5,12 +5,13 @@ import (
"io"
"net/http"
+ "gopkg.in/src-d/go-git.v4/plumbing/protocol/packp"
"gopkg.in/src-d/go-git.v4/plumbing/transport"
)
var errSendPackNotSupported = errors.New("send-pack not supported yet")
-type sendPackSession struct{
+type sendPackSession struct {
*session
}
@@ -18,8 +19,7 @@ func newSendPackSession(c *http.Client, ep transport.Endpoint) transport.SendPac
return &sendPackSession{&session{}}
}
-func (s *sendPackSession) AdvertisedReferences() (*transport.UploadPackInfo,
- error) {
+func (s *sendPackSession) AdvertisedReferences() (*packp.AdvRefs, error) {
return nil, errSendPackNotSupported
}
diff --git a/plumbing/transport/ssh/fetch_pack.go b/plumbing/transport/ssh/fetch_pack.go
index decd9c4..a0f52f1 100644
--- a/plumbing/transport/ssh/fetch_pack.go
+++ b/plumbing/transport/ssh/fetch_pack.go
@@ -35,7 +35,7 @@ func newFetchPackSession(ep transport.Endpoint) (*fetchPackSession, error) {
return s, nil
}
-func (s *fetchPackSession) AdvertisedReferences() (*transport.UploadPackInfo, error) {
+func (s *fetchPackSession) AdvertisedReferences() (*packp.AdvRefs, error) {
if s.advRefsRun {
return nil, transport.ErrAdvertistedReferencesAlreadyCalled
}
@@ -46,9 +46,9 @@ func (s *fetchPackSession) AdvertisedReferences() (*transport.UploadPackInfo, er
return nil, err
}
- i := transport.NewUploadPackInfo()
- if err := i.Decode(s.stdout); err != nil {
- if err != packp.ErrEmpty {
+ ar := packp.NewAdvRefs()
+ if err := ar.Decode(s.stdout); err != nil {
+ if err != packp.ErrEmptyAdvRefs {
return nil, err
}
@@ -65,12 +65,12 @@ func (s *fetchPackSession) AdvertisedReferences() (*transport.UploadPackInfo, er
return nil, err
}
- return i, nil
+ return ar, nil
}
// FetchPack returns a packfile for a given upload request.
// Closing the returned reader will close the SSH session.
-func (s *fetchPackSession) FetchPack(req *transport.UploadPackRequest) (
+func (s *fetchPackSession) FetchPack(req *packp.UploadPackRequest) (
io.ReadCloser, error) {
if req.IsEmpty() {
@@ -161,13 +161,13 @@ var (
// 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 *transport.UploadPackRequest) error {
+ req *packp.UploadPackRequest) error {
- if err := sendUlReq(w, req); err != nil {
+ if err := req.UploadRequest.Encode(w); err != nil {
return fmt.Errorf("sending upload-req message: %s", err)
}
- if err := sendHaves(w, req); err != nil {
+ if err := req.UploadHaves.Encode(w); err != nil {
return fmt.Errorf("sending haves message: %s", err)
}
@@ -186,32 +186,6 @@ func fetchPack(w io.WriteCloser, r io.Reader,
return nil
}
-func sendUlReq(w io.Writer, req *transport.UploadPackRequest) error {
- ur := packp.NewUlReq()
- ur.Wants = req.Wants
- ur.Depth = packp.DepthCommits(req.Depth)
- e := packp.NewUlReqEncoder(w)
-
- return e.Encode(ur)
-}
-
-func sendHaves(w io.Writer, req *transport.UploadPackRequest) error {
- e := pktline.NewEncoder(w)
- for _, have := range req.Haves {
- if err := e.Encodef("have %s\n", have); err != nil {
- return fmt.Errorf("sending haves for %q: %s", have, err)
- }
- }
-
- if len(req.Haves) != 0 {
- if err := e.Flush(); err != nil {
- return fmt.Errorf("sending flush-pkt after haves: %s", err)
- }
- }
-
- return nil
-}
-
func sendDone(w io.Writer) error {
e := pktline.NewEncoder(w)
diff --git a/plumbing/transport/ssh/send_pack.go b/plumbing/transport/ssh/send_pack.go
index afe7510..adf67bb 100644
--- a/plumbing/transport/ssh/send_pack.go
+++ b/plumbing/transport/ssh/send_pack.go
@@ -4,6 +4,7 @@ import (
"errors"
"io"
+ "gopkg.in/src-d/go-git.v4/plumbing/protocol/packp"
"gopkg.in/src-d/go-git.v4/plumbing/transport"
)
@@ -19,8 +20,7 @@ func newSendPackSession(ep transport.Endpoint) (transport.SendPackSession,
return &sendPackSession{&session{}}, nil
}
-func (s *sendPackSession) AdvertisedReferences() (*transport.UploadPackInfo,
- error) {
+func (s *sendPackSession) AdvertisedReferences() (*packp.AdvRefs, error) {
return nil, errSendPackNotSupported
}
diff --git a/plumbing/transport/test/common.go b/plumbing/transport/test/common.go
index 059c0c9..7818fbb 100644
--- a/plumbing/transport/test/common.go
+++ b/plumbing/transport/test/common.go
@@ -10,6 +10,7 @@ import (
"gopkg.in/src-d/go-git.v4/plumbing"
"gopkg.in/src-d/go-git.v4/plumbing/format/packfile"
+ "gopkg.in/src-d/go-git.v4/plumbing/protocol/packp"
"gopkg.in/src-d/go-git.v4/plumbing/transport"
"gopkg.in/src-d/go-git.v4/storage/memory"
@@ -40,7 +41,7 @@ func (s *FetchPackSuite) TestInfoNotExists(c *C) {
r, err = s.Client.NewFetchPackSession(s.NonExistentEndpoint)
c.Assert(err, IsNil)
- req := &transport.UploadPackRequest{}
+ req := packp.NewUploadPackRequest()
req.Want(plumbing.NewHash("6ecf0ef2c2dffb796033e5a02219af86ec6584e5"))
reader, err := r.FetchPack(req)
c.Assert(err, Equals, transport.ErrRepositoryNotFound)
@@ -85,7 +86,7 @@ func (s *FetchPackSuite) TestFullFetchPack(c *C) {
c.Assert(err, IsNil)
c.Assert(info, NotNil)
- req := &transport.UploadPackRequest{}
+ req := packp.NewUploadPackRequest()
req.Want(plumbing.NewHash("6ecf0ef2c2dffb796033e5a02219af86ec6584e5"))
reader, err := r.FetchPack(req)
@@ -99,7 +100,7 @@ func (s *FetchPackSuite) TestFetchPack(c *C) {
c.Assert(err, IsNil)
defer func() { c.Assert(r.Close(), IsNil) }()
- req := &transport.UploadPackRequest{}
+ req := packp.NewUploadPackRequest()
req.Want(plumbing.NewHash("6ecf0ef2c2dffb796033e5a02219af86ec6584e5"))
reader, err := r.FetchPack(req)
@@ -113,7 +114,7 @@ func (s *FetchPackSuite) TestFetchPackNoChanges(c *C) {
c.Assert(err, IsNil)
defer func() { c.Assert(r.Close(), IsNil) }()
- req := &transport.UploadPackRequest{}
+ req := packp.NewUploadPackRequest()
req.Want(plumbing.NewHash("6ecf0ef2c2dffb796033e5a02219af86ec6584e5"))
req.Have(plumbing.NewHash("6ecf0ef2c2dffb796033e5a02219af86ec6584e5"))
@@ -127,7 +128,7 @@ func (s *FetchPackSuite) TestFetchPackMulti(c *C) {
c.Assert(err, IsNil)
defer func() { c.Assert(r.Close(), IsNil) }()
- req := &transport.UploadPackRequest{}
+ req := packp.NewUploadPackRequest()
req.Want(plumbing.NewHash("6ecf0ef2c2dffb796033e5a02219af86ec6584e5"))
req.Want(plumbing.NewHash("e8d3ffab552895c19b9fcf7aa264d277cde33881"))
@@ -141,7 +142,7 @@ func (s *FetchPackSuite) TestFetchError(c *C) {
r, err := s.Client.NewFetchPackSession(s.Endpoint)
c.Assert(err, IsNil)
- req := &transport.UploadPackRequest{}
+ req := packp.NewUploadPackRequest()
req.Want(plumbing.NewHash("1111111111111111111111111111111111111111"))
reader, err := r.FetchPack(req)