tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: sort --version-sort



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).

Attachment: signature.asc
Description: PGP signature



Home | Main Index | Thread Index | Old Index