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

Sort kegs based on version scheme #16973

Merged
merged 1 commit into from
Mar 29, 2024
Merged

Sort kegs based on version scheme #16973

merged 1 commit into from
Mar 29, 2024

Conversation

Bo98
Copy link
Member

@Bo98 Bo98 commented Mar 29, 2024

version_scheme is exclusively used in situations where new version < old version, so all keg sorting techniques need to be aware of it.

Because this requires reading the tab, this has a minor performance penalty. Hopefully it is not noticeable.

This is a best effort attempt to fix all existing call sites - I could have missed some.

Copy link
Contributor

@scpeters scpeters left a comment

Choose a reason for hiding this comment

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

the code looks good, and it fixed brew upgrade, brew info, and brew link for me

@PizzaShift

This comment was marked as spam.

@PizzaShift

This comment has been minimized.

@Bo98 Bo98 merged commit 02a0ea8 into master Mar 29, 2024
25 checks passed
@Bo98 Bo98 deleted the keg-sort branch March 29, 2024 23:55
@apainintheneck
Copy link
Contributor

Nit: It might make more sense to have Keg.sort_by_version and Keg.max_by_version. As it is Keg.sort is not very descriptive or well documented. The second hardest problem in computer science.

@MikeMcQuaid
Copy link
Member

Good catch, thanks for this @Bo98!

Comment on lines -2845 to +2844
head - [Keg.new(head_prefix)] + stable.sort_by(&:version).slice(0...-1)
head - [Keg.new(head_prefix)] + Keg.sort(stable).drop(1)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this logic is different from before since we're now doing a reverse sort by version. Before we were dropping the newest version and now we're dropping the oldest one.

Copy link
Member Author

Choose a reason for hiding this comment

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

slice(0...-1) drops the last entry but drop(1) drops the first entry

Comment on lines +151 to +154
sig { params(kegs: T::Array[Keg]).returns(T::Array[Keg]) }
def self.sort(kegs)
kegs.sort_by { |keg| [keg.version_scheme, keg.version] }.reverse!
end
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 not equivalent to the previous usages of keg_array.sort_by(&:version) since it now does a reverse sort. Are you sure that order doesn't matter in any of the places where it was replaced?

Copy link
Member Author

@Bo98 Bo98 Apr 1, 2024

Choose a reason for hiding this comment

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

JSON API maybe matters, but that's about it. Most of the rest don't use the full list and those were all updated, and the others were largely in non-parsable output (e.g. plain brew info/brew outdated).

@apainintheneck
Copy link
Contributor

I opened a follow-up PR here: #16986

@github-actions github-actions bot added the outdated PR was locked due to age label May 1, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated PR was locked due to age
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants