ashlar-diff
Headless text diffs for ashlar apps: which lines changed, which words in them, and how to show them with context.
FileDiff::from_texts(old, new): a line diff (Myers' algorithm) cut into hunks with three lines of context. A cost cap bounds the time and memory of one run; past it the diff splits at lines unique to both sides, and as a last resort replaces the rest wholesale (coarseis then set).from_texts_withtakes the context size, the cap, and whether to compute word emphasis.- Word-level emphasis: in a run of removed lines followed by added lines, the n-th removed line
pairs with the n-th added one, and
Line::emphasisholds the byte ranges that differ.word_diff(old, new)exposes the same for any two strings. FileDiff::gaps(): the unchanged ranges between hunks, which a view shows collapsed. They are expandable (source_line) when the new text is known: always forfrom_texts, and for a parsed patch afterwith_source(new_text).parse_patch(text): unified patches andgit diffoutput, oneFileDiffper file, with renames, copies, mode changes, binary markers (andGIT binary patchdata), quoted paths and\ No newline at end of file. Malformed input is aPatchErrorwith a line number, never a panic; nothing is allocated from a number the patch states.write_patchwritesgit diffoutput back byte for byte.diff_ops(a, b, max_cost): the underlying edit script for anyEq + Hashsequence.
No dependencies, no UI; builds for wasm32-unknown-unknown. The view is
ashlar_ui::diff_view::DiffView.
use ;
let d = from_texts.with_paths;
assert_eq!;
let files = parse_patch.unwrap;
assert_eq!;
assert_eq!;