aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/transport/internal/common/common.go
diff options
context:
space:
mode:
authorSantiago M. Mola <santi@mola.io>2016-12-08 14:24:25 +0100
committerGitHub <noreply@github.com>2016-12-08 14:24:25 +0100
commit7d9d9bfee34ea428a127da0df900d3a26de37c38 (patch)
tree225c5661c6be1a000c2e5cc15961c214040c7cff /plumbing/transport/internal/common/common.go
parent3962b8d4dbb2d2d61e9282d73f8d3d0f2a222461 (diff)
downloadgo-git-7d9d9bfee34ea428a127da0df900d3a26de37c38.tar.gz
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.
Diffstat (limited to 'plumbing/transport/internal/common/common.go')
-rw-r--r--plumbing/transport/internal/common/common.go21
1 files changed, 9 insertions, 12 deletions
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