feat(dir): support path-restricted directory diffs#435
Open
dwf wants to merge 1 commit into
Open
Conversation
Motivation: comparing two very large directory trees where the set of
created/deleted/modified files is already known ahead of time. The
existing dir mode scans both trees exhaustively (recursive fs_scandir +
content comparison), which is prohibitively expensive when the trees are
huge and only a handful of paths are of interest -- the scan dominates,
even though almost every file is identical or irrelevant.
Add an optional `opts.paths` list to dir mode so the diff can be
restricted to a specific set of relative paths instead of walking the
trees. Each listed path is stat'd directly in both roots (O(#paths)
rather than O(tree)), so the cost scales with the paths you care about,
not the size of the trees.
Classification per path: present on both -> content-compared (M/none);
present on one side -> creation/deletion (A/D); absent on both -> reported
via a new `missing` list and skipped. Paths are normalized (separator,
leading `./` and `/`, de-duplicated).
The filter is threaded through explorer_data -> panel -> render -> refresh
so refreshing the explorer (R) re-diffs only the listed paths.
Surface it via a new Lua API, `require("codediff").dir_diff(dir1, dir2,
{ paths, layout })`: a caller-supplied path list is unwieldy as inline
`:CodeDiff` command arguments (it can be hundreds of entries), so a Lua
entry point is the most ergonomic option for programmatic use. `layout`
("inline"/"side-by-side") is passed through to the existing dir-mode
layout selection.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
fabf3c7 to
4bbb0e8
Compare
Author
|
N.B. Happy to revisit the public API or put it in e.g. a |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation: comparing two very large directory trees where the set of created/deleted/modified files is already known ahead of time. The existing dir mode scans both trees exhaustively (recursive fs_scandir + content comparison), which is prohibitively expensive when the trees are huge and only a handful of paths are of interest -- the scan dominates, even though almost every file is identical or irrelevant.
Add an optional
opts.pathslist to dir mode so the diff can be restricted to a specific set of relative paths instead of walking the trees. Each listed path is stat'd directly in both roots (O(#paths) rather than O(tree)), so the cost scales with the paths you care about, not the size of the trees.Classification per path: present on both -> content-compared (M/none); present on one side -> creation/deletion (A/D); absent on both -> reported via a new
missinglist and skipped. Paths are normalized (separator, leading./and/, de-duplicated).The filter is threaded through explorer_data -> panel -> render -> refresh so refreshing the explorer (R) re-diffs only the listed paths.
Surface it via a new Lua API,
require("codediff").dir_diff(dir1, dir2, { paths, layout }): a caller-supplied path list is unwieldy as inline:CodeDiffcommand arguments (it can be hundreds of entries), so a Lua entry point is the most ergonomic option for programmatic use.layout("inline"/"side-by-side") is passed through to the existing dir-mode layout selection.