refactor(git): split URI read from conditional refresh

This commit is contained in:
2026-05-06 04:46:01 +02:00
parent abb5434893
commit abc09d4ae3
5 changed files with 70 additions and 69 deletions
+6 -18
View File
@@ -81,17 +81,13 @@ local function uri_split(opts, buf, rev)
local object = require("git.object")
if opts.rev and opts.rev:find(":", 1, true) then
local content = util.exec(
{ "git", "cat-file", "-p", opts.rev },
{ cwd = r.worktree, silent = true }
)
if not content then
if not r:rev_parse(opts.rev, true) then
util.error("invalid rev: %s", opts.rev)
return
end
place_pair(
buf,
object.buf_for(r, Revision.parse(opts.rev), content),
object.buf_for(r, Revision.parse(opts.rev)),
false,
opts.vertical
)
@@ -123,15 +119,11 @@ local function uri_split(opts, buf, rev)
local m = mapping[rev.stage]
or { Revision.new({ stage = 0, path = rev.path }), true }
local other_rev, left = m[1], m[2]
local content = util.exec(
{ "git", "cat-file", "-p", other_rev:format() },
{ cwd = r.worktree, silent = true }
)
if not content then
if not r:rev_parse(other_rev:format(), true) then
util.error("invalid rev: %s", other_rev:format())
return
end
place_pair(buf, object.buf_for(r, other_rev, content), left, opts.vertical)
place_pair(buf, object.buf_for(r, other_rev), left, opts.vertical)
end
---@class ow.Git.Diff.SplitOpts
@@ -172,15 +164,11 @@ function M.split(opts)
else
rev = Revision.new({ base = opts.rev, path = rel })
end
local content = util.exec(
{ "git", "cat-file", "-p", rev:format() },
{ cwd = r.worktree, silent = true }
)
if not content then
if not r:rev_parse(rev:format(), true) then
util.error("invalid rev: %s", rev:format())
return
end
local buf = require("git.object").buf_for(r, rev, content)
local buf = require("git.object").buf_for(r, rev)
place_pair(buf, cur_buf, true, opts.vertical)
end