unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Removing packages from archive-contents if removed from elpa-packages
@ 2022-10-31  9:40 Philip Kaludercic
  2022-10-31 12:11 ` Stefan Monnier
  0 siblings, 1 reply; 10+ messages in thread
From: Philip Kaludercic @ 2022-10-31  9:40 UTC (permalink / raw)
  To: emacs-devel

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


Hi,

there is at least one broken package on NonGNU ELPA
(color-theme-tangotango) that was added, then removed as dependencies
were missing, but it remained in the archive because it was added to the
archive-contents file.  The following patch would make sure that any
package not listed in elpa-packages is also remove from
archive-contents:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Remove-packages-from-archive-if-they-are-not-listed-.patch --]
[-- Type: text/x-patch, Size: 1659 bytes --]

From 501309b5507e9e87eb59fbaab65184ee915a5386 Mon Sep 17 00:00:00 2001
From: Philip Kaludercic <philipk@posteo.net>
Date: Mon, 31 Oct 2022 10:18:17 +0100
Subject: [PATCH] Remove packages from archive if they are not listed in
 elpa-packages

* elpa-admin.el (elpaa--update-archive-contents): Cross-examine the
package specifications before updating archive contents.
---
 elpa-admin.el | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/elpa-admin.el b/elpa-admin.el
index c03fea47a1..ac36aa686a 100644
--- a/elpa-admin.el
+++ b/elpa-admin.el
@@ -156,15 +156,19 @@ Delete backup files also."
 
 (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))
+  (let* ((specs (elpaa--get-specs))
+         (filename (expand-file-name "archive-contents" dir))
          (ac (if (file-exists-p filename)
                  (elpaa--form-from-file-contents filename)
                '(1))))
     (elpaa--message "current AC: %S" ac)
     (setf (alist-get (car pkg-desc) (cdr ac)) (cdr pkg-desc))
-    (setf (cdr ac) (sort (cdr ac)
-                         (lambda (x y)
-                           (string-lessp (symbol-name (car x)) (symbol-name (car y))))))
+    (setf (cdr ac)
+          (sort (mapcan
+                 (lambda (pkg)
+                   (and (assoc (car pkg) specs #'string=) (list pkg)))
+                 (cdr ac))
+                (lambda (x y) (string-lessp (car x) (car y)))))
     (elpaa--message "new AC: %S" ac)
     (with-temp-buffer
       (pp ac (current-buffer))
-- 
2.38.0


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


It might be a good idea to cache the interpretation of elpa-packages, so
I would also suggest the following:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #4: 0001-Cache-elpaa-get-specs-invocations.patch --]
[-- Type: text/x-patch, Size: 1008 bytes --]

From 539e36cc448315cb26bae400cb52de4308a0a747 Mon Sep 17 00:00:00 2001
From: Philip Kaludercic <philipk@posteo.net>
Date: Mon, 31 Oct 2022 10:35:21 +0100
Subject: [PATCH] Cache 'elpaa--get-specs' invocations

* elpa-admin.el (elpa--specs-cache): Add new variable.
(elpaa--get-specs): Use 'elpa--specs-cache'.
---
 elpa-admin.el | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/elpa-admin.el b/elpa-admin.el
index ac36aa686a..3fb1d756fb 100644
--- a/elpa-admin.el
+++ b/elpa-admin.el
@@ -176,8 +176,11 @@ Delete backup files also."
       (let ((default-directory (expand-file-name dir)))
         (elpaa--html-make-index (cdr ac))))))
 
+(defvar elpa--specs-cache nil)
+
 (defun elpaa--get-specs ()
-  (elpaa--form-from-file-contents elpaa--specs-file))
+  (or elpa--specs-cache
+      (setq elpa--specs-cache (elpaa--form-from-file-contents elpaa--specs-file))))
 
 (defun elpaa--spec-get (pkg-spec prop &optional default)
   (or (plist-get (cdr pkg-spec) prop) default))
-- 
2.38.0


[-- Attachment #5: Type: text/plain, Size: 484 bytes --]


While this would fix the above problem, two points remain:

1. This does not remove any tarballs.  It wouldn't be hard to do, but I
   am not sure if there would be any unintended side effects of doing
   so -- at least immediately.

2. There are functioning packages on NonGNU ELPA like haskell-mode that
   were also added to elpa-packages then removed, and still linger in
   the archive without being updated.  This would get rid of those too,
   which might not be a good idea.

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

* Re: Removing packages from archive-contents if removed from elpa-packages
  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
  0 siblings, 1 reply; 10+ messages in thread
From: Stefan Monnier @ 2022-10-31 12:11 UTC (permalink / raw)
  To: Philip Kaludercic; +Cc: emacs-devel

Philip Kaludercic [2022-10-31 09:40:36] wrote:
> there is at least one broken package on NonGNU ELPA
> (color-theme-tangotango) that was added, then removed as dependencies
> were missing, but it remained in the archive because it was added to the
> archive-contents file.  The following patch would make sure that any
> package not listed in elpa-packages is also remove from
> archive-contents:

Thanks, but I don't think `elpaa--update-archive-contents` is the right
place for that.  This can be called N times for a given invocation of
`elpaa-batch-make-all-packages`.
Why not call a dedicated function from `elpaa-batch-make-all-packages`
(i.e. alongside the call to `elpaa--publish-package-specs`)?

> It might be a good idea to cache the interpretation of elpa-packages, so
> I would also suggest the following:

Not sure it's worth the trouble: the way the code is written, it should
be called only once per Emacs session in the majority of cases, no?

> 1. This does not remove any tarballs.  It wouldn't be hard to do, but I
>    am not sure if there would be any unintended side effects of doing
>    so -- at least immediately.

I think we should keep the old HTML page and tarballs.

> 2. There are functioning packages on NonGNU ELPA like haskell-mode that
>    were also added to elpa-packages then removed, and still linger in
>    the archive without being updated.  This would get rid of those too,
>    which might not be a good idea.

Indeed, `haskell-mode` should be re-added to `elpa-packages`
because IIRC it's still actively depended-upon (by GNU ELPA's `hcel`).


        Stefan




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

* Re: Removing packages from archive-contents if removed from elpa-packages
  2022-10-31 12:11 ` Stefan Monnier
