diff options
| author | Jambunathan K | 2011-02-25 13:30:00 -0500 |
|---|---|---|
| committer | Chong Yidong | 2011-02-25 13:30:00 -0500 |
| commit | 7fe42546dd03801d190684ae29ced8e13b192156 (patch) | |
| tree | 4912f1610b521f53c3d6b5164c70786392d6c627 | |
| parent | 003522ceb63964998728415caaa9e328aeb74bce (diff) | |
| download | emacs-7fe42546dd03801d190684ae29ced8e13b192156.tar.gz emacs-7fe42546dd03801d190684ae29ced8e13b192156.zip | |
Fix package uploading for newly made or local archives.
* emacs-lisp/package-x.el (package--archive-contents-from-url)
(package--archive-contents-from-file): New functions.
(package-update-news-on-upload): New var.
(package-upload-buffer-internal): Extract archive-contents from
package-archive-upload-base if it is not found at archive-url.
Obey package-update-news-on-upload.
(package-upload-buffer, package-upload-file): Doc fix.
| -rw-r--r-- | lisp/ChangeLog | 10 | ||||
| -rw-r--r-- | lisp/emacs-lisp/package-x.el | 89 |
2 files changed, 77 insertions, 22 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index c44c491cad0..b59b11590d0 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,13 @@ | |||
| 1 | 2011-02-25 Jambunathan K <kjambunathan@gmail.com> | ||
| 2 | |||
| 3 | * emacs-lisp/package-x.el (package--archive-contents-from-url) | ||
| 4 | (package--archive-contents-from-file): New functions. | ||
| 5 | (package-update-news-on-upload): New var. | ||
| 6 | (package-upload-buffer-internal): Extract archive-contents from | ||
| 7 | package-archive-upload-base if it is not found at archive-url. | ||
| 8 | Obey package-update-news-on-upload. | ||
| 9 | (package-upload-buffer, package-upload-file): Doc fix. | ||
| 10 | |||
| 1 | 2011-02-24 Glenn Morris <rgm@gnu.org> | 11 | 2011-02-24 Glenn Morris <rgm@gnu.org> |
| 2 | 12 | ||
| 3 | * files-x.el (modify-dir-local-variable): Handle dir-locals from | 13 | * files-x.el (modify-dir-local-variable): Handle dir-locals from |
diff --git a/lisp/emacs-lisp/package-x.el b/lisp/emacs-lisp/package-x.el index b9994be3d39..61f23abf0a7 100644 --- a/lisp/emacs-lisp/package-x.el +++ b/lisp/emacs-lisp/package-x.el | |||
| @@ -40,6 +40,9 @@ | |||
| 40 | (defvar package-archive-upload-base nil | 40 | (defvar package-archive-upload-base nil |
| 41 | "Base location for uploading to package archive.") | 41 | "Base location for uploading to package archive.") |
| 42 | 42 | ||
| 43 | (defvar package-update-news-on-upload nil | ||
| 44 | "Whether package upload should also update NEWS and RSS feeds.") | ||
| 45 | |||
| 43 | (defun package--encode (string) | 46 | (defun package--encode (string) |
| 44 | "Encode a string by replacing some characters with XML entities." | 47 | "Encode a string by replacing some characters with XML entities." |
| 45 | ;; We need a special case for translating "&" to "&". | 48 | ;; We need a special case for translating "&" to "&". |
| @@ -86,6 +89,36 @@ | |||
| 86 | (unless old-buffer | 89 | (unless old-buffer |
| 87 | (kill-buffer (current-buffer))))))) | 90 | (kill-buffer (current-buffer))))))) |
| 88 | 91 | ||
| 92 | (defun package--archive-contents-from-url (archive-url) | ||
| 93 | "Parse archive-contents file at ARCHIVE-URL. | ||
| 94 | Return the file contents, as a string, or nil if unsuccessful." | ||
| 95 | (ignore-errors | ||
| 96 | (when archive-url | ||
| 97 | (let* ((buffer (url-retrieve-synchronously | ||
| 98 | (concat archive-url "archive-contents")))) | ||
| 99 | (set-buffer buffer) | ||
| 100 | (package-handle-response) | ||
| 101 | (re-search-forward "^$" nil 'move) | ||
| 102 | (forward-char) | ||
| 103 | (delete-region (point-min) (point)) | ||
| 104 | (prog1 (package-read-from-string | ||
| 105 | (buffer-substring-no-properties (point-min) (point-max))) | ||
| 106 | (kill-buffer buffer)))))) | ||
| 107 | |||
| 108 | (defun package--archive-contents-from-file (file) | ||
| 109 | "Parse the given archive-contents file." | ||
| 110 | (if (not (file-exists-p file)) | ||
| 111 | ;; no existing archive-contents, possibly a new ELPA repo. | ||
| 112 | (list package-archive-version) | ||
| 113 | (let ((dont-kill (find-buffer-visiting file))) | ||
| 114 | (with-current-buffer (let ((find-file-visit-truename t)) | ||
| 115 | (find-file-noselect file)) | ||
| 116 | (prog1 | ||
| 117 | (package-read-from-string | ||
| 118 | (buffer-substring-no-properties (point-min) (point-max))) | ||
| 119 | (unless dont-kill | ||
| 120 | (kill-buffer (current-buffer)))))))) | ||
| 121 | |||
| 89 | (defun package-maint-add-news-item (title description archive-url) | 122 | (defun package-maint-add-news-item (title description archive-url) |
| 90 | "Add a news item to the ELPA web pages. | 123 | "Add a news item to the ELPA web pages. |
| 91 | TITLE is the title of the news item. | 124 | TITLE is the title of the news item. |
| @@ -111,11 +144,20 @@ PKG-INFO is the package info, see `package-buffer-info'. | |||
| 111 | EXTENSION is the file extension, a string. It can be either | 144 | EXTENSION is the file extension, a string. It can be either |
| 112 | \"el\" or \"tar\". | 145 | \"el\" or \"tar\". |
| 113 | 146 | ||
| 147 | The variable `package-archive-upload-base' specifies the upload | ||
| 148 | destination. If this is nil, signal an error. | ||
| 149 | |||
| 114 | Optional arg ARCHIVE-URL is the URL of the destination archive. | 150 | Optional arg ARCHIVE-URL is the URL of the destination archive. |
| 115 | If nil, the \"gnu\" archive is used." | 151 | If it is non-nil, compute the new \"archive-contents\" file |
| 116 | (unless archive-url | 152 | starting from the existing \"archive-contents\" at that URL. In |
| 117 | (or (setq archive-url (cdr (assoc "gnu" package-archives))) | 153 | addition, if `package-update-news-on-upload' is non-nil, call |
| 118 | (error "No destination URL"))) | 154 | `package--update-news' to add a news item at that URL. |
| 155 | |||
| 156 | If ARCHIVE-URL is nil, compute the new \"archive-contents\" file | ||
| 157 | from the \"archive-contents\" at `package-archive-upload-base', | ||
| 158 | if it exists." | ||
| 159 | (unless package-archive-upload-base | ||
| 160 | (error "No destination specified in `package-archive-upload-base'")) | ||
| 119 | (save-excursion | 161 | (save-excursion |
| 120 | (save-restriction | 162 | (save-restriction |
| 121 | (let* ((file-type (cond | 163 | (let* ((file-type (cond |
| @@ -131,21 +173,14 @@ If nil, the \"gnu\" archive is used." | |||
| 131 | (pkg-version (aref pkg-info 3)) | 173 | (pkg-version (aref pkg-info 3)) |
| 132 | (commentary (aref pkg-info 4)) | 174 | (commentary (aref pkg-info 4)) |
| 133 | (split-version (version-to-list pkg-version)) | 175 | (split-version (version-to-list pkg-version)) |
| 134 | (pkg-buffer (current-buffer)) | 176 | (pkg-buffer (current-buffer))) |
| 135 | 177 | ||
| 136 | ;; Download latest archive-contents. | 178 | ;; Get archive-contents from ARCHIVE-URL if it's non-nil, or |
| 137 | (buffer (url-retrieve-synchronously | 179 | ;; from `package-archive-upload-base' otherwise. |
| 138 | (concat archive-url "archive-contents")))) | 180 | (let ((contents (or (package--archive-contents-from-url archive-url) |
| 139 | 181 | (package--archive-contents-from-file | |
| 140 | ;; Parse archive-contents. | 182 | (concat package-archive-upload-base |
| 141 | (set-buffer buffer) | 183 | "archive-contents")))) |
| 142 | (package-handle-response) | ||
| 143 | (re-search-forward "^$" nil 'move) | ||
| 144 | (forward-char) | ||
| 145 | (delete-region (point-min) (point)) | ||
| 146 | (let ((contents (package-read-from-string | ||
| 147 | (buffer-substring-no-properties (point-min) | ||
| 148 | (point-max)))) | ||
| 149 | (new-desc (vector split-version requires desc file-type))) | 184 | (new-desc (vector split-version requires desc file-type))) |
| 150 | (if (> (car contents) package-archive-version) | 185 | (if (> (car contents) package-archive-version) |
| 151 | (error "Unrecognized archive version %d" (car contents))) | 186 | (error "Unrecognized archive version %d" (car contents))) |
| @@ -176,7 +211,6 @@ If nil, the \"gnu\" archive is used." | |||
| 176 | (symbol-name pkg-name) "-readme.txt"))) | 211 | (symbol-name pkg-name) "-readme.txt"))) |
| 177 | 212 | ||
| 178 | (set-buffer pkg-buffer) | 213 | (set-buffer pkg-buffer) |
| 179 | (kill-buffer buffer) | ||
| 180 | (write-region (point-min) (point-max) | 214 | (write-region (point-min) (point-max) |
| 181 | (concat package-archive-upload-base | 215 | (concat package-archive-upload-base |
| 182 | file-name "-" pkg-version | 216 | file-name "-" pkg-version |
| @@ -184,8 +218,10 @@ If nil, the \"gnu\" archive is used." | |||
| 184 | nil nil nil 'excl) | 218 | nil nil nil 'excl) |
| 185 | 219 | ||
| 186 | ;; Write a news entry. | 220 | ;; Write a news entry. |
| 187 | (package--update-news (concat file-name "." extension) | 221 | (and package-update-news-on-upload |
| 188 | pkg-version desc archive-url) | 222 | archive-url |
| 223 | (package--update-news (concat file-name "." extension) | ||
| 224 | pkg-version desc archive-url)) | ||
| 189 | 225 | ||
| 190 | ;; special-case "package": write a second copy so that the | 226 | ;; special-case "package": write a second copy so that the |
| 191 | ;; installer can easily find the latest version. | 227 | ;; installer can easily find the latest version. |
| @@ -196,7 +232,9 @@ If nil, the \"gnu\" archive is used." | |||
| 196 | nil nil nil 'ask))))))) | 232 | nil nil nil 'ask))))))) |
| 197 | 233 | ||
| 198 | (defun package-upload-buffer () | 234 | (defun package-upload-buffer () |
| 199 | "Upload a single .el file to ELPA from the current buffer." | 235 | "Upload the current buffer as a single-file Emacs Lisp package. |
| 236 | The variable `package-archive-upload-base' specifies the upload | ||
| 237 | destination." | ||
| 200 | (interactive) | 238 | (interactive) |
| 201 | (save-excursion | 239 | (save-excursion |
| 202 | (save-restriction | 240 | (save-restriction |
| @@ -205,6 +243,13 @@ If nil, the \"gnu\" archive is used." | |||
| 205 | (package-upload-buffer-internal pkg-info "el"))))) | 243 | (package-upload-buffer-internal pkg-info "el"))))) |
| 206 | 244 | ||
| 207 | (defun package-upload-file (file) | 245 | (defun package-upload-file (file) |
| 246 | "Upload the Emacs Lisp package FILE to the package archive. | ||
| 247 | Interactively, prompt for FILE. The package is considered a | ||
| 248 | single-file package if FILE ends in \".el\", and a multi-file | ||
| 249 | package if FILE ends in \".tar\". | ||
| 250 | |||
| 251 | The variable `package-archive-upload-base' specifies the upload | ||
| 252 | destination." | ||
| 208 | (interactive "fPackage file name: ") | 253 | (interactive "fPackage file name: ") |
| 209 | (with-temp-buffer | 254 | (with-temp-buffer |
| 210 | (insert-file-contents-literally file) | 255 | (insert-file-contents-literally file) |