perf(git): cache index blob sha, drop rev-parse from the edit path
This commit is contained in:
@@ -71,6 +71,32 @@ t.test("get_cached memoizes by key", function()
|
||||
t.truthy(v1 == v2, "second call should return cached table")
|
||||
end)
|
||||
|
||||
t.test("index_sha returns the blob sha and caches it", function()
|
||||
local dir = h.make_repo({ a = "x\n" })
|
||||
local r = assert(require("git.core.repo").resolve(dir))
|
||||
local sha = r:index_sha("a")
|
||||
t.truthy(sha and #sha > 0, "index_sha returns the stage-0 blob sha")
|
||||
t.truthy(r._cache["index:a"] ~= nil, "the result is cached")
|
||||
t.eq(r:index_sha("a"), sha, "a cached call returns the same sha")
|
||||
end)
|
||||
|
||||
t.test("index_sha caches a negative result for an untracked path", function()
|
||||
local dir = h.make_repo({ a = "x\n" })
|
||||
local r = assert(require("git.core.repo").resolve(dir))
|
||||
t.eq(r:index_sha("nope"), nil, "an untracked path has no index sha")
|
||||
t.eq(r._cache["index:nope"], false, "the negative result is cached")
|
||||
end)
|
||||
|
||||
t.test("index_sha cache clears when the index is written", function()
|
||||
local dir = h.make_repo({ a = "x\n" })
|
||||
local r = assert(require("git.core.repo").resolve(dir))
|
||||
r:index_sha("a")
|
||||
t.truthy(r._cache["index:a"] ~= nil, "sha is cached before the stage")
|
||||
t.write(dir, "a", "y\n")
|
||||
h.git(dir, "add", "a")
|
||||
wait_cleared(r, "index:a", 2000)
|
||||
end)
|
||||
|
||||
t.test("cache clears after top-level .git change (commit)", function()
|
||||
local dir = h.make_repo({ a = "x" })
|
||||
local r = assert(require("git.core.repo").resolve(dir))
|
||||
|
||||
Reference in New Issue
Block a user