| Artifact ID: | 49aa4e8f7d3467167ac5dc8bafb8ded0a1f60d2430bf292898198442751f7db4 |
|---|---|
| Page Name: | checkin/1a2098f1f2d8d52a901cd53a70a9d388960ec7498bd5ddd4b25ab4cead3c69da |
| Date: | 2026-11-30 15:31:05 |
| Original User: | drh |
| Mimetype: | text/x-markdown |
Side-by-side diff: prototype enhancements
Experimental changes for A/B comparison of difficult side-by-side diff output.
A/B switch
FOSSIL_DIFF_PROTO, read as hex, default (unset) = all on = 7:
0x1token-level inner diff0x2merge small gaps0x4block rewrite detector
FOSSIL_DIFF_PROTO=0 disables all.
Heuristics
Token-level inner diff. Tokens are identifier runs (letters, digits,
_, non-ASCII), whitespace runs, and single punctuation characters. A length-weighted LCS over tokens gives matched tokens; contiguous matches form anchors, kept if >= 4 bytes (LCS_MIN_LEN). Spans are the text between anchors. If there are more spans than fit in aLineChange(MX_CSN), the closest are merged. Falls back to the byte algorithm above 160 tokens per line.trimSpans()then trims the common prefix and suffix inside each span, sooffset->offset2marks only the2. Changes attokenLineChanges(),trimSpans(), called fromlineChangesEx()Merge change spans whose unchanged gap is less than 1/4 of the two spans' combined size. At
mergeSmallGaps(), called fromlineChangesEx()Block rewrite detector. For each aligned block, count "heavy" pairs: pairs already coded as replace (4), or edits where more than
BLOCK_HEAVY_PCT(50)% of the bytes are inside marks (lineChangePercent()). If at least 2 pairs are heavy and heavy >= light, the heavy pairs are changed to code 4 (no inner marks). Light pairs keep their marks. AtformatDiff().
oneLineChange() now calls lineChangesEx() instead of textLineChanges()
directly; lineChangesEx() tries the token algorithm, falls back to the byte
algorithm, merges small gaps, then trims spans. The common-ratio gate
(heuristic 4) still runs on its result.
Notes
The first token version regressed
offset->offset2. The punctuation-only island) +was dropped as "not useful", merging two marks into one big one. Two fixes: token anchors use a plain >= 4 byte rule instead of the alphanumeric test, andtrimSpans()narrows each span back to the bytes that really differ.Token mode is coarser on short identifiers:
void foo->int foo2marks both whole phrases instead of three small marks.Thresholds (50% heavy, gap/4, 4-byte anchors, 160 tokens) are guesses from a handful of examples.
Need to tune thresholds against real rewrite hunks.
Consider also tightening the near-diagonal pairing rule in
diffBlockAlignment()(i<j+1 && i>j-1), which can force a pairing of unrelated lines.