@ 2022-10-31 14:25   ` Philip Kaludercic
  2022-10-31 14:47     ` Stefan Kangas
  2022-10-31 16:06     ` Philip Kaludercic
  0 siblings, 2 replies; 10+ messages in thread
From: Philip Kaludercic @ 2022-10-31 14:25 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

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

> Philip Kaludercic [2022-10-31 09:40:36] wrote:
>> there is at least one broken package on NonGNU ELPA
>> (color-theme-tangotango) that was added, then removed as dependencies
>> were missing, but it remained in the archive because it was added to the
>> archive-contents file.  The following patch would make sure that any
>> package not listed in elpa-packages is also remove from
>> archive-contents:
>
> Thanks, but I don't think `elpaa--update-archive-contents` is the right
> place for that.  This can be called N times for a given invocation of
> `elpaa-batch-make-all-packages`.
> Why not call a dedicated function from `elpaa-batch-make-all-packages`
> (i.e. alongside the call to `elpaa--publish-package-specs`)?

That can be done.

>> It might be a good idea to cache the interpretation of elpa-packages, so
>> I would also suggest the following:
>
> Not sure it's worth the trouble: the way the code is written, it should
> be called only once per Emacs session in the majority of cases, no?

Right, ideally somewhen around the beginning.

>> 1. This does not remove any tarballs.  It wouldn't be hard to do, but I
>>    am not sure if there would be any unintended side effects of doing
>>    so -- at least immediately.
>
> I think we should keep the old HTML page and tarballs.

I agree.

>> 2. There are functioning packages on NonGNU ELPA like haskell-mode that
>>    were also added to elpa-packages then removed, and still linger in
>>    the archive without being updated.  This would get rid of those too,
>>    which might not be a good idea.
>
> Indeed, `haskell-mode` should be re-added to `elpa-packages`
> because IIRC it's still actively depended-upon (by GNU ELPA's `hcel`).

The issue here is that upstream isn't responsive and has asked for
haskell-mode to not be added until further notice :/



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

* Re: Removing packages from archive-contents if removed from elpa-packages
  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
  1 sibling, 1 reply; 10+ messages in thread
From: Stefan Kangas @ 2022-10-31 14:47 UTC (permalink / raw)
  To: Philip Kaludercic, Stefan Monnier; +Cc: emacs-devel, Steve Purcell

Philip Kaludercic <philipk@posteo.net> writes:

> Stefan Monnier <monnier@iro.umontreal.ca> writes:
>
>> Indeed, `haskell-mode` should be re-added to `elpa-packages`
>> because IIRC it's still actively depended-upon (by GNU ELPA's `hcel`).
>
> The issue here is that upstream isn't responsive and has asked for
> haskell-mode to not be added until further notice :/

I'm copying in the haskell-mode maintainer Steve Purcell.

For background:

    https://github.com/haskell/haskell-mode/issues/1755



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

* Re: Removing packages from archive-contents if removed from elpa-packages
  2022-10-31 14:47     ` Stefan Kangas
