Re: sort --version-sort

наб <[email protected]> Tue, 18 Feb 2025 17:00:43 +0100
Newsgroups gmane.os.netbsd.devel.userlevel
Message-ID <m6ff3tdbtq5mtr52igimawfnp4sliykj5iuk7nsyjdm24u7up4@tarta.nabijaczleweli.xyz>
On Tue, Feb 18, 2025 at 09:10:44AM -0500, enh wrote:
> fwiw, one reason i never bothered implementing strverscmp() for
> Android is that (a) basic testing showed that the gnu documentation
> didn't match their implementation and (b) no two existing
> implementations appeared to behave the same.

It's worth noting that coreutils version sort (ls, sort) is /not/
strverscmp(), but a different, more complex algorithm
(this is because strverscmp() actually sucks for sorting filenames:
   strverscmp q-1.2.1.tar < q-1.2.1a.tar < q-1.2.tar  < q-1.2a.tar  < q-1.2b.tar
   ls -v      q-1.2.tar   < q-1.2a.tar   < q-1.2b.tar < q-1.2.1.tar < q-1.2.1a.tar
 as discovered by my brief misguided stint of actually using strverscmp
   https://git.sr.ht/~nabijaczleweli/voreutils/tree/74f986a51cdfa67587efa186726617539300551a%5E/item/cmd/ls.cpp#L710).

I've implemented this comparison recently,
and believe it to be faithful to coreutils ls -v/sort -V:
  https://git.sr.ht/~nabijaczleweli/voreutils/tree/2705e7531acab0e14d3f8947f17811beee6fd97d/item/cmd/ls.cpp#L813
  https://git.sr.ht/~nabijaczleweli/voreutils/tree/2705e7531acab0e14d3f8947f17811beee6fd97d/item/cmd/ls.cpp#L713
(I think sort -V does away with the extension suff and just uses version_compare(),
 but I don't know if this is true; all I know is that this ls -v driver works).
signature.asc (application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE-----

iQIzBAABCgAdFiEEfWlHToQCjFzAxEFjvP0LAY0mWPEFAme0rqYACgkQvP0LAY0m
WPGSdw//XiJPaapxUiDqKeaumxQu08qt65DT7+8fHZxaxCekA6fhnx/gbrPEispM
4CfCOaN6l664fTd2se1ycdCqoxysCE0PYulqQuSR925ndbzkZ8Op8ZwdNSk4npFs
2KsfQ9juHGD92KxgmSvT7ZA16T+mWiJqKvge0tot7L4rvF/WjBvrm7i6jqnvpIJ4
PZBpqqNAbpGa2RaHcW5MNC88U4Z/YspcDWODINcNAuxBW1t6tkjhWIPlEaBdTnB7
bHS2HJmwP4upwENNJknqQoBSJrS4P7l5r5Puao4Yk2t8/+BHEcadZ7suUA0lBOVM
3XO7/DDkdVdrmFiPhjUMjRRW7RzggxssXW30W8xzbAeuSxv6dByxSvNxws2xykgG
Pu9ZdY03PREMFOS7/JPYK75WuN0e6fELTU0+L0FM+wozeVVaO9MP9rsldeIP9PiS
bSP3ztZSIpaWFWiImrrc4uVvziiOOa7mt0cFGPPxRRr5tx6PvUGQSARpKePDdzDS
Kw24M3LvCMZ5LJEaWQx5PfRMKT0daxqp/plb96t5irQqRwrKNcYC7qs4/GOtdq2E
q9YUDnNj1bqIrSAVeEeqmysk/kjLZX9kntW9UYpC9VG8fbZIVVbIYpvyFCW2xAI6
jNkqlyQg8oRCqYNHy90B46dCO07ive6Y18y0kVCfdrh3kDFpC6g=
=aU5p
-----END PGP SIGNATURE-----