neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

commit ed73ed82837455ad5dae6d6917a20c3679016343
parent 8200223ee7a8dd9882367582c4a6e1d280012fff
Author: Evgeni Chasnovski <evgeni.chasnovski@gmail.com>
Date:   Sat,  2 Aug 2025 14:58:03 +0300

fix(pack): ensure explicit default `version` in events (where possible)

Problem: Both `PackChangedPre` and `PackChanged` contain |event-data|
  with plugin's `spec`. It looks like a good idea to have all its
  triggers contain the same format across all kinds ("install",
  "update", "delete"). There are several choices:
    - Have it be as verbatim as supplied to `vim.pack.add()`, i.e. can
      be either string or table. A bit too ambiguous.
    - Have it be table with `src` and `name` inferred. This requires
      less work for "install", but more work for "update" and "delete"
      (since they use `vim.pack.get()` which already infers default
      `version`).
    - Have it be table with *all* defaults made explicit. This looks
      like the best approach, but requires extra care to only infer
      default `version` when needed (i.e. avoid inferring during regular
      load) because it is costly in terms of startup time.
      This might also introduce inconsistency when dealing with
      lockfile(s) as information there should be as close to what user
      supplied as possible. Address that when dealing with lockfile.

Solution: Ensure explicit `version` in all events where possible.

Diffstat:
Mruntime/doc/pack.txt | 2+-
Mruntime/lua/vim/pack.lua | 5++++-
2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/runtime/doc/pack.txt b/runtime/doc/pack.txt @@ -291,7 +291,7 @@ Available events to hook into ~ Each event populates the following |event-data| fields: • `kind` - one of "install" (install on disk), "update" (update existing plugin), "delete" (delete from disk). -• `spec` - plugin's specification. +• `spec` - plugin's specification with defaults made explicit. • `path` - full path to plugin's directory. diff --git a/runtime/lua/vim/pack.lua b/runtime/lua/vim/pack.lua @@ -88,7 +88,7 @@ --- Each event populates the following |event-data| fields: --- - `kind` - one of "install" (install on disk), "update" (update existing --- plugin), "delete" (delete from disk). ---- - `spec` - plugin's specification. +--- - `spec` - plugin's specification with defaults made explicit. --- - `path` - full path to plugin's directory. local api = vim.api @@ -569,6 +569,9 @@ local function install_list(plug_list) git_clone(p.spec.src, p.path) p.info.installed = true + -- Infer default branch for fuller `event-data` + p.spec.version = p.spec.version or git_get_default_branch(p.path) + -- Do not skip checkout even if HEAD and target have same commit hash to -- have new repo in expected detached HEAD state and generated help files. checkout(p, timestamp, false)