Skip to main content

detect_exact_renames

Function detect_exact_renames 

Source
pub fn detect_exact_renames(entries: &mut Vec<DiffEntry>)
Expand description

Collapse exact (identical-content) delete+add pairs in entries into single DiffKind::Renamed entries, in place.

mkit is content-addressed, so two paths that share an object id hold byte-identical content. A DiffKind::Removed entry and a DiffKind::Added entry with equal object ids are therefore an exact rename — git’s similarity index 100%, but with no heuristic, no threshold, and no false positives. When identical content is duplicated across several removed/added paths, pairs are formed in sorted-path order so the outcome is deterministic; any unpaired remainder stays as a plain add/remove. The result is left sorted by destination path, matching the rest of the diff pipeline.

Callers scope this to a single diff (git detects renames within one diff): for status, that means applying it per staging leg so a staged delete never pairs with an unstaged add.