bug-gnu-emacs
[Top][All Lists]
Advanced

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

bug#55787: 29.0.50; inconsistent sort order with ls-lisp-version-lessp


From: Eli Zaretskii
Subject: bug#55787: 29.0.50; inconsistent sort order with ls-lisp-version-lessp
Date: Sat, 04 Jun 2022 17:52:44 +0300

> From: TAKAHASHI Yoshio <yfb02119@nifty.com>
> Cc: 55787@debbugs.gnu.org
> Date: Sat, 04 Jun 2022 23:11:17 +0900
> 
> >> $ cat /tmp/test.el
> >> (require 'ls-lisp)
> >> (print (sort (vector "01.0" "10" "010" "01.2")
> >>              (lambda (x y)
> >>                (ls-lisp-version-lessp x y))))
> >> $ emacs -Q --batch -l /tmp/test.el
> >> 
> >> ["01.0" "10" "010" "01.2"]
> >
> > Why do you think this is wrong?  This function is not meant to compare
> > dotted versions with undotted ones, only dotted to dotted or undotted
> > to undotted.  The strings are supposed to be file names, where a dot
> > begins an extension.
> > 
> > See the node "More details about version sort" in the GNU Coreutils
> > manual for more info.
> 
> I report this "inconsistency" because ls-lisp does not sort files as ls
> program does when `dired-listing-switches' has 'v', such as "-alGv".

What do you see with 'ls' and what do you see with ls-lisp?  Also, in
which locale are you trying this with 'ls'?

> # "01.0", "10", ... is minimal reproducible pattern that I stlipped down
> # my real filenames pattern.

I'd prefer to see the real file names instead, since that's what
ls-lisp-version-lessp was written to handle.

> I'm not aware that `ls-lisp-version-lessp' does not support
> dotted-undotted mixed cases.  Doc string says it acts as `strverscmp', I
> expect the same result (order) in dired buffer.  And in below example,
> the result seems to act like `strverscmp'.

The exact spec of strverscmp is not known, AFAIK, and the
implementation is a state machine, which is somewhat hard to
reverse-engineer.  I'm only aware of the documentation in the glibc
manual; did you read it?

Comparing with 'ls' is also somewhat problematic, because in UTF-8
locales its collation rules ignore some punctuation characters --
again, because that's how glibc implements that.  Emacs on MS-Windows
can emulate this behavior if you set w32-collate-ignore-punctuation to
a non-nil value.

>     (print (sort (vector "01.0" "10" "01.2") ; no "010" in arg.
>                  (lambda (x y)
>                    (ls-lisp-version-lessp x y))))
>     ["01.0" "01.2" "10"]

If I create files by the names in your original example, I see this in
a Dired buffer created by "C-u C-x d" after I set the switches to "-alv":

    drwxrwxrwx  1 xxxxx yyy 0 06-04 10:19 .
    drwxrwxrwx  1 xxxxx yyy 0 06-04 11:02 ..
    -rw-rw-rw-  1 xxxxx yyy 0 06-04 10:19 10
    -rw-rw-rw-  1 xxxxx yyy 0 06-04 10:19 010
    -rw-rw-rw-  1 xxxxx yyy 0 06-04 10:19 01.0
    -rw-rw-rw-  1 xxxxx yyy 0 06-04 10:19 01.2

which seems reasonable.

> > If you want a general-purpose version-comparison function, use
> > version< instead.
> 
> Umm, do I need to use `version<' in `ls-lisp-handle-switches' with
> extracting numerical part from filename argument?

No, I wrote that before I understood what you were trying to do.
Please ignore that part.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]