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

List Rubies in natural version sort order. #628

Closed
wants to merge 2 commits into from
Closed

List Rubies in natural version sort order. #628

wants to merge 2 commits into from

Commits on Sep 7, 2014

  1. Sort Ruby versions lexicographically.

    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.
    havenwood committed Sep 7, 2014
    Configuration menu
    Copy the full SHA
    3250117 View commit details
    Browse the repository at this point in the history
  2. Limit explicit sorting to four columns.

    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.
    havenwood committed Sep 7, 2014
    Configuration menu
    Copy the full SHA
    b4691e3 View commit details
    Browse the repository at this point in the history