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

Commit 634b6f0

Browse files
authored
protocol/packp: capabilities new Capability entity and List struct, test improvements (#144)
* protocol/pakp: capabilities new Capability entity and List struct, test improvements * etc: example cloud-config file * removing sorting from List.String
1 parent 44c6a49 commit 634b6f0

22 files changed

+819
-474
lines changed

common_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"gopkg.in/src-d/go-git.v4/plumbing"
1111
"gopkg.in/src-d/go-git.v4/plumbing/format/packfile"
1212
"gopkg.in/src-d/go-git.v4/plumbing/protocol/packp"
13+
"gopkg.in/src-d/go-git.v4/plumbing/protocol/packp/capability"
1314
"gopkg.in/src-d/go-git.v4/plumbing/transport"
1415
"gopkg.in/src-d/go-git.v4/plumbing/transport/client"
1516
"gopkg.in/src-d/go-git.v4/storage/filesystem"
@@ -97,8 +98,8 @@ func (c *MockFetchPackSession) AdvertisedReferences() (*packp.AdvRefs, error) {
9798

9899
h := fixtures.ByURL(c.endpoint.String()).One().Head
99100

100-
cap := packp.NewCapabilities()
101-
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")
101+
cap := capability.NewList()
102+
cap.Set(capability.Agent, "go-git/tests")
102103

103104
ref := plumbing.ReferenceName("refs/heads/master")
104105
branch := plumbing.ReferenceName("refs/heads/branch")

plumbing/protocol/packp/advrefs.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,11 @@ import (
55
"strings"
66

77
"gopkg.in/src-d/go-git.v4/plumbing"
8+
"gopkg.in/src-d/go-git.v4/plumbing/protocol/packp/capability"
89
"gopkg.in/src-d/go-git.v4/plumbing/storer"
910
"gopkg.in/src-d/go-git.v4/storage/memory"
1011
)
1112

12-
const (
13-
symref = "symref"
14-
)
15-
1613
// AdvRefs values represent the information transmitted on an
1714
// advertised-refs message. Values from this type are not zero-value
1815
// safe, use the New function instead.
@@ -31,7 +28,7 @@ const (
3128
type AdvRefs struct {
3229
Prefix [][]byte // payloads of the prefix
3330
Head *plumbing.Hash
34-
Capabilities *Capabilities
31+
Capabilities *capability.List
3532
References map[string]plumbing.Hash
3633
Peeled map[string]plumbing.Hash
3734
Shallows []plumbing.Hash
@@ -41,7 +38,7 @@ type AdvRefs struct {
4138
func NewAdvRefs() *AdvRefs {
4239
return &AdvRefs{
4340
Prefix: [][]byte{},
44-
Capabilities: NewCapabilities(),
41+
Capabilities: capability.NewList(),
4542
References: make(map[string]plumbing.Hash),
4643
Peeled: make(map[string]plumbing.Hash),
4744
Shallows: []plumbing.Hash{},
@@ -52,7 +49,7 @@ func (a *AdvRefs) AddReference(r *plumbing.Reference) error {
5249
switch r.Type() {
5350
case plumbing.SymbolicReference:
5451
v := fmt.Sprintf("%s:%s", r.Name().String(), r.Target().String())
55-
a.Capabilities.Add(symref, v)
52+
a.Capabilities.Add(capability.SymRef, v)
5653
case plumbing.HashReference:
5754
a.References[r.Name().String()] = r.Hash()
5855
default:
@@ -87,7 +84,7 @@ func addSymbolicRefs(s storer.ReferenceStorer, ar *AdvRefs) error {
8784
return nil
8885
}
8986

90-
for _, symref := range ar.Capabilities.Get(symref).Values {
87+
for _, symref := range ar.Capabilities.Get(capability.SymRef) {
9188
chunks := strings.Split(symref, ":")
9289
if len(chunks) != 2 {
9390
err := fmt.Errorf("bad number of `:` in symref value (%q)", symref)
@@ -105,5 +102,5 @@ func addSymbolicRefs(s storer.ReferenceStorer, ar *AdvRefs) error {
105102
}
106103

107104
func hasSymrefs(ar *AdvRefs) bool {
108-
return ar.Capabilities.Supports(symref)
105+
return ar.Capabilities.Supports(capability.SymRef)
109106
}

plumbing/protocol/packp/advrefs_decode.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,8 @@ func decodeCaps(p *advRefsDecoder) decoderStateFn {
201201
return decodeOtherRefs
202202
}
203203

204-
for _, c := range bytes.Split(p.line, sp) {
205-
name, values := readCapability(c)
206-
p.data.Capabilities.Add(name, values...)
204+
if err := p.data.Capabilities.Decode(p.line); err != nil {
205+
p.error("invalid capabilities: %s", err)
207206
}
208207

209208
return decodeOtherRefs

0 commit comments

Comments
 (0)