aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/pack.lua
diff options
context:
space:
mode:
authorEvgeni Chasnovski <evgeni.chasnovski@gmail.com>2026-04-06 03:35:14 +0300
committerGitHub <noreply@github.com>2026-04-05 20:35:14 -0400
commit157c7bccb0b5a7132c0f4067f2cf575fd1bb152b (patch)
tree31d90345eb2797469ec51b0c41dd13134d694229 /runtime/lua/vim/pack.lua
parent13faa0ef847135b3c295560b6e5fdd83aff4b2a4 (diff)
downloadrneovim-157c7bccb0b5a7132c0f4067f2cf575fd1bb152b.tar.gz
rneovim-157c7bccb0b5a7132c0f4067f2cf575fd1bb152b.tar.bz2
rneovim-157c7bccb0b5a7132c0f4067f2cf575fd1bb152b.zip
fix(pack): avoid eager vim.version call #38705
Problem: Commands that rely on Git may need its version to perform more targeted actions (like decide which arguments are safe to use). For performance, computing this version is delayed up until it is needed (like to not compute on regular startup), but not done before every Git operation (as it is too much and can be done better). This requires storing the Git version in a variable which is currently initiated via `vim.version.parse()` call (most probably because it was easier to handle Lua types this way). However, the problem is that this results in sourcing `vim.version` and computing `vim.version.parse` on every startup even if no Git operation would be done. Solution: Don't call `vim.version.parse()` during `require('vim.pack')` and ensure its more precise lazy computation.
Diffstat (limited to 'runtime/lua/vim/pack.lua')
-rw-r--r--runtime/lua/vim/pack.lua7
1 files changed, 5 insertions, 2 deletions
diff --git a/runtime/lua/vim/pack.lua b/runtime/lua/vim/pack.lua
index 3a5545cd63..7a10e1707a 100644
--- a/runtime/lua/vim/pack.lua
+++ b/runtime/lua/vim/pack.lua
@@ -253,14 +253,15 @@ local function git_cmd(cmd, cwd)
return (stdout:gsub('\n+$', ''))
end
-local git_version = vim.version.parse('1')
+--- @type vim.Version
+local git_version
local function git_ensure_exec()
local ok, sys = pcall(vim.system, { 'git', 'version' })
if not ok then
error('No `git` executable')
end
- git_version = vim.version.parse(sys:wait().stdout)
+ git_version = vim.version.parse(sys:wait().stdout) --[[@as vim.Version]]
end
--- @async
@@ -915,6 +916,7 @@ local function lock_sync(confirm, specs)
table.sort(to_install, function(a, b)
return a.spec.name < b.spec.name
end)
+ git_ensure_exec()
install_list(to_install, confirm)
lock_write()
end
@@ -1466,6 +1468,7 @@ function M.get(names, opts)
end
if opts.info then
+ git_ensure_exec()
add_p_data_info(res)
end