aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJorgen Schaefer2014-12-07 22:28:38 +0100
committerJorgen Schaefer2015-01-16 11:23:36 +0100
commitb689b906f27c326c4c7531d4987ffaae49b50dcd (patch)
tree0cac953ad3320aaf5a322dd500314de9292647e5
parent5d244fec3e0278110b686d66410191b89a463b93 (diff)
downloademacs-b689b906f27c326c4c7531d4987ffaae49b50dcd.tar.gz
emacs-b689b906f27c326c4c7531d4987ffaae49b50dcd.zip
Package archives now have priorities.
* lisp/package.el: Provide repository priorities. (package-archive-priorities): New variable. (package--add-to-alist): New function. (package--add-to-archive-contents): Use it. (package-menu--find-upgrades): Use it as well. Small clean up to make the use of the package name here explicit. (package-archive-priority): New function. (package-desc-priority-version): New function. Fixes: debbugs:19296
-rw-r--r--lisp/ChangeLog11
-rw-r--r--lisp/emacs-lisp/package.el96
-rw-r--r--test/automated/package-test.el17
3 files changed, 98 insertions, 26 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index fbfd68e8730..d46726f7db7 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,14 @@
12015-01-16 Jorgen Schaefer <contact@jorgenschaefer.de>
2
3 * lisp/package.el: Provide repository priorities.
4 (package-archive-priorities): New variable.
5 (package--add-to-alist): New function.
6 (package--add-to-archive-contents): Use it.
7 (package-menu--find-upgrades): Use it as well. Small clean up to
8 make the use of the package name here explicit.
9 (package-archive-priority): New function.
10 (package-desc-priority-version): New function.
11
12015-01-16 Daniel Colascione <dancol@dancol.org> 122015-01-16 Daniel Colascione <dancol@dancol.org>
2 13
3 * cus-start.el (all): Make `ring-bell-function' customizable. 14 * cus-start.el (all): Make `ring-bell-function' customizable.
diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el
index 79f8b65d43c..5336271b65b 100644
--- a/lisp/emacs-lisp/package.el
+++ b/lisp/emacs-lisp/package.el
@@ -228,6 +228,22 @@ a package can run arbitrary code."
228 :group 'package 228 :group 'package
229 :version "24.1") 229 :version "24.1")
230 230
231(defcustom package-archive-priorities nil
232 "An alist of priorities for packages.
233
234Each element has the form (ARCHIVE-ID . PRIORITY).
235
236When installing packages, the package with the highest version
237number from the archive with the highest priority is
238selected. When higher versions are available from archives with
239lower priorities, the user has to select those manually.
240
241Archives not in this list have the priority 0."
242 :type 'integer
243 :risky t
244 :group 'package
245 :version "25.1")
246
231(defcustom package-pinned-packages nil 247(defcustom package-pinned-packages nil
232 "An alist of packages that are pinned to specific archives. 248 "An alist of packages that are pinned to specific archives.
233This can be useful if you have multiple package archives enabled, 249This can be useful if you have multiple package archives enabled,
@@ -1114,23 +1130,32 @@ Also, add the originating archive to the `package-desc' structure."
1114 ;; Older archive-contents files have only 4 1130 ;; Older archive-contents files have only 4
1115 ;; elements here. 1131 ;; elements here.
1116 (package--ac-desc-extras (cdr package))))) 1132 (package--ac-desc-extras (cdr package)))))
1117 (existing-packages (assq name package-archive-contents))
1118 (pinned-to-archive (assoc name package-pinned-packages))) 1133 (pinned-to-archive (assoc name package-pinned-packages)))
1119 (cond 1134 ;; Skip entirely if pinned to another archive.
1120 ;; Skip entirely if pinned to another archive. 1135 (when (not (and pinned-to-archive
1121 ((and pinned-to-archive 1136 (not (equal (cdr pinned-to-archive) archive))))
1122 (not (equal (cdr pinned-to-archive) archive))) 1137 (setq package-archive-contents
1123 nil) 1138 (package--add-to-alist pkg-desc package-archive-contents)))))
1124 ((not existing-packages) 1139
1125 (push (list name pkg-desc) package-archive-contents)) 1140(defun package--add-to-alist (pkg-desc alist)
1126 (t 1141 "Add PKG-DESC to ALIST.
1127 (while 1142
1128 (if (and (cdr existing-packages) 1143Packages are grouped by name. The package descriptions are sorted
1129 (version-list-< 1144by version number."
1130 version (package-desc-version (cadr existing-packages)))) 1145 (let* ((name (package-desc-name pkg-desc))
1131 (setq existing-packages (cdr existing-packages)) 1146 (priority-version (package-desc-priority-version pkg-desc))
1132 (push pkg-desc (cdr existing-packages)) 1147 (existing-packages (assq name alist)))
1133 nil)))))) 1148 (if (not existing-packages)
1149 (cons (list name pkg-desc)
1150 alist)
1151 (while (if (and (cdr existing-packages)
1152 (version-list-< priority-version
1153 (package-desc-priority-version
1154 (cadr existing-packages))))
1155 (setq existing-packages (cdr existing-packages))
1156 (push pkg-desc (cdr existing-packages))
1157 nil))
1158 alist)))
1134 1159
1135(defun package-download-transaction (packages) 1160(defun package-download-transaction (packages)
1136 "Download and install all the packages in PACKAGES. 1161 "Download and install all the packages in PACKAGES.
@@ -1319,6 +1344,25 @@ The file can either be a tar file or an Emacs Lisp file."
1319 "Return the archive containing the package NAME." 1344 "Return the archive containing the package NAME."
1320 (cdr (assoc (package-desc-archive desc) package-archives))) 1345 (cdr (assoc (package-desc-archive desc) package-archives)))
1321 1346
1347(defun package-archive-priority (archive)
1348 "Return the priority of ARCHIVE.
1349
1350The archive priorities are specified in
1351`package-archive-priorities'. If not given there, the priority
1352defaults to 0."
1353 (or (cdr (assoc archive package-archive-priorities))
1354 0))
1355
1356(defun package-desc-priority-version (pkg-desc)
1357 "Return the version PKG-DESC with the archive priority prepended.
1358
1359This allows for easy comparison of package versions from
1360different archives if archive priorities are meant to be taken in
1361consideration."
1362 (cons (package-archive-priority
1363 (package-desc-archive pkg-desc))
1364 (package-desc-version pkg-desc)))
1365
1322(defun package--download-one-archive (archive file) 1366(defun package--download-one-archive (archive file)
1323 "Retrieve an archive file FILE from ARCHIVE, and cache it. 1367 "Retrieve an archive file FILE from ARCHIVE, and cache it.
1324ARCHIVE should be a cons cell of the form (NAME . LOCATION), 1368ARCHIVE should be a cons cell of the form (NAME . LOCATION),
@@ -1991,18 +2035,18 @@ If optional arg BUTTON is non-nil, describe its associated package."
1991 ;; ENTRY is (PKG-DESC [NAME VERSION STATUS DOC]) 2035 ;; ENTRY is (PKG-DESC [NAME VERSION STATUS DOC])
1992 (let ((pkg-desc (car entry)) 2036 (let ((pkg-desc (car entry))
1993 (status (aref (cadr entry) 2))) 2037 (status (aref (cadr entry) 2)))
1994 (cond ((member status '("installed" "unsigned")) 2038 (cond ((member status '("installed" "unsigned"))
1995 (push pkg-desc installed)) 2039 (push pkg-desc installed))
1996 ((member status '("available" "new")) 2040 ((member status '("available" "new"))
1997 (push (cons (package-desc-name pkg-desc) pkg-desc) 2041 (setq available (package--add-to-alist pkg-desc available))))))
1998 available)))))
1999 ;; Loop through list of installed packages, finding upgrades. 2042 ;; Loop through list of installed packages, finding upgrades.
2000 (dolist (pkg-desc installed) 2043 (dolist (pkg-desc installed)
2001 (let ((avail-pkg (assq (package-desc-name pkg-desc) available))) 2044 (let* ((name (package-desc-name pkg-desc))
2002 (and avail-pkg 2045 (avail-pkg (cadr (assq name available))))
2003 (version-list-< (package-desc-version pkg-desc) 2046 (and avail-pkg
2004 (package-desc-version (cdr avail-pkg))) 2047 (version-list-< (package-desc-priority-version pkg-desc)
2005 (push avail-pkg upgrades)))) 2048 (package-desc-priority-version avail-pkg))
2049 (push (cons name avail-pkg) upgrades))))
2006 upgrades)) 2050 upgrades))
2007 2051
2008(defun package-menu-mark-upgrades () 2052(defun package-menu-mark-upgrades ()
diff --git a/test/automated/package-test.el b/test/automated/package-test.el
index 27a71c528c6..89e0bc18509 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."
230 (package-refresh-contents) 230 (package-refresh-contents)
231 (package-install 'simple-single))) 231 (package-install 'simple-single)))
232 232
233(ert-deftest package-test-install-prioritized ()
234 "Install a lower version from a higher-prioritized archive."
235 (with-package-test ()
236 (let* ((newer-version (expand-file-name "data/package/newer-versions"
237 package-test-file-dir))
238 (package-archives `(("older" . ,package-test-data-dir)
239 ("newer" . ,newer-version)))
240 (package-archive-priorities '(("newer" . 100))))
241
242 (package-initialize)
243 (package-refresh-contents)
244 (package-install 'simple-single)
245
246 (let ((installed (cdr (assq 'simple-single package-alist))))
247 (should (version-list-= '(1 3)
248 (package-desc-version installed)))))))
249
233(ert-deftest package-test-install-multifile () 250(ert-deftest package-test-install-multifile ()
234 "Check properties of the installed multi-file package." 251 "Check properties of the installed multi-file package."
235 (with-package-test (:basedir "data/package" :install '(multi-file)) 252 (with-package-test (:basedir "data/package" :install '(multi-file))