aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/protocol/packp/capability
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2016-12-01 09:59:19 +0100
committerGitHub <noreply@github.com>2016-12-01 09:59:19 +0100
commitc15bf1dff332873644290db0e186b8f5ad9b8fb2 (patch)
tree1dd79212333823b70f2792ad116864ea127e4a1c /plumbing/protocol/packp/capability
parent7de79aef5d4aa3100382d4df3e99525f9949e8d1 (diff)
downloadgo-git-c15bf1dff332873644290db0e186b8f5ad9b8fb2.tar.gz
capabilities: full integration (#151)
* format/pktline: fix readPayloadLen err handling * protocol/pakp: UploadReq validation and creation of capabilities * protocol/pakp: AdvRef tests * protocol/pakp: capability.List.Delete * protocol: filter unsupported capabilities * remote capability negociation * transport: UploadRequest validation * requested changes
Diffstat (limited to 'plumbing/protocol/packp/capability')
-rw-r--r--plumbing/protocol/packp/capability/list.go17
-rw-r--r--plumbing/protocol/packp/capability/list_test.go16
2 files changed, 33 insertions, 0 deletions
diff --git a/plumbing/protocol/packp/capability/list.go b/plumbing/protocol/packp/capability/list.go
index ff8d4a4..7197d36 100644
--- a/plumbing/protocol/packp/capability/list.go
+++ b/plumbing/protocol/packp/capability/list.go
@@ -145,6 +145,23 @@ func (l *List) Supports(capability Capability) bool {
return ok
}
+// Delete deletes a capability from the List
+func (l *List) Delete(capability Capability) {
+ if !l.Supports(capability) {
+ return
+ }
+
+ delete(l.m, capability)
+ for i, c := range l.sort {
+ if c != string(capability) {
+ continue
+ }
+
+ l.sort = append(l.sort[:i], l.sort[i+1:]...)
+ return
+ }
+}
+
// String generates the capabilities strings, the capabilities are sorted in
// insertion order
func (l *List) String() string {
diff --git a/plumbing/protocol/packp/capability/list_test.go b/plumbing/protocol/packp/capability/list_test.go
index eeb3173..d6aac16 100644
--- a/plumbing/protocol/packp/capability/list_test.go
+++ b/plumbing/protocol/packp/capability/list_test.go
@@ -97,6 +97,22 @@ func (s *SuiteCapabilities) TestGetEmpty(c *check.C) {
c.Assert(cap.Get(Agent), check.HasLen, 0)
}
+func (s *SuiteCapabilities) TestDelete(c *check.C) {
+ cap := NewList()
+ cap.Delete(SymRef)
+
+ err := cap.Add(Sideband)
+ c.Assert(err, check.IsNil)
+ err = cap.Set(SymRef, "bar")
+ c.Assert(err, check.IsNil)
+ err = cap.Set(Sideband64k)
+ c.Assert(err, check.IsNil)
+
+ cap.Delete(SymRef)
+
+ c.Assert(cap.String(), check.Equals, "side-band side-band-64k")
+}
+
func (s *SuiteCapabilities) TestAdd(c *check.C) {
cap := NewList()
err := cap.Add(SymRef, "foo", "qux")