diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2016-12-07 11:16:59 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-12-07 11:16:59 +0100 |
commit | 01ea726be6ed745a21c88fd61fc5e2a62c4ceb88 (patch) | |
tree | 8e0cbfe502afb3187d93e8da95cc1677794c6df5 /remote.go | |
parent | 5990aeb7198a4961a363eeb422a3faa57c8dc029 (diff) | |
download | go-git-01ea726be6ed745a21c88fd61fc5e2a62c4ceb88.tar.gz |
remote: sideband support (#164)
* remote: sideband support
* changes
Diffstat (limited to 'remote.go')
-rw-r--r-- | remote.go | 33 |
1 files changed, 30 insertions, 3 deletions
@@ -10,6 +10,7 @@ import ( "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/protocol/packp/capability" + "gopkg.in/src-d/go-git.v4/plumbing/protocol/packp/sideband" "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" @@ -22,6 +23,7 @@ var NoErrAlreadyUpToDate = errors.New("already up-to-date") type Remote struct { c *config.RemoteConfig s Storer + p sideband.Progress // cache fields, there during the connection is open endpoint transport.Endpoint @@ -31,8 +33,8 @@ type Remote struct { refs memory.ReferenceStorage } -func newRemote(s Storer, c *config.RemoteConfig) *Remote { - return &Remote{s: s, c: c} +func newRemote(s Storer, p sideband.Progress, c *config.RemoteConfig) *Remote { + return &Remote{s: s, p: p, c: c} } // Config return the config @@ -125,7 +127,10 @@ func (r *Remote) Fetch(o *FetchOptions) (err error) { } defer checkClose(reader, &err) - if err := r.updateObjectStorage(reader); err != nil { + + if err = r.updateObjectStorage( + r.buildSidebandIfSupported(req.Capabilities, reader), + ); err != nil { return err } @@ -178,6 +183,10 @@ func (r *Remote) buildRequest( req.Capabilities.Set(capability.Shallow) } + if r.p == nil && r.advRefs.Capabilities.Supports(capability.NoProgress) { + req.Capabilities.Set(capability.NoProgress) + } + for _, ref := range refs { req.Wants = append(req.Wants, ref.Hash()) } @@ -221,6 +230,24 @@ func (r *Remote) updateObjectStorage(reader io.Reader) error { return err } +func (r *Remote) buildSidebandIfSupported(l *capability.List, reader io.Reader) io.Reader { + var t sideband.Type + + switch { + case l.Supports(capability.Sideband): + t = sideband.Sideband + case l.Supports(capability.Sideband64k): + t = sideband.Sideband64k + default: + return reader + } + + d := sideband.NewDemuxer(t, reader) + d.Progress = r.p + + return d +} + func (r *Remote) updateLocalReferenceStorage(specs []config.RefSpec, refs []*plumbing.Reference) error { for _, spec := range specs { for _, ref := range refs { |