Subject: Re: bug#68317: Can't sort *Packages* buffer by version after installing with package-vc

From: Philip Kaludercic <[email-masked]>
Date: Tue, 09 Jan 2024 20:19:15 +0000

Eli Zaretskii <[email-masked]> writes:

>> From: Philip Kaludercic <[email-masked]>
>> Cc: Joseph Turner <[email-masked]>,  [email-masked]
>> Date: Tue, 09 Jan 2024 19:25:44 +0000
>> 
>> Eli Zaretskii <[email-masked]> writes:
>> 
>> >> version-to-list: Invalid version syntax: ‘c99367ebc2f0afe0baaf2f5e5ca1ad9d62ba6e21’ (must start with a number)
>> >
>> > Sounds like package-vc-commit should be modified to produce a valid
>> > version string (which SHA1 is not)?  Philip?
>> 
>> We can also adjust `package-menu--version-predicate' to handle
>> non-version numbers, which I think would be more robust.
>
> Fine by me, but can this be done safely enough for emacs-29?

This would be a simple implementation, I don't know if it is safe enough
for you:

diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el
index fa9903e13e3..f97c2cff783 100644
--- a/lisp/emacs-lisp/package.el
+++ b/lisp/emacs-lisp/package.el
@@ -4070,8 +4070,8 @@ package-menu-execute
 (defun package-menu--version-predicate (A B)
   "Predicate to sort \"*Packages*\" buffer by the version column.
 This is used for `tabulated-list-format' in `package-menu-mode'."
-  (let ((vA (or (version-to-list (aref (cadr A) 1)) '(0)))
-        (vB (or (version-to-list (aref (cadr B) 1)) '(0))))
+  (let ((vA (or (ignore-error error (version-to-list (aref (cadr A) 1))) '(0)))
+        (vB (or (ignore-error error (version-to-list (aref (cadr B) 1))) '(0))))
     (if (version-list-= vA vB)
         (package-menu--name-predicate A B)
       (version-list-< vA vB))))