tweak(cli): download package archives by default

From this point on, Straight will download packages from tarballs (if
possible) from their associated forge rather than clone them as git
repositories. This is (marginally) faster and consumes significantly
less space. Doom treats its packages as build artifacts anyway.

This shouldn't cause any immediate breakage, but it may upset folks who
want their local package installs to be repositories. For them, this can
be reversed by simply adding this to $DOOMDIR/init.el:

  (after! doom-straight
    (setq straight-vc-use-snapshot-installation nil))

This only applies to packages installed after this point. Packages that
are already cloned as a repo will stay that way until the next time
they're uninstalled or reinstalled from scratch. Plus it only works on
systems that have `tar` in their $PATH *and* forges that are
supported (at the time of writing: github, gitlab, codeberg, bitbucket,
and sourcehut).

Ref: radian-software/straight.el@4241b63952
This commit is contained in:
Henrik Lissner
2025-08-30 13:40:06 +02:00
parent 4b9f237250
commit 8cdddd87d9
3 changed files with 48 additions and 41 deletions

View File

@@ -84,28 +84,29 @@
(print! (item "No ELN directories to purge"))
0))
(cl-defun doom-gc--regraft-repo (repo)
(defun doom-gc--regraft-repo (repo)
(unless repo
(error "No repo specified for regrafting"))
(let ((default-directory (straight--repos-dir repo)))
(unless (file-directory-p ".git")
(print! (warn "\rrepos/%s is not a git repo, skipping" repo))
(cl-return))
(unless (file-in-directory-p default-directory straight-base-dir)
(print! (warn "\rSkipping repos/%s because it is local" repo))
(cl-return))
(let ((before-size (doom-directory-size default-directory)))
(doom-call-process "git" "reset" "--hard")
(doom-call-process "git" "clean" "-ffd")
(if (not (zerop (car (doom-call-process "git" "replace" "--graft" "HEAD"))))
(print! (item "\rrepos/%s is already compact\033[1A" repo))
(doom-call-process "git" "reflog" "expire" "--expire=all" "--all")
(doom-call-process "git" "gc" "--prune=now")
(let ((after-size (doom-directory-size default-directory)))
(if (equal after-size before-size)
(print! (success "\rrepos/%s cannot be compacted further" repo))
(print! (success "\rRegrafted repos/%s (from %0.1fKB to %0.1fKB)")
repo before-size after-size)))))
(catch 'skip
(unless (file-directory-p ".git")
(print! (warn "\rrepos/%s is not a git repo, skipping" repo))
(throw 'skip t))
(unless (file-in-directory-p default-directory straight-base-dir)
(print! (warn "\rSkipping repos/%s because it is local" repo))
(throw 'skip t))
(let ((before-size (doom-directory-size default-directory)))
(doom-call-process "git" "reset" "--hard")
(doom-call-process "git" "clean" "-ffd")
(if (not (zerop (car (doom-call-process "git" "replace" "--graft" "HEAD"))))
(print! (item "\rrepos/%s is already compact\033[1A" repo))
(doom-call-process "git" "reflog" "expire" "--expire=all" "--all")
(doom-call-process "git" "gc" "--prune=now")
(let ((after-size (doom-directory-size default-directory)))
(if (equal after-size before-size)
(print! (success "\rrepos/%s cannot be compacted further" repo))
(print! (success "\rRegrafted repos/%s (from %0.1fKB to %0.1fKB)")
repo before-size after-size))))))
t))
(defun doom-gc--regraft-repos (repos)

View File

@@ -55,7 +55,10 @@
;; no affect on packages that are pinned, however (run 'doom sync --gc' to
;; compact those after-the-fact). Some packages break when shallow cloned
;; (like magit and org), but we'll deal with that elsewhere.
straight-vc-git-default-clone-depth '(1 single-branch))
straight-vc-git-default-clone-depth '(1 single-branch)
;; Install archives from forges instead of cloning them. Much faster and
;; lighter.
straight-vc-use-snapshot-installation (and (executable-find "tar") t))
(with-eval-after-load 'straight
;; HACK: Doom relies on deferred compilation, which spares the user 20-50min

View File

@@ -1011,7 +1011,8 @@ Must be run from a magit diff buffer."
;; indicates a successful clone (causing load
;; errors later).
(let ((try 0))
(while (not (file-directory-p (doom-path repo-dir ".git")))
(while (not (or (file-directory-p ".git")
(file-exists-p ".straight-commit")))
(when (= try 3)
(error "Failed to clone package"))
(print! (warn "Failed to clone %S, trying again (attempt #%d)...") package (1+ try))
@@ -1077,7 +1078,8 @@ Must be run from a magit diff buffer."
(print! (warn "(%d/%d) Skipping %s because it is out-of-tree...") i total package)
(cl-return))
(when (eq type 'git)
(unless (file-exists-p ".git")
(unless (or (file-directory-p ".git")
(file-exists-p ".straight-commit"))
(error "%S is not a valid repository" package)))
(when (and pinned-only-p (not (assoc local-repo pinned)))
(cl-return))
@@ -1205,28 +1207,29 @@ Must be run from a magit diff buffer."
(length
(delq nil (mapcar #'doom-packages--purge-build builds))))))
(cl-defun doom-packages--regraft-repo (repo)
(defun doom-packages--regraft-repo (repo)
(unless repo
(error "No repo specified for regrafting"))
(let ((default-directory (straight--repos-dir repo)))
(unless (file-directory-p ".git")
(print! (warn "\rrepos/%s is not a git repo, skipping" repo))
(cl-return))
(unless (file-in-directory-p default-directory straight-base-dir)
(print! (warn "\rSkipping repos/%s because it is local" repo))
(cl-return))
(let ((before-size (doom-directory-size default-directory)))
(doom-call-process "git" "reset" "--hard")
(doom-call-process "git" "clean" "-ffd")
(if (not (zerop (car (doom-call-process "git" "replace" "--graft" "HEAD"))))
(print! (item "\rrepos/%s is already compact\033[1A" repo))
(doom-call-process "git" "reflog" "expire" "--expire=all" "--all")
(doom-call-process "git" "gc" "--prune=now")
(let ((after-size (doom-directory-size default-directory)))
(if (equal after-size before-size)
(print! (success "\rrepos/%s cannot be compacted further" repo))
(print! (success "\rRegrafted repos/%s (from %0.1fKB to %0.1fKB)")
repo before-size after-size)))))
(catch 'skip
(unless (file-directory-p ".git")
(print! (warn "\rrepos/%s is not a git repo, skipping" repo))
(throw 'skip t))
(unless (file-in-directory-p default-directory straight-base-dir)
(print! (warn "\rSkipping repos/%s because it is local" repo))
(throw 'skip t))
(let ((before-size (doom-directory-size default-directory)))
(doom-call-process "git" "reset" "--hard")
(doom-call-process "git" "clean" "-ffd")
(if (not (zerop (car (doom-call-process "git" "replace" "--graft" "HEAD"))))
(print! (item "\rrepos/%s is already compact\033[1A" repo))
(doom-call-process "git" "reflog" "expire" "--expire=all" "--all")
(doom-call-process "git" "gc" "--prune=now")
(let ((after-size (doom-directory-size default-directory)))
(if (equal after-size before-size)
(print! (success "\rrepos/%s cannot be compacted further" repo))
(print! (success "\rRegrafted repos/%s (from %0.1fKB to %0.1fKB)")
repo before-size after-size))))))
t))
(defun doom-packages--regraft-repos (repos)