Skip to main content

Crate divot

Crate divot 

Source
Expand description

Fast diff/patch engine built on imara-diff (Apache-2.0), the diff engine that powers gitoxide. This crate adds:

  • Word- and char-granularity tokenization (imara-diff only ships line tokenization out of the box).
  • A jsdiff-shaped Change result type (unchanged/added/removed runs across the whole input, not just the changed hunks), so the npm binding can offer an easy migration path from the incumbent diff package it measurably outperforms.

See the repository README for the real, reproducible benchmark against jsdiff.

Structs§

Change
One contiguous run of tokens in a diff result: unchanged (present identically in both before and after), added, or removed. Mirrors jsdiff’s Change shape ({value, added, removed, count}) so the npm binding can expose an API shaped like the incumbent it’s meant to be an easy migration from.

Enums§

Algorithm
imara-diff supports multiple different algorithms for computing an edit sequence. These algorithms have different performance and all produce different output.

Functions§

char_diff
Diffs before/after character by character.
line_diff
Diffs before/after line by line (the newline is included in each line’s token, same convention imara-diff uses, so changing the final line’s trailing newline is itself detected as a change).
line_diff_many
Diffs many (before, after) pairs at once, across a Rayon thread pool.
unified_diff
Renders a unified diff (git diff/diff -u style patch text) for before/after. Thin wrapper over imara-diff’s own unified_diff feature – no reimplementation needed here, unlike the tokenizers above.
word_diff
Diffs before/after word by word. “Word” means a maximal run of alphanumeric/_ characters; runs of whitespace/punctuation between words are their own tokens, so e.g. a single added space is reported as its own small change rather than merged into a neighboring word.