Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

Commit 6aaad69

Browse files
smolamcuadros
authored andcommitted
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
1 parent ccf5bb1 commit 6aaad69

35 files changed

+1521
-1400
lines changed

common_test.go

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
package git
22

33
import (
4-
"errors"
4+
"fmt"
55
"io"
66
"os"
77
"testing"
88

99
"gopkg.in/src-d/go-git.v4/fixtures"
1010
"gopkg.in/src-d/go-git.v4/plumbing"
11-
"gopkg.in/src-d/go-git.v4/plumbing/client"
12-
"gopkg.in/src-d/go-git.v4/plumbing/client/common"
1311
"gopkg.in/src-d/go-git.v4/plumbing/format/packfile"
1412
"gopkg.in/src-d/go-git.v4/plumbing/format/packp"
13+
"gopkg.in/src-d/go-git.v4/plumbing/transport"
14+
"gopkg.in/src-d/go-git.v4/plumbing/transport/client"
1515
"gopkg.in/src-d/go-git.v4/storage/filesystem"
1616

1717
. "gopkg.in/check.v1"
@@ -36,9 +36,7 @@ func (s *BaseSuite) SetUpSuite(c *C) {
3636
}
3737

3838
func (s *BaseSuite) installMockProtocol(c *C) {
39-
clients.InstallProtocol("https", func(end common.Endpoint) common.GitUploadPackService {
40-
return &MockGitUploadPackService{endpoint: end}
41-
})
39+
client.InstallProtocol("https", &MockClient{})
4240
}
4341

4442
func (s *BaseSuite) buildRepository(c *C) {
@@ -68,38 +66,47 @@ func (s *BaseSuite) buildRepositories(c *C, f fixtures.Fixtures) {
6866

6967
const RepositoryFixture = "https://github.com/git-fixtures/basic.git"
7068

71-
type MockGitUploadPackService struct {
72-
connected bool
73-
endpoint common.Endpoint
74-
auth common.AuthMethod
69+
type MockClient struct{}
70+
71+
type MockFetchPackSession struct {
72+
endpoint transport.Endpoint
73+
auth transport.AuthMethod
7574
}
7675

77-
func (p *MockGitUploadPackService) Connect() error {
78-
p.connected = true
79-
return nil
76+
func (c *MockClient) NewFetchPackSession(ep transport.Endpoint) (
77+
transport.FetchPackSession, error) {
78+
79+
return &MockFetchPackSession{
80+
endpoint: ep,
81+
auth: nil,
82+
}, nil
8083
}
8184

82-
func (p *MockGitUploadPackService) SetAuth(auth common.AuthMethod) error {
83-
p.auth = auth
85+
func (c *MockClient) NewSendPackSession(ep transport.Endpoint) (
86+
transport.SendPackSession, error) {
87+
88+
return nil, fmt.Errorf("not supported")
89+
}
90+
91+
func (c *MockFetchPackSession) SetAuth(auth transport.AuthMethod) error {
92+
c.auth = auth
8493
return nil
8594
}
8695

87-
func (p *MockGitUploadPackService) Info() (*common.GitUploadPackInfo, error) {
88-
if !p.connected {
89-
return nil, errors.New("not connected")
90-
}
96+
func (c *MockFetchPackSession) AdvertisedReferences() (
97+
*transport.UploadPackInfo, error) {
9198

92-
h := fixtures.ByURL(p.endpoint.String()).One().Head
99+
h := fixtures.ByURL(c.endpoint.String()).One().Head
93100

94-
c := packp.NewCapabilities()
95-
c.Decode("6ecf0ef2c2dffb796033e5a02219af86ec6584e5 HEADmulti_ack thin-pack side-band side-band-64k ofs-delta shallow no-progress include-tag multi_ack_detailed no-done symref=HEAD:refs/heads/master agent=git/2:2.4.8~dbussink-fix-enterprise-tokens-compilation-1167-gc7006cf")
101+
cap := packp.NewCapabilities()
102+
cap.Decode("6ecf0ef2c2dffb796033e5a02219af86ec6584e5 HEADmulti_ack thin-pack side-band side-band-64k ofs-delta shallow no-progress include-tag multi_ack_detailed no-done symref=HEAD:refs/heads/master agent=git/2:2.4.8~dbussink-fix-enterprise-tokens-compilation-1167-gc7006cf")
96103

97104
ref := plumbing.ReferenceName("refs/heads/master")
98105
branch := plumbing.ReferenceName("refs/heads/branch")
99106
tag := plumbing.ReferenceName("refs/tags/v1.0.0")
100107

101-
return &common.GitUploadPackInfo{
102-
Capabilities: c,
108+
return &transport.UploadPackInfo{
109+
Capabilities: cap,
103110
Refs: map[plumbing.ReferenceName]*plumbing.Reference{
104111
plumbing.HEAD: plumbing.NewSymbolicReference(plumbing.HEAD, ref),
105112
ref: plumbing.NewHashReference(ref, h),
@@ -109,12 +116,10 @@ func (p *MockGitUploadPackService) Info() (*common.GitUploadPackInfo, error) {
109116
}, nil
110117
}
111118

112-
func (p *MockGitUploadPackService) Fetch(r *common.GitUploadPackRequest) (io.ReadCloser, error) {
113-
if !p.connected {
114-
return nil, errors.New("not connected")
115-
}
119+
func (c *MockFetchPackSession) FetchPack(
120+
r *transport.UploadPackRequest) (io.ReadCloser, error) {
116121

117-
f := fixtures.ByURL(p.endpoint.String())
122+
f := fixtures.ByURL(c.endpoint.String())
118123

119124
if len(r.Wants) == 1 {
120125
return f.Exclude("single-branch").One().Packfile(), nil
@@ -123,8 +128,7 @@ func (p *MockGitUploadPackService) Fetch(r *common.GitUploadPackRequest) (io.Rea
123128
return f.One().Packfile(), nil
124129
}
125130

126-
func (p *MockGitUploadPackService) Disconnect() error {
127-
p.connected = false
131+
func (c *MockFetchPackSession) Close() error {
128132
return nil
129133
}
130134

cshared/auth_method_cshared.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import (
66
"strings"
77

88
"golang.org/x/crypto/ssh"
9-
"gopkg.in/src-d/go-git.v4/plumbing/client/http"
10-
gssh "gopkg.in/src-d/go-git.v4/plumbing/client/ssh"
9+
"gopkg.in/src-d/go-git.v4/plumbing/transport/http"
10+
gssh "gopkg.in/src-d/go-git.v4/plumbing/transport/ssh"
1111
)
1212

1313
//export c_NewBasicAuth

cshared/remote_cshared.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ func c_Remote_Fetch(r uint64, req uint64) (uint64, int, *C.char) {
141141
if !ok {
142142
return IH, ErrorCodeNotFound, C.CString(MessageNotFound)
143143
}
144-
request := obj.(*common.GitUploadPackRequest)
144+
request := obj.(*common.UploadPackRequest)
145145
reader, err := remote.Fetch(request)
146146
if err != nil {
147147
return IH, ErrorCodeInternal, C.CString(err.Error())

examples/custom_http_client/main.go

Lines changed: 0 additions & 59 deletions
This file was deleted.

options.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55

66
"gopkg.in/src-d/go-git.v4/config"
77
"gopkg.in/src-d/go-git.v4/plumbing"
8-
"gopkg.in/src-d/go-git.v4/plumbing/client/common"
8+
"gopkg.in/src-d/go-git.v4/plumbing/transport"
99
)
1010

1111
const (
@@ -23,7 +23,7 @@ type CloneOptions struct {
2323
// The (possibly remote) repository URL to clone from
2424
URL string
2525
// Auth credentials, if required, to uses with the remote repository
26-
Auth common.AuthMethod
26+
Auth transport.AuthMethod
2727
// Name of the remote to be added, by default `origin`
2828
RemoteName string
2929
// Remote branch to clone

plumbing/client/common.go

Lines changed: 0 additions & 46 deletions
This file was deleted.

plumbing/client/common/common_test.go

Lines changed: 0 additions & 126 deletions
This file was deleted.

0 commit comments

Comments
 (0)