diff options
author | Santiago M. Mola <santi@mola.io> | 2016-11-23 15:30:34 +0100 |
---|---|---|
committer | Máximo Cuadros <mcuadros@gmail.com> | 2016-11-23 15:38:12 +0100 |
commit | 08e08d771ef03df80248c80d81475fe7c5ea6fe7 (patch) | |
tree | d12e9befa22409e8cf50c5bbc4895e69fd8a5f48 /remote.go | |
parent | 844169a739fb8bf1f252d416f10d8c7034db9fe2 (diff) | |
download | go-git-08e08d771ef03df80248c80d81475fe7c5ea6fe7.tar.gz |
transport: create Client interface (#132)
* plumbing: move plumbing/client package to plumbing/transport.
* transport: create Client interface.
* A Client can instantiate any client transport service.
* InstallProtocol installs a Client for a given protocol,
instead of just a UploadPackService.
* A Client can open a session for fetch-pack or send-pack
for a specific Endpoint.
* Adapt ssh and http clients to the new client interface.
* updated doc
Diffstat (limited to 'remote.go')
-rw-r--r-- | remote.go | 43 |
1 files changed, 28 insertions, 15 deletions
@@ -7,11 +7,11 @@ import ( "gopkg.in/src-d/go-git.v4/config" "gopkg.in/src-d/go-git.v4/plumbing" - "gopkg.in/src-d/go-git.v4/plumbing/client" - "gopkg.in/src-d/go-git.v4/plumbing/client/common" "gopkg.in/src-d/go-git.v4/plumbing/format/packfile" "gopkg.in/src-d/go-git.v4/plumbing/format/packp" "gopkg.in/src-d/go-git.v4/plumbing/storer" + "gopkg.in/src-d/go-git.v4/plumbing/transport" + "gopkg.in/src-d/go-git.v4/plumbing/transport/client" ) var NoErrAlreadyUpToDate = errors.New("already up-to-date") @@ -22,8 +22,10 @@ type Remote struct { s Storer // cache fields, there during the connection is open - upSrv common.GitUploadPackService - upInfo *common.GitUploadPackInfo + endpoint transport.Endpoint + client transport.Client + fetchSession transport.FetchPackSession + upInfo *transport.UploadPackInfo } func newRemote(s Storer, c *config.RemoteConfig) *Remote { @@ -37,35 +39,46 @@ func (r *Remote) Config() *config.RemoteConfig { // Connect with the endpoint func (r *Remote) Connect() error { - if err := r.connectUploadPackService(); err != nil { + if err := r.initClient(); err != nil { return err } + var err error + r.fetchSession, err = r.client.NewFetchPackSession(r.endpoint) + if err != nil { + return nil + } + return r.retrieveUpInfo() } -func (r *Remote) connectUploadPackService() error { - endpoint, err := common.NewEndpoint(r.c.URL) +func (r *Remote) initClient() error { + var err error + r.endpoint, err = transport.NewEndpoint(r.c.URL) if err != nil { return err } - r.upSrv, err = clients.NewGitUploadPackService(endpoint) + if r.client != nil { + return nil + } + + r.client, err = client.NewClient(r.endpoint) if err != nil { return err } - return r.upSrv.Connect() + return nil } func (r *Remote) retrieveUpInfo() error { var err error - r.upInfo, err = r.upSrv.Info() + r.upInfo, err = r.fetchSession.AdvertisedReferences() return err } // Info returns the git-upload-pack info -func (r *Remote) Info() *common.GitUploadPackInfo { +func (r *Remote) Info() *transport.UploadPackInfo { return r.upInfo } @@ -98,7 +111,7 @@ func (r *Remote) Fetch(o *FetchOptions) (err error) { return err } - reader, err := r.upSrv.Fetch(req) + reader, err := r.fetchSession.FetchPack(req) if err != nil { return err } @@ -149,8 +162,8 @@ func (r *Remote) getWantedReferences(spec []config.RefSpec) ([]*plumbing.Referen func (r *Remote) buildRequest( s storer.ReferenceStorer, o *FetchOptions, refs []*plumbing.Reference, -) (*common.GitUploadPackRequest, error) { - req := &common.GitUploadPackRequest{} +) (*transport.UploadPackRequest, error) { + req := &transport.UploadPackRequest{} req.Depth = o.Depth for _, ref := range refs { @@ -264,7 +277,7 @@ func (r *Remote) Refs() (storer.ReferenceIter, error) { // Disconnect from the remote and save the config func (r *Remote) Disconnect() error { r.upInfo = nil - return r.upSrv.Disconnect() + return r.fetchSession.Close() } func (r *Remote) String() string { |