doom/purge: refactor & optimize

Reduce how much work it had to do.
This commit is contained in:
Henrik Lissner 2020-05-25 15:53:09 -04:00
parent 944d7ec83f
commit 0bc3f8ea87
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -404,31 +404,31 @@ If ELPA-P, include packages installed with package.el (M-x package-install)."
(doom--barf-if-incomplete-packages)
(print! (start "Purging orphaned packages (for the emperor)..."))
(cl-destructuring-bind (&optional builds-to-purge repos-to-purge repos-to-regraft)
(let ((rdirs (straight--directory-files (straight--repos-dir) nil nil 'sort))
(bdirs (straight--directory-files (straight--build-dir) nil nil 'sort)))
(list (seq-remove (doom-rpartial #'gethash straight--profile-cache)
bdirs)
(seq-remove (doom-rpartial #'straight--checkhash straight--repo-cache)
rdirs)
(seq-filter (doom-rpartial #'straight--checkhash straight--repo-cache)
rdirs)))
(let (success)
(print-group!
(if (not builds-p)
(print! (info "Skipping builds"))
(and (/= 0 (doom--cli-packages-purge-builds builds-to-purge))
(setq success t)
(straight-prune-build-cache)))
(if (not elpa-p)
(print! (info "Skipping elpa packages"))
(and (/= 0 (doom--cli-packages-purge-elpa))
(setq success t)))
(if (not repos-p)
(print! (info "Skipping repos"))
(and (/= 0 (doom--cli-packages-purge-repos repos-to-purge))
(setq success t)))
(if (not regraft-repos-p)
(print! (info "Skipping regrafting"))
(and (doom--cli-packages-regraft-repos repos-to-regraft)
(setq success t)))
success))))
(let ((rdirs
(and (or repos-p regraft-repos-p)
(straight--directory-files (straight--repos-dir) nil nil 'sort))))
(list (when builds-p
(seq-remove (doom-rpartial #'gethash straight--profile-cache)
(straight--directory-files (straight--build-dir) nil nil 'sort)))
(when repos-p
(seq-remove (doom-rpartial #'straight--checkhash straight--repo-cache)
rdirs))
(when regraft-repos-p
(seq-filter (doom-rpartial #'straight--checkhash straight--repo-cache)
rdirs))))
(print-group!
(delq
nil (list
(if (not builds-p)
(ignore (print! (info "Skipping builds")))
(and (/= 0 (doom--cli-packages-purge-builds builds-to-purge))
(straight-prune-build-cache)))
(if (not elpa-p)
(ignore (print! (info "Skipping elpa packages")))
(/= 0 (doom--cli-packages-purge-elpa)))
(if (not repos-p)
(ignore (print! (info "Skipping repos")))
(/= 0 (doom--cli-packages-purge-repos repos-to-purge)))
(if (not regraft-repos-p)
(ignore (print! (info "Skipping regrafting")))
(doom--cli-packages-regraft-repos repos-to-regraft)))))))