refactor(git): centralise the git:// scheme behind util.uri / util.parse_uri

This commit is contained in:
2026-04-29 09:56:32 +02:00
parent 590651e9d8
commit 9d938b228b
4 changed files with 25 additions and 10 deletions
+6 -7
View File
@@ -152,8 +152,7 @@ local pending_content = {}
---@param content string?
---@return integer
function M.buf_for(worktree, revspec, content)
local name = "git://" .. revspec
local buf = vim.fn.bufadd(name)
local buf = vim.fn.bufadd(util.uri(revspec))
vim.b[buf].git_worktree = worktree
if content then
pending_content[buf] = content
@@ -170,7 +169,7 @@ end
---@param buf integer
function M.read_uri(buf)
local name = vim.api.nvim_buf_get_name(buf)
local revspec = name:match("^git://(.+)$")
local revspec = util.parse_uri(name)
if not revspec then
return
end
@@ -230,7 +229,7 @@ local function blob_buf(worktree, blob, path, ref)
local revspec = ref .. ":" .. path
if is_zero(blob) then
return diff.empty_buf({
name = "git://" .. revspec,
name = util.uri(revspec),
bufhidden = "hide",
})
end
@@ -311,7 +310,7 @@ end
function M.open_commit(worktree, ref, opts)
local split = opts and opts.split
local sha = repo.rev_parse(worktree, ref, true) or ref
local name = "git://" .. sha
local name = util.uri(sha)
local existing = vim.fn.bufnr(name)
if existing ~= -1 and vim.api.nvim_buf_is_loaded(existing) then
if split == false then
@@ -376,7 +375,7 @@ function M.open_object(worktree, ref, opts)
local commit_ref, path = ref:match("^(.-):(.+)$")
if commit_ref then
local sha = repo.rev_parse(worktree, commit_ref, true) or commit_ref
open_uri(worktree, "git://" .. sha .. ":" .. path, sha, opts)
open_uri(worktree, util.uri(sha .. ":" .. path), sha, opts)
return
end
@@ -398,7 +397,7 @@ function M.open_object(worktree, ref, opts)
-- `filetype.add` pattern doesn't match; default to `git` so
-- tree / tag header lines syntax-highlight.
local sha = repo.rev_parse(worktree, ref, true) or ref
open_uri(worktree, "git://" .. sha, sha, opts, "git")
open_uri(worktree, util.uri(sha), sha, opts, "git")
end
---@return boolean dispatched true if the cursor was on an actionable line