mirror of
https://github.com/zoriya/jj.nvim.git
synced 2026-08-05 18:56:13 +00:00
Feat: Rewrite diff module to allow for external dependencies as jj.nvim's diff tool (#74)
- Refactor diff into modular architecture (native, diffview, codediff) - Add the possibility for users to define their own diff backend - Support external diff tools like diffview.nvim codediff.nvim - Enable visual mode selection to diff two changes in log buffer - Add summary tooltip integration with terminal - Update documentation with new diff workflows
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
local utils = require("jj.utils")
|
||||
|
||||
---@type jj.diff
|
||||
local diff = require("jj.diff")
|
||||
|
||||
--- Givewn two changes, show their diff using codediff
|
||||
--- @param left string
|
||||
--- @param right string
|
||||
local function diff_two_changes(left, right)
|
||||
local commit_id_left = utils.get_commit_id(left)
|
||||
if commit_id_left == nil then
|
||||
return
|
||||
end
|
||||
|
||||
local commit_id_right = utils.get_commit_id(right)
|
||||
if commit_id_right == nil then
|
||||
return
|
||||
end
|
||||
|
||||
vim.cmd(string.format("CodeDiff %s %s", commit_id_right, commit_id_left))
|
||||
end
|
||||
|
||||
-----------------------------------------------------------------------
|
||||
-- Codediff Backend
|
||||
-----------------------------------------------------------------------
|
||||
|
||||
diff.register_backend("codediff", {
|
||||
diff_current = function(opts)
|
||||
if not utils.has_dependency("codediff") then
|
||||
return
|
||||
end
|
||||
|
||||
-- Extract the commit id from opts.rev
|
||||
local commit_id = "HEAD~1"
|
||||
if opts.rev then
|
||||
local t_commit_id = utils.get_commit_id(opts.rev)
|
||||
if t_commit_id == nil then
|
||||
return
|
||||
end
|
||||
commit_id = t_commit_id
|
||||
end
|
||||
|
||||
vim.cmd(string.format("CodeDiff file %s", commit_id))
|
||||
end,
|
||||
|
||||
show_revision = function(opts)
|
||||
if not utils.has_dependency("codediff") then
|
||||
return
|
||||
end
|
||||
|
||||
-- When comparing a revision we always compare it to it's parent to get the diff
|
||||
local right = string.format("%s-", opts.rev)
|
||||
|
||||
diff_two_changes(opts.rev, right)
|
||||
end,
|
||||
|
||||
diff_revisions = function(opts)
|
||||
if not utils.has_dependency("codediff") then
|
||||
return
|
||||
end
|
||||
|
||||
diff_two_changes(opts.left, opts.right)
|
||||
end,
|
||||
})
|
||||
Reference in New Issue
Block a user