unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Philip Kaludercic <philipk@posteo.net>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: emacs-devel@gnu.org
Subject: Re: Removing packages from archive-contents if removed from elpa-packages
Date: Tue, 01 Nov 2022 10:42:37 +0000	[thread overview]
Message-ID: <87y1svgdlu.fsf@posteo.net> (raw)
In-Reply-To: <jwvmt9b51g4.fsf-monnier+emacs@gnu.org> (Stefan Monnier's message of "Mon, 31 Oct 2022 13:53:18 -0400")

[-- Attachment #1: Type: text/plain, Size: 1436 bytes --]

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> +(defun elpaa--scrub-archive-contents (dir)
>> +  "Remove dead packages from archive contents in DIR."
>> +  (let* ((filename (expand-file-name "archive-contents" dir))
>> +         (ac (if (file-exists-p filename)
>> +                 (elpaa--form-from-file-contents filename)
>> +               '(1)))
>> +         (specs (elpaa--get-specs)))
>> +    (elpaa--write-archive-contents
>> +     (cons (car ac)
>> +           (mapcan
>> +            (lambda (pkg)
>> +              (and (assoc (car pkg) specs #'string=) (list pkg)))
>> +            (cdr ac)))
>> +     dir)))
>> +
>>  (defun elpaa--publish-package-specs (specs)
>>    "Process and publish SPECS in elpa-packages.eld files."
>>    (with-temp-buffer
>> @@ -814,6 +833,8 @@ of the current `process-environment'.  Return the modified copy."
>>  
>>  (defun elpaa-batch-make-all-packages (&rest _)
>>    "Check all the packages and build the relevant new tarballs."
>> +  (elpaa--scrub-archive-contents elpaa--release-subdir)
>> +  (elpaa--scrub-archive-contents elpaa--devel-subdir)
>>    (let ((specs (elpaa--get-specs)))
>>      (dolist (spec specs)
>>        (condition-case err
>
> Hmm... in `elpaa--scrub-archive-contents` you `elpaa--get-specs` but you
> could skip that if you called this function a tiny bit later and passed
> `specs` to it instead, right?

No, you are absolutely right, I just didn't see that.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Remove-deleted-packages-from-archive-contents.patch --]
[-- Type: text/x-patch, Size: 3164 bytes --]

From 62fa93b120f664f1be44c1194f701a1c5d965f2a Mon Sep 17 00:00:00 2001
From: Philip Kaludercic <philipk@posteo.net>
Date: Mon, 31 Oct 2022 17:01:07 +0100
Subject: [PATCH 1/2] Remove deleted packages from archive-contents

* elpa-admin.el (elpaa--write-archive-contents): Extract from
'elpaa--update-archive-contents'
(elpaa--update-archive-contents): Use 'elpaa--write-archive-contents'.
(elpaa--scrub-archive-contents): Add function.
(elpaa-batch-make-all-packages): Call 'elpaa--scrub-archive-contents'.
---
 elpa-admin.el | 31 ++++++++++++++++++++++++++-----
 1 file changed, 26 insertions(+), 5 deletions(-)

diff --git a/elpa-admin.el b/elpa-admin.el
index c03fea47a1..12306ec818 100644
--- a/elpa-admin.el
+++ b/elpa-admin.el
@@ -154,6 +154,14 @@ Delete backup files also."
 	       (backup-file-name-p f))
 	   (delete-file f)))))
 
+(defun elpaa--write-archive-contents (ac dir)
+  "Write archive contents AC into directory DIR."
+  (with-temp-buffer
+    (pp ac (current-buffer))
+    (write-region nil nil (expand-file-name "archive-contents" dir)))
+  (let ((default-directory (expand-file-name dir)))
+    (elpaa--html-make-index (cdr ac))))
+
 (defun elpaa--update-archive-contents (pkg-desc dir)
   "Update the `archive-contents' file in DIR with new package PKG-DESC."
   (let* ((filename (expand-file-name "archive-contents" dir))
@@ -166,11 +174,7 @@ Delete backup files also."
                          (lambda (x y)
                            (string-lessp (symbol-name (car x)) (symbol-name (car y))))))
     (elpaa--message "new AC: %S" ac)
-    (with-temp-buffer
-      (pp ac (current-buffer))
-      (write-region nil nil filename)
-      (let ((default-directory (expand-file-name dir)))
-        (elpaa--html-make-index (cdr ac))))))
+    (elpaa--write-archive-contents ac dir)))
 
 (defun elpaa--get-specs ()
   (elpaa--form-from-file-contents elpaa--specs-file))
@@ -788,6 +792,21 @@ of the current `process-environment'.  Return the modified copy."
 	  (list pkgname))
       spec)))
 
+(defun elpaa--scrub-archive-contents (dir specs)
+  "Remove dead packages from archive contents in DIR.
+SPECS is the list of package specifications."
+  (let* ((filename (expand-file-name "archive-contents" dir))
+         (ac (if (file-exists-p filename)
+                 (elpaa--form-from-file-contents filename)
+               '(1))))
+    (elpaa--write-archive-contents
+     (cons (car ac)
+           (mapcan
+            (lambda (pkg)
+              (and (assoc (car pkg) specs #'string=) (list pkg)))
+            (cdr ac)))
+     dir)))
+
 (defun elpaa--publish-package-specs (specs)
   "Process and publish SPECS in elpa-packages.eld files."
   (with-temp-buffer
@@ -815,6 +834,8 @@ of the current `process-environment'.  Return the modified copy."
 (defun elpaa-batch-make-all-packages (&rest _)
   "Check all the packages and build the relevant new tarballs."
   (let ((specs (elpaa--get-specs)))
+    (elpaa--scrub-archive-contents elpaa--release-subdir specs)
+    (elpaa--scrub-archive-contents elpaa--devel-subdir specs)
     (dolist (spec specs)
       (condition-case err
           (elpaa--make-one-package spec)
-- 
2.38.0


[-- Attachment #3: Type: text/plain, Size: 474 bytes --]


>
>         Stefan
>
>
> PS: Haven't really looked at the rest of the patch, actually, this part
> just jumped at me.  But now that I see how this is more complex than
> your original patch, maybe doing it N times is the better option (and if
> not, we can add a global boolean var telling us if we've done it
> already).

It is slightly more complicated, if only because I extracted
`elpaa--write-archive-contents', but I think it is a lot cleaner than my
first approach.

  reply	other threads:[~2022-11-01 10:42 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-31  9:40 Removing packages from archive-contents if removed from elpa-packages Philip Kaludercic
2022-10-31 12:11 ` Stefan Monnier
2022-10-31 14:25   ` Philip Kaludercic
2022-10-31 14:47     ` Stefan Kangas
2022-10-31 15:10       ` Philip Kaludercic
2022-10-31 16:06     ` Philip Kaludercic
2022-10-31 17:53       ` Stefan Monnier
2022-11-01 10:42         ` Philip Kaludercic [this message]
2022-11-02  2:02           ` Stefan Monnier
2022-11-02  6:59             ` Philip Kaludercic

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87y1svgdlu.fsf@posteo.net \
    --to=philipk@posteo.net \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).