Skip to content
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

Merged
merged 4 commits into from
Oct 15, 2024

Conversation

ctron
Copy link
Contributor

@ctron ctron commented Oct 8, 2024

No description provided.

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
@ctron ctron force-pushed the feature/osv_ver_1 branch from 51526fc to 0bff50c Compare October 8, 2024 14:51
Also, implement generic version comparison.
@ctron ctron changed the title chore: implement other version schemes using an exact match Refactor and enhance version comparison Oct 9, 2024
@ctron ctron marked this pull request as draft October 9, 2024 18:03
@ctron ctron requested a review from bobmcwhirter October 9, 2024 18:04
Copy link
Contributor

@bobmcwhirter bobmcwhirter left a comment

Choose a reason for hiding this comment

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

Looking good.

@ctron ctron marked this pull request as ready for review October 11, 2024 09:45
return false;

end
$$
Copy link
Collaborator

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(|| {
Copy link
Collaborator

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))
Copy link
Collaborator

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 ?

Copy link
Collaborator

@JimFuller-RedHat JimFuller-RedHat left a 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

@ctron ctron added this pull request to the merge queue Oct 15, 2024
Merged via the queue into trustification:main with commit a108924 Oct 15, 2024
3 checks passed
@ctron ctron deleted the feature/osv_ver_1 branch October 15, 2024 08:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants