Skip to content

Add a new Match method to the reference package#2039

Merged
stevvooe merged 1 commit intodistribution:masterfrom
vdemeester:add-match-support-to-reference
Nov 10, 2016
Merged

Add a new Match method to the reference package#2039
stevvooe merged 1 commit intodistribution:masterfrom
vdemeester:add-match-support-to-reference

Conversation

@vdemeester
Copy link
Contributor

The Match method allows to see if a reference matches a specified patterns.

This is linked to moby/moby#27872 (comment) 👼

/cc @stevvooe @aaronlehmann

🐸

Signed-off-by: Vincent Demeester [email protected]

@codecov-io
Copy link

codecov-io commented Nov 4, 2016

Current coverage is 51.38% (diff: 100%)

Merging #2039 into master will decrease coverage by 10.15%

@@             master      #2039   diff @@
==========================================
  Files           126        126           
  Lines         11275      11268      -7   
  Methods           0          0           
  Messages          0          0           
  Branches          0          0           
==========================================
- Hits           6939       5790   -1149   
- Misses         3449       4732   +1283   
+ Partials        887        746    -141   

Powered by Codecov. Last update 02f4195...353e3a4

reference: "foo/c/baz:tag",
pattern: "foo/c/baz:tag",
expected: true,
},

Choose a reason for hiding this comment

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

Let's add a few test cases for references that include domain names.

return false
}
if namedRef, isNamed := ref.(Named); isNamed && !matched {
matched, _ = path.Match(pattern, namedRef.Name())

Choose a reason for hiding this comment

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

I'm confused about why Match is called twice. Seems like this is returning matches(ref.String()) || matches(ref.Name()). Why isn't ref.String() enough?

Also, the eror is not checked here.

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 returning matches(ref.String()) || matches(ref.Name()) if the reference is Named, others ref will only check ref.String(). The basic idea is to map a little bit what docker images did (and a little more). That means foo/*/ba[rz] would match foo/a/bar:tag for example. To achieve that, I need to check if the name part matches if the whole string does not (this way foo/*/ba[rz]:t* will match foo/a/bar:tag too).

The error is not checked here because it cannot happen the only error is if the pattern is wrong, and this error is already checked just before 👼.

Choose a reason for hiding this comment

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

It just seems confusing to me that a function called Match would have this behavior. Could we call it something like MatchRefOrName? Feel free to suggest something better.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@aaronlehmann ah I see what you mean, makes sence. I'll rename 👼

}, nil
}

// Match reports whether ref matches the specified pattern.
Copy link
Collaborator

Choose a reason for hiding this comment

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

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 👍


// Match reports whether ref matches the specified pattern.
// See https://godoc.org/path#Match for supported patterns.
func Match(pattern string, ref Reference) bool {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's follow the same pattern as the stblib: this should return an error if the pattern is bad.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds fair 👍

@dmcgowan
Copy link
Collaborator

dmcgowan commented Nov 9, 2016

LGTM


// MatchRefOrName reports whether ref matches the specified pattern.
// See https://godoc.org/path#Match for supported patterns.
func MatchRefOrName(pattern string, ref Reference) (bool, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's just call it match, please.

The Match method allows to see if a reference matches a specified
patterns.

Signed-off-by: Vincent Demeester <[email protected]>
@vdemeester
Copy link
Contributor Author

@stevvooe updated 👼

@stevvooe
Copy link
Collaborator

LGTM

@stevvooe stevvooe merged commit 26c9a77 into distribution:master Nov 10, 2016
@vdemeester vdemeester deleted the add-match-support-to-reference branch November 10, 2016 09:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants