Subject: bug#62720: 29.0.60; Not easy at all to upgrade :core packages like Eglot

From: Philip Kaludercic <[email-masked]>
Date: Sun, 23 Apr 2023 13:02:06 +0000

Dmitry Gutov <[email-masked]> writes:

> Philip,
>
> On 13/04/2023 21:49, Philip Kaludercic wrote:
>> +    (when (and (or current-prefix-arg package-install-upgrade-built-in)
>> +               (package--active-built-in-p pkg))
>> +      (setq pkg (cadr (assq name package-archive-contents))))
>
> How sure are you that the first element in (cdr (assq name
> package-archive-contents)) will contain the latest version?

This is not certain, but the same approach is used in other places in
package.el, so I just stocked to it.

> When reading the code I stumbled on these two items:
>
> - Comment in package-compute-transaction:
>
>                 ;; pkg-descs is sorted by priority, not version, so
>                 ;; don't error just yet.
>
> - package-menu--find-upgrades iterates through installed packages and
>   checks for new versions with this condition:
>
>              (version-list-< (package-desc-priority-version pkg-desc)
>                              (package-desc-priority-version avail-pkg))
>
> That's why I came with the more complex way to choose the appropriate
> package-desc in my latest attempt:
>
>  (car
>   (last (seq-sort-by #'package-desc-priority-version
>                      #'version-list-<
>                      (cdr (assq package package-archive-contents)))))

If we insist on package.el installing the newest version, then this
would make sense.  AFAIK there is no guarantees on the order of packages
in `package-archive-contents'.  This shouldn't be an issue for Eglot,
but might be one for use-package.  I would actually pull it out into a
separate utility function that we would re-use in other places.

> Would be happy to hear it's an overkill and we can use the more simple
> version.