mirror of
https://github.com/folke/lazy.nvim.git
synced 2025-06-29 11:54:15 +00:00
Merge remote-tracking branch 'upstream/main' into feat/prioritize-cond
This commit is contained in:
commit
7e39270651
27 changed files with 1212 additions and 905 deletions
|
@ -13,7 +13,14 @@ M.reported = {}
|
|||
|
||||
function M.start()
|
||||
M.fast_check()
|
||||
M.schedule()
|
||||
if M.schedule() > 0 and not M.has_errors() then
|
||||
Manage.log({
|
||||
clear = false,
|
||||
show = false,
|
||||
check = true,
|
||||
concurrency = Config.options.checker.concurrency,
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
function M.schedule()
|
||||
|
@ -21,6 +28,7 @@ function M.schedule()
|
|||
local next_check = State.checker.last_check + Config.options.checker.frequency - os.time()
|
||||
next_check = math.max(next_check, 0)
|
||||
vim.defer_fn(M.check, next_check * 1000)
|
||||
return next_check
|
||||
end
|
||||
|
||||
---@param opts? {report:boolean} report defaults to true
|
||||
|
@ -39,20 +47,23 @@ function M.fast_check(opts)
|
|||
M.report(opts.report ~= false)
|
||||
end
|
||||
|
||||
function M.has_errors()
|
||||
for _, plugin in pairs(Config.plugins) do
|
||||
if Plugin.has_errors(plugin) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function M.check()
|
||||
State.checker.last_check = os.time()
|
||||
State.write() -- update state
|
||||
local errors = false
|
||||
for _, plugin in pairs(Config.plugins) do
|
||||
if Plugin.has_errors(plugin) then
|
||||
errors = true
|
||||
break
|
||||
end
|
||||
end
|
||||
if errors then
|
||||
if M.has_errors() then
|
||||
M.schedule()
|
||||
else
|
||||
Manage.check({
|
||||
clear = false,
|
||||
show = false,
|
||||
concurrency = Config.options.checker.concurrency,
|
||||
}):wait(function()
|
||||
|
|
|
@ -136,13 +136,13 @@ function M.check(opts)
|
|||
}, opts)
|
||||
end
|
||||
|
||||
---@param opts? ManagerOpts
|
||||
---@param opts? ManagerOpts | {check?:boolean}
|
||||
function M.log(opts)
|
||||
opts = M.opts(opts, { mode = "log" })
|
||||
return M.run({
|
||||
pipeline = {
|
||||
{ "git.origin", check = true },
|
||||
"git.log",
|
||||
{ "git.log", check = opts.check },
|
||||
},
|
||||
plugins = function(plugin)
|
||||
return plugin.url and plugin._.installed
|
||||
|
@ -174,7 +174,10 @@ function M.sync(opts)
|
|||
end)
|
||||
opts.show = false
|
||||
end
|
||||
local clean = M.clean(opts)
|
||||
|
||||
local clean_opts = vim.deepcopy(opts)
|
||||
clean_opts.plugins = nil
|
||||
local clean = M.clean(clean_opts)
|
||||
local install = M.install(opts)
|
||||
local update = M.update(opts)
|
||||
clean:wait(function()
|
||||
|
|
|
@ -2,7 +2,7 @@ local Config = require("lazy.core.config")
|
|||
|
||||
local M = {}
|
||||
|
||||
---@type table<vim.loop.Process, true>
|
||||
---@type table<uv.uv_process_t, true>
|
||||
M.running = {}
|
||||
|
||||
M.signals = {
|
||||
|
@ -49,7 +49,7 @@ local uv = vim.loop
|
|||
---@field on_line? fun(string)
|
||||
---@field on_exit? fun(ok:boolean, output:string)
|
||||
---@field timeout? number
|
||||
---@field env? string[]
|
||||
---@field env? table<string,string>
|
||||
|
||||
---@param opts? ProcessOpts
|
||||
---@param cmd string
|
||||
|
@ -57,31 +57,31 @@ function M.spawn(cmd, opts)
|
|||
opts = opts or {}
|
||||
opts.timeout = opts.timeout or (Config.options.git and Config.options.git.timeout * 1000)
|
||||
|
||||
local env = {
|
||||
"GIT_TERMINAL_PROMPT=0",
|
||||
"GIT_SSH_COMMAND=ssh -oBatchMode=yes",
|
||||
}
|
||||
if opts.env then
|
||||
vim.list_extend(env, opts.env)
|
||||
---@type table<string, string>
|
||||
local env = vim.tbl_extend("force", {
|
||||
GIT_SSH_COMMAND = "ssh -oBatchMode=yes",
|
||||
}, uv.os_environ(), opts.env or {})
|
||||
env.GIT_DIR = nil
|
||||
env.GIT_TERMINAL_PROMPT = "0"
|
||||
|
||||
---@type string[]
|
||||
local env_flat = {}
|
||||
for k, v in pairs(env) do
|
||||
env_flat[#env_flat + 1] = k .. "=" .. v
|
||||
end
|
||||
|
||||
for key, value in
|
||||
pairs(uv.os_environ() --[[@as string[] ]])
|
||||
do
|
||||
table.insert(env, key .. "=" .. value)
|
||||
end
|
||||
|
||||
local stdout = uv.new_pipe()
|
||||
local stderr = uv.new_pipe()
|
||||
local stdout = assert(uv.new_pipe())
|
||||
local stderr = assert(uv.new_pipe())
|
||||
|
||||
local output = ""
|
||||
---@type vim.loop.Process
|
||||
---@type uv.uv_process_t
|
||||
local handle = nil
|
||||
|
||||
---@type uv.uv_timer_t
|
||||
local timeout
|
||||
local killed = false
|
||||
if opts.timeout then
|
||||
timeout = uv.new_timer()
|
||||
timeout = assert(uv.new_timer())
|
||||
timeout:start(opts.timeout, 0, function()
|
||||
if M.kill(handle) then
|
||||
killed = true
|
||||
|
@ -93,7 +93,7 @@ function M.spawn(cmd, opts)
|
|||
stdio = { nil, stdout, stderr },
|
||||
args = opts.args,
|
||||
cwd = opts.cwd,
|
||||
env = env,
|
||||
env = env_flat,
|
||||
}, function(exit_code, signal)
|
||||
M.running[handle] = nil
|
||||
if timeout then
|
||||
|
@ -103,7 +103,7 @@ function M.spawn(cmd, opts)
|
|||
handle:close()
|
||||
stdout:close()
|
||||
stderr:close()
|
||||
local check = uv.new_check()
|
||||
local check = assert(uv.new_check())
|
||||
check:start(function()
|
||||
if not stdout:is_closing() or not stderr:is_closing() then
|
||||
return
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
local Cache = require("lazy.core.cache")
|
||||
local Config = require("lazy.core.config")
|
||||
local Util = require("lazy.util")
|
||||
local Plugin = require("lazy.core.plugin")
|
||||
|
@ -6,12 +5,11 @@ local Loader = require("lazy.core.loader")
|
|||
|
||||
local M = {}
|
||||
|
||||
---@type table<string, CacheHash>
|
||||
---@type table<string, vim.loop.Stat>
|
||||
M.files = {}
|
||||
|
||||
---@type vim.loop.Timer
|
||||
M.timer = nil
|
||||
M.root = nil
|
||||
|
||||
function M.enable()
|
||||
if M.timer then
|
||||
|
@ -19,7 +17,6 @@ function M.enable()
|
|||
end
|
||||
if #Config.spec.modules > 0 then
|
||||
M.timer = vim.loop.new_timer()
|
||||
M.root = vim.fn.stdpath("config") .. "/lua"
|
||||
M.check(true)
|
||||
M.timer:start(2000, 2000, M.check)
|
||||
end
|
||||
|
@ -32,6 +29,12 @@ function M.disable()
|
|||
end
|
||||
end
|
||||
|
||||
---@param h1 vim.loop.Stat
|
||||
---@param h2 vim.loop.Stat
|
||||
function M.eq(h1, h2)
|
||||
return h1 and h2 and h1.size == h2.size and h1.mtime.sec == h2.mtime.sec and h1.mtime.nsec == h2.mtime.nsec
|
||||
end
|
||||
|
||||
function M.check(start)
|
||||
---@type table<string,true>
|
||||
local checked = {}
|
||||
|
@ -41,10 +44,10 @@ function M.check(start)
|
|||
-- spec is a module
|
||||
local function check(_, modpath)
|
||||
checked[modpath] = true
|
||||
local hash = Cache.hash(modpath)
|
||||
local hash = vim.loop.fs_stat(modpath)
|
||||
if hash then
|
||||
if M.files[modpath] then
|
||||
if not Cache.eq(M.files[modpath], hash) then
|
||||
if not M.eq(M.files[modpath], hash) then
|
||||
M.files[modpath] = hash
|
||||
table.insert(changes, { file = modpath, what = "changed" })
|
||||
end
|
||||
|
|
|
@ -15,7 +15,7 @@ M.log = {
|
|||
return true
|
||||
end
|
||||
local stat = vim.loop.fs_stat(plugin.dir .. "/.git")
|
||||
return stat and stat.type ~= "directory"
|
||||
return not (stat and stat.type == "directory")
|
||||
end,
|
||||
---@param opts {args?: string[], updated?:boolean, check?:boolean}
|
||||
run = function(self, opts)
|
||||
|
@ -64,11 +64,18 @@ M.clone = {
|
|||
local args = {
|
||||
"clone",
|
||||
self.plugin.url,
|
||||
"--filter=blob:none",
|
||||
"--recurse-submodules",
|
||||
"--progress",
|
||||
}
|
||||
|
||||
if Config.options.git.filter then
|
||||
args[#args + 1] = "--filter=blob:none"
|
||||
end
|
||||
|
||||
if self.plugin.submodules ~= false then
|
||||
args[#args + 1] = "--recurse-submodules"
|
||||
end
|
||||
|
||||
args[#args + 1] = "--progress"
|
||||
|
||||
if self.plugin.branch then
|
||||
vim.list_extend(args, { "-b", self.plugin.branch })
|
||||
end
|
||||
|
@ -152,6 +159,10 @@ M.fetch = {
|
|||
"--progress",
|
||||
}
|
||||
|
||||
if self.plugin.submodules == false then
|
||||
table.remove(args, 2)
|
||||
end
|
||||
|
||||
self:spawn("git", {
|
||||
args = args,
|
||||
cwd = self.plugin.dir,
|
||||
|
@ -203,6 +214,10 @@ M.checkout = {
|
|||
"--recurse-submodules",
|
||||
}
|
||||
|
||||
if self.plugin.submodules == false then
|
||||
table.remove(args, 3)
|
||||
end
|
||||
|
||||
if lock then
|
||||
table.insert(args, lock.commit)
|
||||
elseif target.tag then
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue