Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Diff directories (not git rev) #533

Open
Makaze opened this issue Oct 6, 2024 · 3 comments
Open

Feature request: Diff directories (not git rev) #533

Makaze opened this issue Oct 6, 2024 · 3 comments

Comments

@Makaze
Copy link

Makaze commented Oct 6, 2024

Situation: Have two folders, e.g., two worktrees.

Desired behavior: :DiffView path1/ path2/ (or equiv) and DiffView behaves as expected relative to the folders instead of the git rev.

If this is already possible, please add this as a use case to the docs! It's powerful agnostic of the versioning tools used.

@Makaze Makaze changed the title Feature request: Diff folders (not git rev) Feature request: Diff directories (not git rev) Oct 6, 2024
@Kailian-Jacy
Copy link

Kailian-Jacy commented Dec 22, 2024

Currently it seems diffing non-git files are not supported. Either git or hg adapter needs to be selected.

function M.diffview_open(args)
local default_args = config.get_config().default_args.DiffviewOpen
local argo = arg_parser.parse(utils.flatten({ default_args, args }))
local rev_arg = argo.args[1]
logger:info("[command call] :DiffviewOpen " .. table.concat(utils.flatten({
default_args,
args,
}), " "))
local err, adapter = vcs.get_adapter({
cmd_ctx = {
path_args = argo.post_args,
cpath = argo:get_flag("C", { no_empty = true, expand = true }),
},
})
if err then
utils.err(err)
return
end

Also advocating for this function.

The name diffview.nvim sounds like a general diffing view as alternative and enhancement to nvim diff, but without this functionality it seems more like gitdiff.nvim, vcsdiff.nvim or something.

I haven't read code carefully, but on skip reading It seems like diffview.nvim is diffing manually but not relying on something like git diff. So hopefully it will be convenient to extend diffview to general files not being tracked by git?

function Diff:lcs(astart, aend, bstart, bend)
-- separate common head
while astart < aend and bstart < bend and self.eql_fn(self.a[astart], self.b[bstart]) do
astart = astart + 1
bstart = bstart + 1
end
-- separate common tail
while astart < aend and bstart < bend and self.eql_fn(self.a[aend - 1], self.b[bend - 1]) do
aend = aend - 1
bend = bend - 1
end
if astart == aend then
-- only insertions
while bstart < bend do
self.modb[bstart] = true
bstart = bstart + 1
end
elseif bend == bstart then
-- only deletions
while astart < aend do
self.moda[astart] = true
astart = astart + 1
end
else
local snake = self:snake(astart, aend, bstart, bend)
self:lcs(astart, snake.x, bstart, snake.y)
self:lcs(snake.u, aend, snake.v, bend)
end
end

@bew
Copy link

bew commented Dec 22, 2024

It could be using git diff --no-index path1 path2 which works well for any paths (file, dir, that is inside or outside a repo)

I'm assuming here (but am not sure at all) that diffview integrates with the output of git diff 🤔

@Kailian-Jacy
Copy link

It could be using git diff --no-index path1 path2 which works well for any paths

Does diffview have support for this?
POSIX diff can do this too I'm afraid. But we need an integration into nvim tui.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants