Skip to main content

diff_ops

Function diff_ops 

Source
pub fn diff_ops(old: &[&[u8]], new: &[&[u8]]) -> Vec<Op>
Expand description

The full edit script, not just its length.

[edit_counts] answers how many lines moved and needs only the edit distance; a blame needs which, so this is the same Myers walk with its trace kept and backtracked. It is a separate function because the trace costs O(D²) where the distance alone costs O(D), and the common caller — a diff’s line counts — must not pay for a script nobody reads.

Past [MAX_EDIT_DISTANCE] it returns the trivial script (delete everything, insert everything). That is a valid script, so a blame built on it attributes every line to the commit that rewrote the file — which is what actually happened when a file changes that much.