-
Notifications
You must be signed in to change notification settings - Fork 785
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
List Rubies in natural version sort order. #628
Conversation
First normalize each Ruby (by converting dashes and plusses to periods) followed by a tab then the original Ruby version: ```shell sed -e "h" -e 's/[+-]/./g' -e "G" -e 's/\n/ /' ``` For example, `jruby-9000+graal-dev` becomes `jruby.9000.graal.dev\tjruby-9000+graal-dev`. Then dictionary sort the first column and numerically sort the next four columns: ```shell sort -t "." -k "1,1" -k "2,2n" -k "3,3n" -k "4,4n" -k "5,5n" ``` For most non-MRI Rubies, this results in the Ruby name being dictionary sorted and the MAJOR, MINOR, TINY, plus one more column being numerically sorted. Additional numeric sort columns could be added but aren't needed at present. For all existing ruby-build Ruby versions this sort order is correct. Once lexicographically sorted, cut to the original Ruby versions column with a `cut -f 2`. Closes #512. One caveat is that with ruby-build's special case dropping the CRuby `ruby-` prefix (see #543), a future MRI version 10.0+ could miss-sorted. I'm assuming 1.X will be long dead before a 10.0+ comes around but now we've had a JRuby 9000 so who knows. See chruby [#278](postmodern/chruby#278) and [#277](postmodern/chruby#277) for more discussion of related numeric sorting of Ruby versions with sed.
Previous sort order:
Pull request sort order:
|
The PR comment here is very helpful in explaining what you're doing, but I think the commit comment is misleading since you're doing more than sorting lexicographically. |
@nirvdrum I didn't mean to be misleading. Does "List Rubies in natural version sort order." seem better or if I'm missing the point could you suggest something appropriate? Also re-scanning the order I noticed this remaining issue:
and
|
My intention is equivalent sort order to GNU's Edit: With the exception of the |
What I thought was an abundance of caution with the extra sort column ended up causing the four-digit JRuby versions to be missorted. The fall-through sorting appears to sort properly for columns beyond the four that are explicitly sorted.
Updated (fixed) sort order:
|
@havenwood That does sound better. I was confused when I first saw the PR because the previous ordering was lexicographic, so I wasn't sure what changed. Otherwise, I like the changes. |
@@ -870,7 +870,9 @@ list_definitions() { | |||
{ for definition in "${RUBY_BUILD_ROOT}/share/ruby-build/"*; do | |||
echo "${definition##*/}" | |||
done | |||
} | sort | |||
} | sed -e "h" -e 's/[+-]/./g' -e "G" -e 's/\n/ /' | |
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.
The literal ctrl-v tab
in 's/\n/ /'
is for portability since OS X's sed doesn't properly support \t
tabs.
I don't like that even with this PR, pre-release versions ("dev", "preview", "rc") are sorted after stable releases. I've taken a stab at this myself in #631 |
I didn't think of pre-release order, but yeah that's nice. |
Show Rubies listed by
ruby-build --definitions
in a nice sort order by Ruby names then versions. This commit uses a combination ofsed
,sort
andcut
to achieve the desired result since GNUls
andsort
natural version number sorting options aren't portable.First normalize each Ruby (by converting dashes and plusses to periods) followed by a tab then the original Ruby version:
For example,
jruby-9000+graal-dev
becomesjruby.9000.graal.dev\tjruby-9000+graal-dev
.Then dictionary sort the first column and numerically sort the next four columns:
For most non-MRI Rubies, this results in the Ruby name being dictionary sorted and the MAJOR, MINOR, TINY, plus one more column being numerically sorted. Additional numeric sort columns could be added but aren't needed at present. For all existing ruby-build Ruby versions this sort order is correct.
Once natural version number sorted, cut to the original Ruby versions column with a
cut -f 2
.Closes #512.
One caveat is that with ruby-build's special case dropping the CRuby
ruby-
prefix (see #543), a future MRI version 10.0+ could be missorted. I'm assuming 1.X will be long dead before a 10.0+ comes around but now we've had a JRuby 9000 so who knows.See chruby #278 and #277 for more discussion of related numeric sorting of Ruby versions with sed.