radian-software / straight.el

šŸ€ Next-generation, purely functional package manager for the Emacs hacker.
MIT License
2.75k stars 151 forks source link

straight-freeze-versions tries to clone MELPA #161

Open diamond-lizard opened 7 years ago

diamond-lizard commented 7 years ago

With the only straight-related code in my emacs init file being the bootstrap code from this comment and the only repo in ~/.emacs/straight/repos being straight.el itself, when I run M-x straight-freeze-versions what I expect to happen is for straight.el to simply create one single lockfile for itself. Instead what happens is it started to clone MELPA (which attempt I immediately aborted).

I don't even use MELPA, and I don't understand why straight.el would try to clone it without an explicit request from me (or at least permission to do so), especially as it seems completely unrelated to the simple act of creating a single lockfile for straight.el itself.

raxod502 commented 7 years ago

Ah! Good catch. The reason this is happening is that recipe repositories are treated, internally, just like packages. The default recipe repositories are registered in bootstrap.el:

(straight-use-recipes '(melpa :type git :host github
                              :repo "melpa/melpa"
                              :no-build t))

(straight-use-recipes '(emacsmirror :type git :host github
                                    :repo "emacsmirror/epkgs"
                                    :nonrecursive t
                                    :no-build t))

and as you can see, the definition of straight-use-recipes just delegates to a straight-use-package call:

(defun straight-use-recipes (melpa-style-recipe)
  "Register a recipe repository using MELPA-STYLE-RECIPE.
This registers the recipe and builds it if it is already cloned.
Note that you probably want the recipe for a recipe repository to
include a non-nil `:no-build' property, to unconditionally
inhibit the build phase.

This function also adds the recipe repository to
`straight-recipe-repositories', at the end of the list."
  (straight-use-package-lazy melpa-style-recipe)
  (add-to-list 'straight-recipe-repositories
               (if (listp melpa-style-recipe)
                   (car melpa-style-recipe)
                 melpa-style-recipe)
               'append))

So then when it comes time to use straight-freeze-versions, straight.el inspects all packages which were loaded by the current Emacs session (subject to considerations about the transaction system), determines their local repositories, and tries to save the revisions of those repositories to the lockfiles. However, before it can do that, it attempts to clone any that are missing. This causes MELPA to be unnecessarily cloned, as you observed. It also interferes with deferred installation, see #24. This will be fixed.

The best route would probably be to add yet another cache variable (or stick more data into an existing one) about which recipe repositories were actually used for recipe lookup, and skip those that were not during lockfile generation. Unfortunately, this is slightly nontrivial so I will not have time to implement the fix myself for a little while.

As a workaround, you could let MELPA and EmacsMirror be cloned. This will only happen once. I believe anything better would require changes upstream to straight.el. (You could always fork it and comment out the straight-use-recipes calls, as the bootstrap routine has explicit support for that use caseā€¦ but maybe not the most elegant solution.)