refactor(git): rework log_view, drop URI scheme

This commit is contained in:
2026-05-19 19:40:11 +02:00
parent ffd5584a05
commit b692f23fe2
5 changed files with 23 additions and 71 deletions
+17 -58
View File
@@ -3,8 +3,6 @@ local util = require("git.core.util")
local M = {}
M.URI_PREFIX = "gitlog://"
local LOG_FORMAT = "%h %ad {%an}%d %s"
local cr = vim.api.nvim_replace_termcodes("<CR>", true, false, true)
@@ -56,50 +54,7 @@ local function populate(buf, r)
if not stdout then
return
end
local new_lines = util.split_lines(stdout)
local old_str = table.concat(
vim.api.nvim_buf_get_lines(buf, 0, -1, false),
"\n"
) .. "\n"
local new_str = table.concat(new_lines, "\n") .. "\n"
local hunks = vim.text.diff(old_str, new_str, {
result_type = "indices",
algorithm = "histogram",
})
---@cast hunks [integer, integer, integer, integer][]
if #hunks == 0 then
return
end
for i = #hunks, 1, -1 do
local sa, ca, sb, cb = unpack(hunks[i])
local start = ca == 0 and sa or sa - 1
util.set_buf_lines(
buf,
start,
start + ca,
vim.list_slice(new_lines, sb, sb + cb - 1)
)
end
end
---@param buf integer
function M.read_uri(buf)
local name = vim.api.nvim_buf_get_name(buf)
local worktree = name:sub(#M.URI_PREFIX + 1)
if worktree == "" then
return
end
local r = repo.resolve(worktree)
if not r then
return
end
repo.bind(buf, r)
util.setup_scratch(buf, { bufhidden = "hide" })
vim.bo[buf].filetype = "gitlog"
attach_dispatch(buf)
populate(buf, r)
util.set_buf_lines(buf, 0, -1, util.split_lines(stdout))
end
---@class ow.Git.Log.OpenOpts
@@ -120,19 +75,25 @@ function M.open(opts)
end
max_counts[r.worktree] = opts.max_count
local buf = vim.fn.bufadd(M.URI_PREFIX .. r.worktree)
local was_loaded = vim.api.nvim_buf_is_loaded(buf)
local buf = vim.fn.bufadd(r.worktree .. "/GitLog")
local win = vim.fn.bufwinid(buf)
if win == -1 then
util.place_buf(buf, nil)
else
vim.api.nvim_set_current_win(win)
end
if was_loaded then
local visible = vim.fn.bufwinid(buf)
if visible ~= -1 then
vim.api.nvim_set_current_win(visible)
populate(buf, r)
vim.api.nvim_win_set_cursor(visible, { 1, 0 })
return
end
vim.fn.bufload(buf)
repo.bind(buf, r)
util.setup_scratch(buf, { bufhidden = "hide" })
vim.bo[buf].filetype = "gitlog"
attach_dispatch(buf)
local win = util.place_buf(buf, nil)
vim.api.nvim_win_set_cursor(win, { 1, 0 })
populate(buf, r)
end
---@param cmd_opts table
@@ -170,6 +131,4 @@ function M.complete_glog(arg_lead)
return matches
end
repo.on_uri_change(M.URI_PREFIX, populate)
return M
+1 -1
View File
@@ -17,7 +17,7 @@ local WINDOW_WIDTH = 50
---@param r ow.Git.Repo
---@return string
local function buf_name_for(r)
return r.worktree .. "/Git Status"
return r.worktree .. "/GitStatus"
end
---@alias ow.Git.StatusView.Placement "sidebar"|"split"|"current"