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

protocol/packp: capabilities new Capability entity and List struct, test improvements #144

Merged
merged 4 commits into from
Nov 29, 2016
Merged

Conversation

mcuadros
Copy link
Contributor

  • Capabilities struct moved to a package inside packp, and renamed to List
  • New type Capability and all the consts with the valid capabilities
  • Validation of unknown capabilities, capabilities with invalid values and other cases
  • Removed duplicate Decode function at packp

@@ -98,7 +98,7 @@ func (c *MockFetchPackSession) AdvertisedReferences() (

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

cap := packp.NewCapabilities()
cap := capability.NewList()
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")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Decode method changes his input param type from string to byte[].


// Get returns the values for a capability
func (l *List) Get(capability Capability) []string {
return l.m[capability].Values
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This panics when capability is not found in the map.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True

return nil
}

func (l *List) validate(c Capability, values []string) error {
Copy link
Contributor

@alcortesm alcortesm Nov 29, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this method is missing the point: why is this a method of the List type?

IMHO it should be a method of the entry type or an external function. And it must be public.

There must be a public List.Validate method thought, but it should not do what this method is doing, instead it should check things like having incompatible capabilities in the list, like sideband and sideband64, for example.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a basic validation preventing values where should not be. The other validation is requested dependant and should be on the request, not here.

// List represents a list of capabilities
type List struct {
m map[Capability]*entry
o []string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does o means?

What is it purpose? I cannot see how is this useful. If it is here only for easier sorting in the String method, it should be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes is a performance improvement, if not we need to go through all the keys. Yep maybe is useless

return nil
}

if !multipleArgument[c] && len(l.m[c].Values) > 0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is already checked at line 88.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is not the same, this check, if has previous values stored, the other function validate the values you are trying to add

o []string
}

type entry struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This must be public, as it is what the clients would like to use to add new capabilities, instead of a Capability plus some values.

I would rename entry to Capability and rename Capability to Type.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not agree, is what I removed. The values are vary rarely use only two. So this proposal is worse for the majority of the cases

}

for _, value := range cap.Values {
o += fmt.Sprintf("%s=%s ", key, value)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strings should be quoted here to prevent name collisions. Also on the key.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quoted? Why?

}
}

return strings.Trim(o, " ")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use a proper prefix separator, initialized to the empty string on the first iterarion, instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will use a slice and implode it

@@ -0,0 +1,158 @@
package capability
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The List type will need some more methods in the future:

  • Complementary set: to check the validity of client requests: requested caps not present in the announcement
  • Announced-requested validity: to check client/server compatibility. Example: PushCert without AllowReachableSHA1InWant

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not in the scope of this object this should be checked in the request since are request dependant

@codecov-io
Copy link

Current coverage is 75.56% (diff: 90.66%)

Merging #144 into master will increase coverage by 0.18%

@@             master       #144   diff @@
==========================================
  Files            78         78          
  Lines          5091       5088     -3   
  Methods           0          0          
  Messages          0          0          
  Branches          0          0          
==========================================
+ Hits           3838       3845     +7   
+ Misses          804        794    -10   
  Partials        449        449          

Powered by Codecov. Last update 7cee84e...af95613

@mcuadros mcuadros merged commit 634b6f0 into src-d:master Nov 29, 2016
@mcuadros mcuadros deleted the capabilities branch December 13, 2016 10:13
mcuadros added a commit that referenced this pull request Jan 31, 2017
…est improvements (#144)

* protocol/pakp: capabilities new Capability entity and List struct, test improvements

* etc: example cloud-config file

* removing sorting from List.String
gsalingu-ovhus pushed a commit to gsalingu-ovhus/go-git that referenced this pull request Mar 28, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants