pub fn delta(base: &[u8], target: &[u8]) -> Result<Option<Vec<u8>>>Expand description
A git delta that rebuilds target out of base, or None when there is
no point sending one.
None — not an error — for every case where the whole object is the better
answer, and the caller’s fallback is exactly that. Two conditions produce it,
and only two:
- a base at or past 4 GiB, which a copy offset cannot name. Checked up front, because nothing downstream could notice a truncated offset;
- a delta that came out no smaller than the target itself. This is the guard that makes a badly chosen candidate merely useless rather than harmful, and it is also what answers every degenerate input — an empty base, an empty target, a base shorter than one block — without a special case for any of them, because all of them produce a literal-only encoding that is longer than what it encodes. An earlier revision checked the empties separately; removing that check changed no outcome on any input, which is the definition of a guard that could never fail.
The size comparison is against the raw target length rather than the deflated one, because the delta is deflated afterwards by the same encoder at the same level: comparing the two before compression compares like with like and costs no extra deflate to decide.