@ 2022-10-31 15:10       ` Philip Kaludercic
  0 siblings, 0 replies; 10+ messages in thread
From: Philip Kaludercic @ 2022-10-31 15:10 UTC (permalink / raw)
  To: Stefan Kangas; +Cc: Stefan Monnier, emacs-devel, Steve Purcell

Stefan Kangas <stefankangas@gmail.com> writes:

> Philip Kaludercic <philipk@posteo.net> writes:
>
>> Stefan Monnier <monnier@iro.umontreal.ca> writes:
>>
>>> Indeed, `haskell-mode` should be re-added to `elpa-packages`
>>> because IIRC it's still actively depended-upon (by GNU ELPA's `hcel`).
>>
>> The issue here is that upstream isn't responsive and has asked for
>> haskell-mode to not be added until further notice :/
>
> I'm copying in the haskell-mode maintainer Steve Purcell.
>
> For background:
>
>     https://github.com/haskell/haskell-mode/issues/1755

If necessary, we could also revert to what we were doing initially with
the :version-map, preventing any updates but ensuring the package is
available.



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

* Re: Removing packages from archive-contents if removed from elpa-packages
  2022-10-31 14:25   ` Philip Kaludercic
  2022-10-31 14:47     ` Stefan Kangas
@ 2022-10-31 16:06     ` Philip Kaludercic
  2022-10-31 17:53       ` Stefan Monnier
  1 sibling, 1 reply; 10+ messages in thread
From: Philip Kaludercic @ 2022-10-31 16:06 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

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

Philip Kaludercic <philipk@posteo.net> writes:

> Stefan Monnier <monnier@iro.umontreal.ca> writes:
>
>> Philip Kaludercic [2022-10-31 09:40:36] wrote:
>>> there is at least one broken package on NonGNU ELPA
>>> (color-theme-tangotango) that was added, then removed as dependencies
>>> were missing, but it remained in the archive because it was added to the
>>> archive-contents file.  The following patch would make sure that any
>>> package not listed in elpa-packages is also remove from
>>> archive-contents:
>>
>> Thanks, but I don't think `elpaa--update-archive-contents` is the right
>> place for that.  This can be called N times for a given invocation of
>> `elpaa-batch-make-all-packages`.
>> Why not call a dedicated function from `elpaa-batch-make-all-packages`
>> (i.e. alongside the call to `elpaa--publish-package-specs`)?
>
> That can be done.

It has been done:


[-- 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: 3093 bytes --]

From 092dfa49a6735c5a00565ea51dcf2272ba9b64ff 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..738a957966 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)
+  "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
-- 
2.38.0


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

* Re: Removing packages from archive-contents if removed from elpa-packages
  2022-10-31 16:06     ` Philip Kaludercic
@ 2022-10-31 17:53       ` Stefan Monnier
  2022-11-01 10:42         ` Philip Kaludercic
  0 siblings, 1 reply; 10+ messages in thread
From: Stefan Monnier @ 2022-10-31 17:53 UTC (permalink / raw)
  To: Philip Kaludercic; +Cc: emacs-devel

> +(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?


        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).




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

* Re: Removing packages from archive-contents if removed from elpa-packages
  2022-10-31 17:53       ` Stefan Monnier
@ 2022-11-01 10:42         ` Philip Kaludercic
  2022-11-02  2:02           ` Stefan Monnier
  0 siblings, 1 reply; 10+ messages in thread
From: Philip Kaludercic @ 2022-11-01 10:42 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

[-- 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.

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

* Re: Removing packages from archive-contents if removed from elpa-packages
  2022-11-01 10:42         ` Philip Kaludercic
@ 2022-11-02  2:02           ` Stefan Monnier
  2022-11-02  6:59             ` Philip Kaludercic
  0 siblings, 1 reply; 10+ messages in thread
From: Stefan Monnier @ 2022-11-02  2:02 UTC (permalink / raw)
  To: Philip Kaludercic; +Cc: emacs-devel

> No, you are absolutely right, I just didn't see that.
>
> 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)))

LGTM.  Feel free to push.  Just one comment: we could skip the
`elpaa--write-archive-contents` (and associated
`elpaa--html-make-index`) in the overwhelmingly common case where
nothing was scrubbed.


        Stefan




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

* Re: Removing packages from archive-contents if removed from elpa-packages
  2022-11-02  2:02           ` Stefan Monnier
@ 2022-11-02  6:59             ` Philip Kaludercic
  0 siblings, 0 replies; 10+ messages in thread
From: Philip Kaludercic @ 2022-11-02  6:59 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

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

>> No, you are absolutely right, I just didn't see that.
>>
>> 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)))
>
> LGTM.  Feel free to push.  

Will do.

>                            Just one comment: we could skip the
> `elpaa--write-archive-contents` (and associated
> `elpaa--html-make-index`) in the overwhelmingly common case where
> nothing was scrubbed.

Good point.

>
>         Stefan



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

end of thread, other threads:[~2022-11-02  6:59 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2022-11-02  2:02           ` Stefan Monnier
2022-11-02  6:59             ` Philip Kaludercic

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).