Subject: bug#72141: 29.4; package-upgrade vs package-load-list

From: Thierry Volpiatto <[email-masked]>
Date: Sun, 04 Aug 2024 17:15:04 +0000

Hello Philip,

Philip Kaludercic <[email-masked]> writes:

> Gladly, then I'd like to try it out it and perhaps write a ERT test.

Patch attached, please review and test it before merging ;-)

Thanks.

-- 
Thierry
From 292e251a383c1fb53cc377cd32f71705e6742f85 Mon Sep 17 00:00:00 2001
From: Thierry Volpiatto <[email-masked]>
Date: Sat, 3 Aug 2024 06:07:28 +0200
Subject: [PATCH] Fix bug#72141, package-upgrade should not include disabled
 packages

* lisp/emacs-lisp/package.el (package--upgradeable-packages):
Rewrite with a new optional arg to filter out disabled packages from
output.
(package-upgrade, package-upgrade-all): Use it and filter out built-in
packages from completion according package-install-upgrade-built-in
value.
---
 lisp/emacs-lisp/package.el | 60 ++++++++++++++++++++++----------------
 1 file changed, 35 insertions(+), 25 deletions(-)

diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el
index 7cae8d68bc0..83996c9d6de 100644
--- a/lisp/emacs-lisp/package.el
+++ b/lisp/emacs-lisp/package.el
@@ -2259,11 +2259,15 @@ had been enabled."
   "Upgrade package NAME if a newer version exists."
   (interactive
    (list (completing-read
-          "Upgrade package: " (package--upgradeable-packages t) nil t)))
+          "Upgrade package: " (package--upgradeable-packages
+                               package-install-upgrade-built-in
+                               'ignore-disabled)
+          nil t)))
   (let* ((package (if (symbolp name)
                       name
                     (intern name)))
          (pkg-desc (cadr (assq package package-alist)))
+         ;; Keep this binding for non-interactive use.
          (package-install-upgrade-built-in (not pkg-desc)))
     ;; `pkg-desc' will be nil when the package is an "active built-in".
     (if (and pkg-desc (package-vc-p pkg-desc))
@@ -2275,32 +2279,37 @@ had been enabled."
                        ;; before.  Mark it as installed explicitly.
                        (and pkg-desc 'dont-select)))))
 
-(defun package--upgradeable-packages (&optional include-builtins)
+(defun package--upgradeable-packages (&optional
+                                        include-builtins ignore-disabled)
   ;; Initialize the package system to get the list of package
   ;; symbols for completion.
   (package--archives-initialize)
-  (mapcar
-   #'car
-   (seq-filter
-    (lambda (elt)
-      (or (let ((available
-                 (assq (car elt) package-archive-contents)))
-            (and available
-                 (or (and
-                      include-builtins
-                      (not (package-desc-version (cadr elt))))
-                     (version-list-<
-                      (package-desc-version (cadr elt))
-                      (package-desc-version (cadr available))))))
-          (package-vc-p (cadr elt))))
-    (if include-builtins
-        (append package-alist
-                (mapcan
-                 (lambda (elt)
-                   (when (not (assq (car elt) package-alist))
-                     (list (list (car elt) (package--from-builtin elt)))))
-                 package--builtins))
-      package-alist))))
+  (let ((pkgs (if include-builtins
+                  (append package-alist
+                          (append package-alist
+                                  (mapcan
+                                   (lambda (elt)
+                                     (when (not (assq (car elt) package-alist))
+                                       (list
+                                        (list
+                                         (car elt)
+                                         (package--from-builtin elt)))))
+                                   package--builtins)))
+                package-alist)))
+    (cl-loop for (sym desc) in pkgs
+             for available =
+             (if-let ((av (assq sym package-archive-contents)))
+                 (if ignore-disabled
+                     (and (not (package-disabled-p sym cversion)) av) av))
+             for cversion = (and available (package-desc-version desc))
+             when (or (and available
+                           (or (and include-builtins (not cversion))
+                               (and cversion
+                                    (version-list-<
+                                     cversion
+                                     (package-desc-version (cadr available))))))
+                      (package-vc-p desc))
+             collect sym)))
 
 ;;;###autoload
 (defun package-upgrade-all (&optional query)
@@ -2315,7 +2324,8 @@ from ELPA by either using `\\[package-upgrade]' or
 `\\<package-menu-mode-map>\\[package-menu-mark-install]' after `\\[list-packages]'."
   (interactive (list (not noninteractive)))
   (package-refresh-contents)
-  (let ((upgradeable (package--upgradeable-packages)))
+  (let ((upgradeable (package--upgradeable-packages
+                      package-install-upgrade-built-in 'ignore-disabled)))
     (if (not upgradeable)
         (message "No packages to upgrade")
       (when (and query
-- 
2.34.1