feat(git/repo): add Repo:head_sha for cached HEAD blob lookups

This commit is contained in:
2026-05-20 12:45:56 +02:00
parent 6230c2663c
commit 7c92b5eff6
2 changed files with 29 additions and 0 deletions
+10
View File
@@ -143,6 +143,7 @@ function Repo:_invalidate(relpath)
end
if affects_resolve(relpath) then
self:_clear_cache_prefix("resolve:")
self:_clear_cache_prefix("head_blob:")
end
if relpath == "index" then
self:_clear_cache_prefix("index:")
@@ -605,6 +606,15 @@ function Repo:index_sha(rel)
return sha or nil
end
---@param rel string worktree-relative path
---@return string?
function Repo:head_sha(rel)
local sha = self:get_cached("head_blob:" .. rel, function(self)
return self:rev_parse("HEAD:" .. rel, false) or false
end)
return sha or nil
end
---@alias ow.Git.Repo.ResolveStatus "ok"|"ambiguous"|"missing"
---@param abbrev string