unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#19296: [PATCH] Package archives now have priorities.
@ 2014-12-07 12:31 Jorgen Schaefer
  2014-12-07 16:07 ` Ted Zlatanov
                   ` (2 more replies)
  0 siblings, 3 replies; 28+ messages in thread
From: Jorgen Schaefer @ 2014-12-07 12:31 UTC (permalink / raw)
  To: 19296

When installing packages by name, only packages from archives with
the highest priority are considered, before versions are compared.

This solves the "MELPA problem", where MELPA assigns date-based
version numbers to packages which override all other archives.
Giving MELPA a lower priority means packages are installed from
MELPA only when the package is not available from other archives.

This can be overridden manually by the user.
---
 lisp/emacs-lisp/package.el     |   45 ++++++++++++++++++++++++++++++++++++++--
 test/automated/package-test.el |   17 +++++++++++++++
 2 files changed, 60 insertions(+), 2 deletions(-)

diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el
index 4e5c397..2030482 100644
--- a/lisp/emacs-lisp/package.el
+++ b/lisp/emacs-lisp/package.el
@@ -228,6 +228,33 @@ a package can run arbitrary code."
   :group 'package
   :version "24.1")
 
+(defcustom package-archive-default-priority 500
+  "The default priority for archives.
+
+This is used if the archive is not found in
+`package-archive-priorities'."
+  :type 'integer
+  :risky t
+  :group 'package
+  :version "25.1")
+
+(defcustom package-archive-priorities nil
+  "An alist of priorities for packages.
+
+Each element has the form (ARCHIVE-ID . PRIORITY).
+
+When installing packages, the package with the highest version
+number from the archive with the highest priority is
+selected. When higher versions are available from archives with
+lower priorities, the user has to select those manually.
+
+Archives not in this list have the priority given in
+`package-archive-default-priority'."
+  :type 'integer
+  :risky t
+  :group 'package
+  :version "25.1")
+
 (defcustom package-pinned-packages nil
   "An alist of packages that are pinned to specific archives.
 This can be useful if you have multiple package archives enabled,
@@ -1063,6 +1090,7 @@ Also, add the originating archive to the `package-desc' structure."
                         ;; Older archive-contents files have only 4
                         ;; elements here.
                         (package--ac-desc-extras (cdr package)))))
+         (archive-priority (package-archive-priority archive))
          (existing-packages (assq name package-archive-contents))
          (pinned-to-archive (assoc name package-pinned-packages)))
     (cond
@@ -1075,8 +1103,12 @@ Also, add the originating archive to the `package-desc' structure."
      (t
       (while
           (if (and (cdr existing-packages)
-                   (version-list-<
-                    version (package-desc-version (cadr existing-packages))))
+                   (or (< archive-priority
+                          (package-archive-priority
+                           (package-desc-archive (cadr existing-packages))))
+                       (version-list-<
+                        version
+                        (package-desc-version (cadr existing-packages)))))
               (setq existing-packages (cdr existing-packages))
             (push pkg-desc (cdr existing-packages))
             nil))))))
@@ -1268,6 +1300,15 @@ The file can either be a tar file or an Emacs Lisp file."
   "Return the archive containing the package NAME."
   (cdr (assoc (package-desc-archive desc) package-archives)))
 
+(defun package-archive-priority (archive)
+  "Return the priority of ARCHIVE.
+
+The archive priorities are specified in
+`package-archive-priorities' and
+`package-archive-default-priority'."
+  (or (cdr (assoc archive package-archive-priorities))
+      package-archive-default-priority))
+
 (defun package--download-one-archive (archive file)
   "Retrieve an archive file FILE from ARCHIVE, and cache it.
 ARCHIVE should be a cons cell of the form (NAME . LOCATION),
diff --git a/test/automated/package-test.el b/test/automated/package-test.el
index 6e7994a..2a337fb 100644
--- a/test/automated/package-test.el
+++ b/test/automated/package-test.el
@@ -230,6 +230,23 @@ Must called from within a `tar-mode' buffer."
     (package-refresh-contents)
     (package-install 'simple-single)))
 
+(ert-deftest package-test-install-prioritized ()
+  "Install a lower version from a higher-prioritized archive."
+  (with-package-test ()
+    (let* ((newer-version (expand-file-name "data/package/newer-versions"
+                                            package-test-file-dir))
+           (package-archives `(("older" . ,package-test-data-dir)
+                               ("newer" . ,newer-version)))
+           (package-archive-priorities '(("newer" . 100))))
+
+      (package-initialize)
+      (package-refresh-contents)
+      (package-install 'simple-single)
+
+      (let ((installed (cdr (assq 'simple-single package-alist))))
+        (should (version-list-= '(1 3)
+                                (package-desc-version installed)))))))
+
 (ert-deftest package-test-install-multifile ()
   "Check properties of the installed multi-file package."
   (with-package-test (:basedir "data/package" :install '(multi-file))
-- 
1.7.10.4






^ permalink raw reply related	[flat|nested] 28+ messages in thread

end of thread, other threads:[~2014-12-15 19:07 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <<20141207132244.A14A7200D1E@loki.jorgenschaefer.de>
2014-12-07 14:19 ` bug#19296: [PATCH] Package archives now have priorities Drew Adams
2014-12-07 14:43   ` Jorgen Schaefer
2014-12-07 15:55     ` Drew Adams
2014-12-07 16:10       ` Jorgen Schaefer
2014-12-07 18:16         ` Drew Adams
2014-12-07 16:13       ` Ted Zlatanov
2014-12-07 17:41   ` Stefan Monnier
     [not found] ` <<20141207214345.A8216200D2E@loki.jorgenschaefer.de>
2014-12-07 22:27   ` Drew Adams
2014-12-07 12:31 Jorgen Schaefer
2014-12-07 16:07 ` Ted Zlatanov
2014-12-07 17:56 ` Stefan Monnier
2014-12-07 18:21   ` Jorgen Schaefer
2014-12-07 20:00     ` Jorgen Schaefer
2014-12-08  2:48       ` Stefan Monnier
2014-12-08 10:58         ` Jorgen Schaefer
2014-12-08 15:42           ` Stefan Monnier
2014-12-08 18:49             ` Jorgen Schaefer
2014-12-15  4:59               ` Stefan Monnier
2014-12-15  8:36                 ` Jorgen Schaefer
2014-12-15 12:08                   ` Ted Zlatanov
2014-12-15 14:52                   ` Stefan Monnier
2014-12-15 14:55                     ` Jorgen Schaefer
2014-12-15 19:07                       ` Stefan Monnier
2014-12-07 18:55   ` Achim Gratz
2014-12-08  2:45     ` Stefan Monnier
2014-12-08  7:22       ` Achim Gratz
2014-12-07 21:28 ` Jorgen Schaefer
2014-12-07 21:46   ` Jorgen Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).