Commit 1f6c9174 authored by Ryan Thompson's avatar Ryan Thompson

Merge pull request #533 from DarwinAwardWinner/register-method-keywords

Backend changes to el-get install methods and checksums

 * Fixed an omission the docstring of el-get-methods
 * Add functions `el-get-register-derived-method` and `el-get-register-method-alias` and use them as appropriate
 * Add checksum methods to hg and git
 * Add `el-get-self-checksum` as shortcut for `(el-get-checksum 'el-get)` (fixes #524)
 * Rewrite `el-get-register-method` and `el-get-register-derived-method` to use keyword args (fixes #528)
parents 6063cfe3 5c89a936
...@@ -35,6 +35,11 @@ release. ...@@ -35,6 +35,11 @@ release.
Please note that this versioning policy has been picked while backing Please note that this versioning policy has been picked while backing
1.2~dev, so 1.0 was a "stable" release in fact. Ah, history. 1.2~dev, so 1.0 was a "stable" release in fact. Ah, history.
In addition to the version, you can also get the exact git revision by
running M-x +el-get-self-checksum+. You should provide this checksum
when seeking support or reporting a bug, so that the developers will
know exactly which version you are using.
== How to Install it? == How to Install it?
Here's the 'lazy installer': Here's the 'lazy installer':
......
...@@ -36,19 +36,45 @@ ...@@ -36,19 +36,45 @@
The methods list is a PLIST, each entry has a method name The methods list is a PLIST, each entry has a method name
property which value is another PLIST, which must contain values property which value is another PLIST, which must contain values
for :install, :install-hook, :update, :remove and :checksum for :install, :install-hook, :update, :remove, :remove-hook
properties. Those should be the elisp functions to call for doing and :checksum properties. Those should be the elisp functions to
the named package action in the given method.") call for doing the named package action in the given method.")
(defun el-get-register-method (name install update remove (defun el-get-method-defined-p (name)
&optional install-hook remove-hook compute-checksum) "Returns t if NAME is a known el-get install method backend, nil otherwise."
(and (el-get-method name :install) t))
(defun* el-get-register-method (name &key install update remove
install-hook remove-hook compute-checksum)
"Register the method for backend NAME, with given functions" "Register the method for backend NAME, with given functions"
(loop for required-arg in '(install update remove)
unless (symbol-value required-arg)
do (error "Missing required argument: :%s" required-arg))
(let ((def (list :install install :update update :remove remove))) (let ((def (list :install install :update update :remove remove)))
(when install-hook (setq def (append def (list :install-hook install-hook)))) (when install-hook (setq def (plist-put def :install-hook install-hook)))
(when remove-hook (setq def (append def (list :remove-hook remove-hook)))) (when remove-hook (setq def (plist-put def :remove-hook remove-hook)))
(when compute-checksum (setq def (append def (list :compute-checksum compute-checksum)))) (when compute-checksum (setq def (plist-put def :compute-checksum compute-checksum)))
(setq el-get-methods (plist-put el-get-methods name def)))) (setq el-get-methods (plist-put el-get-methods name def))))
(put 'el-get-register-method 'lisp-indent-function
(get 'prog1 'lisp-indent-function))
(defun* el-get-register-derived-method (name derived-from-name
&rest keys &key &allow-other-keys)
"Register the method for backend NAME.
Defaults for all optional arguments are taken from
already-defined method DERIVED-FROM-NAME."
(unless (el-get-method-defined-p derived-from-name)
(error "Cannot derive new el-get method from unknown method %s" derived-from-name))
(apply #'el-get-register-method name (append keys (plist-get el-get-methods derived-from-name))))
(put 'el-get-register-derived-method 'lisp-indent-function
(get 'prog2 'lisp-indent-function))
(defun el-get-register-method-alias (name old-name)
"Register NAME as an alias for install method OLD-NAME."
(el-get-register-derived-method name old-name))
;; ;;
...@@ -136,8 +162,9 @@ entry." ...@@ -136,8 +162,9 @@ entry."
(defun el-get-method (method-name action) (defun el-get-method (method-name action)
"Return the function to call for doing action (e.g. install) in "Return the function to call for doing action (e.g. install) in
given method." given method."
(let* ((method (intern (concat ":" (format "%s" method-name)))) (let* ((method (if (keywordp method-name) method-name
(actions (plist-get el-get-methods method))) (intern (concat ":" (format "%s" method-name)))))
(actions (plist-get el-get-methods method)))
(plist-get actions action))) (plist-get actions action)))
(defun el-get-check-init () (defun el-get-check-init ()
......
...@@ -27,6 +27,11 @@ ...@@ -27,6 +27,11 @@
;; ;;
;; Please note that this versioning policy has been picked while backing ;; Please note that this versioning policy has been picked while backing
;; 1.2~dev, so 1.0 was a "stable" release in fact. Ah, history. ;; 1.2~dev, so 1.0 was a "stable" release in fact. Ah, history.
;;
;; In addition to the version, you can also get the exact git revision
;; by running M-x `el-get-self-checksum'. You should provide this
;; checksum when seeking support or reporting a bug, so that the
;; developers will know exactly which version you are using.
;;; Change Log: ;;; Change Log:
;; ;;
...@@ -700,8 +705,16 @@ entry which is not a symbol and is not already a known recipe." ...@@ -700,8 +705,16 @@ entry which is not a symbol and is not already a known recipe."
(error "package method %s does not support checksums" type)) (error "package method %s does not support checksums" type))
(when compute-checksum (when compute-checksum
(let ((checksum (funcall compute-checksum package))) (let ((checksum (funcall compute-checksum package)))
(message "Checksum for package %s is: %s" package checksum) (message "Checksum for package %s is: %s. It has been copied to the kill-ring."
(kill-new checksum))))) package checksum)
(kill-new checksum)))))
(defun el-get-self-checksum ()
"Compute the checksum of the running version of el-get itself.
Also put the checksum in the kill-ring."
(interactive)
(el-get-checksum 'el-get))
;; ;;
......
...@@ -150,8 +150,11 @@ password prompt." ...@@ -150,8 +150,11 @@ password prompt."
(add-hook 'el-get-apt-get-remove-hook 'el-get-dpkg-remove-symlink) (add-hook 'el-get-apt-get-remove-hook 'el-get-dpkg-remove-symlink)
(el-get-register-method (el-get-register-method :apt-get
:apt-get #'el-get-apt-get-install #'el-get-apt-get-install #'el-get-apt-get-remove :install #'el-get-apt-get-install
#'el-get-apt-get-install-hook #'el-get-apt-get-remove-hook) :update #'el-get-apt-get-install
:remove #'el-get-apt-get-remove
:install-hook #'el-get-apt-get-install-hook
:remove-hook #'el-get-apt-get-remove-hook)
(provide 'el-get-apt-get) (provide 'el-get-apt-get)
...@@ -89,8 +89,11 @@ ...@@ -89,8 +89,11 @@
(add-hook 'el-get-brew-remove-hook 'el-get-dpkg-remove-symlink) (add-hook 'el-get-brew-remove-hook 'el-get-dpkg-remove-symlink)
(el-get-register-method (el-get-register-method :brew
:brew :install #'el-get-brew-install
#'el-get-brew-install #'el-get-brew-update #'el-get-brew-remove #'el-get-brew-install-hook #'el-get-brew-remove-hook) :update #'el-get-brew-update
:remove #'el-get-brew-remove
:install-hook #'el-get-brew-install-hook
:remove-hook #'el-get-brew-remove-hook)
(provide 'el-get-brew) (provide 'el-get-brew)
...@@ -25,8 +25,10 @@ ...@@ -25,8 +25,10 @@
(make-directory pdir)) (make-directory pdir))
(funcall post-install-fun package))) (funcall post-install-fun package)))
(el-get-register-method (el-get-register-method :builtin
:builtin #'el-get-builtin-install #'el-get-builtin-install #'el-get-rmdir :install #'el-get-builtin-install
#'el-get-builtin-install-hook) :update #'el-get-builtin-install
:remove #'el-get-rmdir
:install-hook #'el-get-builtin-install-hook)
(provide 'el-get-builtin) (provide 'el-get-builtin)
...@@ -56,8 +56,10 @@ ...@@ -56,8 +56,10 @@
:error ,ko)) :error ,ko))
post-update-fun))) post-update-fun)))
(el-get-register-method (el-get-register-method :bzr
:bzr #'el-get-bzr-branch #'el-get-bzr-pull #'el-get-rmdir :install #'el-get-bzr-branch
el-get-bzr-branch-hook) :update #'el-get-bzr-pull
:remove #'el-get-rmdir
:install-hook el-get-bzr-branch-hook)
(provide 'el-get-bzr) (provide 'el-get-bzr)
...@@ -73,8 +73,10 @@ ...@@ -73,8 +73,10 @@
:error ,ko)) :error ,ko))
post-update-fun))) post-update-fun)))
(el-get-register-method (el-get-register-method :cvs
:cvs #'el-get-cvs-checkout #'el-get-cvs-update #'el-get-rmdir :install #'el-get-cvs-checkout
#'el-get-cvs-checkout-hook) :update #'el-get-cvs-update
:remove #'el-get-rmdir
:install-hook #'el-get-cvs-checkout-hook)
(provide 'el-get-cvs) (provide 'el-get-cvs)
...@@ -56,8 +56,10 @@ ...@@ -56,8 +56,10 @@
:error ,ko)) :error ,ko))
post-update-fun))) post-update-fun)))
(el-get-register-method (el-get-register-method :darcs
:darcs #'el-get-darcs-get #'el-get-darcs-pull #'el-get-rmdir :install #'el-get-darcs-get
#'el-get-darcs-get-hook) :update #'el-get-darcs-pull
:remove #'el-get-rmdir
:install-hook #'el-get-darcs-get-hook)
(provide 'el-get-darcs) (provide 'el-get-darcs)
...@@ -134,8 +134,11 @@ the recipe, then return nil." ...@@ -134,8 +134,11 @@ the recipe, then return nil."
(add-hook 'el-get-elpa-remove-hook 'el-get-elpa-post-remove) (add-hook 'el-get-elpa-remove-hook 'el-get-elpa-post-remove)
(el-get-register-method (el-get-register-method :elpa
:elpa #'el-get-elpa-install #'el-get-elpa-update #'el-get-elpa-remove :install #'el-get-elpa-install
#'el-get-elpa-install-hook #'el-get-elpa-remove-hook) :update #'el-get-elpa-update
:remove #'el-get-elpa-remove
:install-hook #'el-get-elpa-install-hook
:remove-hook #'el-get-elpa-remove-hook)
(provide 'el-get-elpa) (provide 'el-get-elpa)
...@@ -33,8 +33,7 @@ ...@@ -33,8 +33,7 @@
(url (or url (format el-get-emacsmirror-base-url pkgname)))) (url (or url (format el-get-emacsmirror-base-url pkgname))))
(el-get-git-clone package url post-install-fun))) (el-get-git-clone package url post-install-fun)))
(el-get-register-method (el-get-register-derived-method :emacsmirror :git
:emacsmirror #'el-get-emacsmirror-clone #'el-get-git-pull #'el-get-rmdir :install #'el-get-emacsmirror-clone)
#'el-get-git-clone-hook)
(provide 'el-get-emacsmirror) (provide 'el-get-emacsmirror)
...@@ -36,9 +36,9 @@ filename.el ;;; filename.el --- description" ...@@ -36,9 +36,9 @@ filename.el ;;; filename.el --- description"
(let ((url (or url (format "%s%s.el" el-get-emacswiki-base-url package)))) (let ((url (or url (format "%s%s.el" el-get-emacswiki-base-url package))))
(el-get-http-install package url post-install-fun))) (el-get-http-install package url post-install-fun)))
(el-get-register-method (el-get-register-derived-method :emacswiki :http
:emacswiki #'el-get-emacswiki-install #'el-get-emacswiki-install #'el-get-rmdir :install #'el-get-emacswiki-install
#'el-get-http-install-hook nil #'el-get-http-compute-checksum) :update #'el-get-emacswiki-install)
;;; ;;;
;;; Functions to maintain a local recipe list from EmacsWiki ;;; Functions to maintain a local recipe list from EmacsWiki
......
...@@ -76,9 +76,11 @@ ...@@ -76,9 +76,11 @@
(add-hook 'el-get-fink-remove-hook 'el-get-dpkg-remove-symlink) (add-hook 'el-get-fink-remove-hook 'el-get-dpkg-remove-symlink)
(el-get-register-method (el-get-register-method :fink
:fink :install #'el-get-fink-install
#'el-get-fink-install #'el-get-fink-install #'el-get-fink-remove :update #'el-get-fink-install
#'el-get-fink-install-hook #'el-get-fink-remove-hook) :remove #'el-get-fink-remove
:install-hook #'el-get-fink-install-hook
:remove-hook #'el-get-fink-remove-hook)
(provide 'el-get-fink) (provide 'el-get-fink)
...@@ -68,9 +68,9 @@ ...@@ -68,9 +68,9 @@
:error ,r-ko)) :error ,r-ko))
post-update-fun))) post-update-fun)))
(el-get-register-method (el-get-register-derived-method :git-svn :git
:git-svn :install #'el-get-git-svn-clone
#'el-get-git-svn-clone #'el-get-git-svn-update #'el-get-rmdir :update #'el-get-git-svn-update
#'el-get-git-svn-clone-hook) :install-hook #'el-get-git-svn-clone-hook)
(provide 'el-get-git-svn) (provide 'el-get-git-svn)
...@@ -89,8 +89,22 @@ found." ...@@ -89,8 +89,22 @@ found."
:error "Could not update git submodules")) :error "Could not update git submodules"))
post-update-fun))) post-update-fun)))
(el-get-register-method (defun el-get-git-compute-checksum (package)
:git #'el-get-git-clone #'el-get-git-pull #'el-get-rmdir "Return the hash of the checked-out revision of PACKAGE."
#'el-get-git-clone-hook) (with-temp-buffer
(cd (el-get-package-directory package))
(let* ((args '("git" "show-ref" "HEAD"))
(cmd (mapconcat 'shell-quote-argument args " "))
(output (shell-command-to-string cmd))
(hash (and (string-match "^[[:space:]]*\\([^[:space:]]+\\)" output)
(match-string 0 output))))
hash)))
(el-get-register-method :git
:install #'el-get-git-clone
:update #'el-get-git-pull
:remove #'el-get-rmdir
:install-hook #'el-get-git-clone-hook
:compute-checksum #'el-get-git-compute-checksum)
(provide 'el-get-git) (provide 'el-get-git)
...@@ -58,8 +58,22 @@ ...@@ -58,8 +58,22 @@
:error ,ko)) :error ,ko))
post-update-fun))) post-update-fun)))
(el-get-register-method (defun el-get-hg-compute-checksum (package)
:hg #'el-get-hg-clone #'el-get-hg-pull #'el-get-rmdir "Return the hash of the checked-out revision of PACKAGE."
#'el-get-hg-clone-hook) (with-temp-buffer
(cd (el-get-package-directory package))
(let* ((args '("hg" "--debug" "tags"))
(cmd (mapconcat 'shell-quote-argument args " "))
(output (shell-command-to-string cmd))
(hash (and (string-match "^tip[[:space:]]+[0-9]+\\:\\([0-9A-Fa-f]+\\)" output)
(match-string 0 output))))
hash)))
(el-get-register-method :hg
:install #'el-get-hg-clone
:update #'el-get-hg-pull
:remove #'el-get-rmdir
:install-hook #'el-get-hg-clone-hook
:compute-checksum #'el-get-hg-compute-checksum)
(provide 'el-get-hg) (provide 'el-get-hg)
...@@ -63,8 +63,10 @@ the files up." ...@@ -63,8 +63,10 @@ the files up."
(add-hook 'el-get-http-tar-install-hook 'el-get-http-tar-cleanup-extract-hook) (add-hook 'el-get-http-tar-install-hook 'el-get-http-tar-cleanup-extract-hook)
(el-get-register-method (el-get-register-method :http-tar
:http-tar #'el-get-http-tar-install #'el-get-http-tar-install #'el-get-rmdir :install #'el-get-http-tar-install
#'el-get-http-tar-install-hook) :update #'el-get-http-tar-install
:remove #'el-get-rmdir
:install-hook #'el-get-http-tar-install-hook)
(provide 'el-get-http-tar) (provide 'el-get-http-tar)
...@@ -60,11 +60,13 @@ the files up." ...@@ -60,11 +60,13 @@ the files up."
:error ,ko)) :error ,ko))
,(symbol-function post-install-fun)))))) ,(symbol-function post-install-fun))))))
(el-get-http-install package url post dest))) (el-get-http-install package url post dest)))
(add-hook 'el-get-http-zip-install-hook 'el-get-http-zip-cleanup-extract-hook) (add-hook 'el-get-http-zip-install-hook 'el-get-http-zip-cleanup-extract-hook)
(el-get-register-method (el-get-register-method :http-zip
:http-zip #'el-get-http-zip-install #'el-get-http-zip-install #'el-get-rmdir :install #'el-get-http-zip-install
#'el-get-http-zip-install-hook) :update #'el-get-http-zip-install
:remove #'el-get-rmdir
:install-hook #'el-get-http-zip-install-hook)
(provide 'el-get-http-zip) (provide 'el-get-http-zip)
...@@ -90,12 +90,13 @@ into the package :localname option or its `file-name-nondirectory' part." ...@@ -90,12 +90,13 @@ into the package :localname option or its `file-name-nondirectory' part."
(puthash package checksum el-get-http-checksums)) (puthash package checksum el-get-http-checksums))
checksum)) checksum))
(el-get-register-method (el-get-register-method :http
:http #'el-get-http-install #'el-get-http-install #'el-get-rmdir :install #'el-get-http-install
#'el-get-http-install-hook nil #'el-get-http-compute-checksum) :update #'el-get-http-install
:remove #'el-get-rmdir
:install-hook #'el-get-http-install-hook
:compute-checksum #'el-get-http-compute-checksum)
(el-get-register-method (el-get-register-method-alias :ftp :http)
:ftp #'el-get-http-install #'el-get-http-install #'el-get-rmdir
#'el-get-http-install-hook nil #'el-get-http-compute-checksum)
(provide 'el-get-http) (provide 'el-get-http)
...@@ -63,9 +63,11 @@ ...@@ -63,9 +63,11 @@
(add-hook 'el-get-pacman-remove-hook 'el-get-dpkg-remove-symlink) (add-hook 'el-get-pacman-remove-hook 'el-get-dpkg-remove-symlink)
(el-get-register-method (el-get-register-method :pacman
:pacman :install #'el-get-pacman-install
#'el-get-pacman-install #'el-get-pacman-install #'el-get-pacman-remove :update #'el-get-pacman-install
#'el-get-pacman-install-hook #'el-get-pacman-remove-hook) :remove #'el-get-pacman-remove
:install-hook #'el-get-pacman-install-hook
:remove-hook #'el-get-pacman-remove-hook)
(provide 'el-get-pacman) (provide 'el-get-pacman)
...@@ -66,8 +66,10 @@ ...@@ -66,8 +66,10 @@
:error ,ko)) :error ,ko))
post-update-fun))) post-update-fun)))
(el-get-register-method (el-get-register-method :svn
:svn #'el-get-svn-checkout #'el-get-svn-update #'el-get-rmdir :install #'el-get-svn-checkout
#'el-get-svn-checkout-hook) :update #'el-get-svn-update
:remove #'el-get-rmdir
:install-hook #'el-get-svn-checkout-hook)
(provide 'el-get-svn) (provide 'el-get-svn)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment