perf(git): cache index blob sha, drop rev-parse from the edit path
This commit is contained in:
+23
-5
@@ -123,6 +123,16 @@ local function affects_resolve(relpath)
|
||||
or relpath == "FETCH_HEAD"
|
||||
end
|
||||
|
||||
---@private
|
||||
---@param prefix string
|
||||
function Repo:_clear_cache_prefix(prefix)
|
||||
for key in pairs(self._cache) do
|
||||
if vim.startswith(key, prefix) then
|
||||
self._cache[key] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
---@private
|
||||
---@param relpath string
|
||||
function Repo:_invalidate(relpath)
|
||||
@@ -132,11 +142,10 @@ function Repo:_invalidate(relpath)
|
||||
end
|
||||
end
|
||||
if affects_resolve(relpath) then
|
||||
for key in pairs(self._cache) do
|
||||
if vim.startswith(key, "resolve:") then
|
||||
self._cache[key] = nil
|
||||
end
|
||||
end
|
||||
self:_clear_cache_prefix("resolve:")
|
||||
end
|
||||
if relpath == "index" then
|
||||
self:_clear_cache_prefix("index:")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -587,6 +596,15 @@ function Repo:rev_parse(rev, short)
|
||||
return trimmed ~= "" and trimmed or nil
|
||||
end
|
||||
|
||||
---@param rel string worktree-relative path
|
||||
---@return string?
|
||||
function Repo:index_sha(rel)
|
||||
local sha = self:get_cached("index:" .. rel, function(self)
|
||||
return self:rev_parse(":" .. rel, false) or false
|
||||
end)
|
||||
return sha or nil
|
||||
end
|
||||
|
||||
---@alias ow.Git.Repo.ResolveStatus "ok"|"ambiguous"|"missing"
|
||||
|
||||
---@param abbrev string
|
||||
|
||||
Reference in New Issue
Block a user