Skip to main content

diff_counts

Function diff_counts 

Source
pub fn diff_counts(before: Option<&str>, after: Option<&str>) -> (u32, u32)
Expand description

Counts added and removed lines between two file revisions.

Returns (added, removed). A text that is None on either side is treated as empty, matching the JS twin: a file being added has no before-revision, and treating that as “unchanged” would report zero lines for a new file.

identical is not returned. The JS twin returns it, but a caller that has the two texts already can compare them; carrying a third value across the boundary for a bit it can derive would be waste.

§Counts are of lines, never bytes

A line ends at \n and a trailing newline yields a final empty element, so "a\n" is two lines and "a" is one. That is the same rule fc-diff and the JS twin use, and it is why the two agree on "a\n" vs "a". It looks like a quirk; it is deliberate, because all three implementations must split the same way or the counts disagree.