How are Mercurial diffs and deltas calculated?
Mercurial diffs are calculated rather differently than those generated by the traditional diff algorithm (but with output that’s completely compatible with patch of course). The algorithm is an optimized C implementation based on Python’s difflib, which is intended to generate diffs that are easier for humans to read rather than be ‘minimal’. This same algorithm is also used for the internal delta compression.