-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor and enhance version comparison #907
Conversation
According to OSV: > ECOSYSTEM: The versions introduced and fixed are arbitrary, > uninterpreted strings specific to the package ecosystem, which does > not conform to SemVer 2.0’s version ordering. > > It is recommended that you provide an explicitly enumerated versions > list when specifying one or more ECOSYSTEM ranges, […] The same is true for the git type. We might consider adding an "exact" scheme in the database. Closes: trustification#900
51526fc
to
0bff50c
Compare
Also, implement generic version comparison.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good.
return false; | ||
|
||
end | ||
$$ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you could rewrite to be a bit more compact:
create or replace function generic_version_matches(version_p text, range_p version_range)
returns bool
as
$$
begin
return (
(range_p.low_version is not null and range_p.low_inclusive and version_p = range_p.low_version)
or (range_p.high_version is not null and range_p.high_inclusive and version_p = range_p.high_version)
);
end
$$ language plpgsql immutable;
untested, I doubt this would result in such a speed up that it is worth reducing readability
} | ||
|
||
pub fn get_well_known_prefixes() -> &'static PrefixMatcher { | ||
WELL_KNOWN_PREFIXES.get_or_init(|| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder (one for the future) if WELL_KNOWN_PREFIXES needs an env var
pub fn detect(&self, input: &str) -> Option<String> { | ||
self.prefixes | ||
.iter() | ||
.find(|each| input.starts_with(&each.prefix)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
have you considered using a find_map here ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
apart from some minor observations, LGTM
No description provided.