From 7d9d9bfee34ea428a127da0df900d3a26de37c38 Mon Sep 17 00:00:00 2001 From: "Santiago M. Mola" Date: Thu, 8 Dec 2016 14:24:25 +0100 Subject: plumbing/transport: allow AdvertisedReferences being called multiple times. (#165) * AdvertisedReferences is now part of transport.Session. * It is allowed to be called more than once. * It is allowed to be called before and after FetchPack/SendPack. * Implementations cache its result. --- plumbing/transport/internal/common/common.go | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) (limited to 'plumbing/transport/internal/common') diff --git a/plumbing/transport/internal/common/common.go b/plumbing/transport/internal/common/common.go index 11c86ef..12f4995 100644 --- a/plumbing/transport/internal/common/common.go +++ b/plumbing/transport/internal/common/common.go @@ -99,10 +99,10 @@ type session struct { Stdout io.Reader Command Command - advRefsRun bool - packRun bool - finished bool - errLines chan string + advRefs *packp.AdvRefs + packRun bool + finished bool + errLines chan string } func (c *client) newSession(s string, ep transport.Endpoint) (*session, error) { @@ -154,12 +154,10 @@ func (s *session) SetAuth(auth transport.AuthMethod) error { // AdvertisedReferences retrieves the advertised references from the server. func (s *session) AdvertisedReferences() (*packp.AdvRefs, error) { - if s.advRefsRun { - return nil, transport.ErrAdvertistedReferencesAlreadyCalled + if s.advRefs != nil { + return s.advRefs, nil } - s.advRefsRun = true - ar := packp.NewAdvRefs() if err := ar.Decode(s.Stdout); err != nil { // If repository is not found, we get empty stdout and server @@ -187,6 +185,7 @@ func (s *session) AdvertisedReferences() (*packp.AdvRefs, error) { } transport.FilterUnsupportedCapabilities(ar.Capabilities) + s.advRefs = ar return ar, nil } @@ -201,10 +200,8 @@ func (s *session) FetchPack(req *packp.UploadPackRequest) (*packp.UploadPackResp return nil, err } - if !s.advRefsRun { - if _, err := s.AdvertisedReferences(); err != nil { - return nil, err - } + if _, err := s.AdvertisedReferences(); err != nil { + return nil, err } s.packRun = true -- cgit