Skip to content
Fossil Update of ”checkin/20def862b03a4202d9e93a895187b312300c3252622ca200007173e261b516e0”
Login

Update of ”checkin/20def862b03a4202d9e93a895187b312300c3252622ca200007173e261b516e0”

Overview

Artifact ID: 3be8c9e8879fed9c80bf2f8a8bfb0595d88f5faf7297cb872aa5949e9d48482c
Page Name:checkin/20def862b03a4202d9e93a895187b312300c3252622ca200007173e261b516e0
Date: 2026-11-30 15:23:34
Original User: drh
Mimetype:text/x-markdown
Content

Side-by-side diff: reducing edit-mark "confetti"

Problem

When a block of lines is mostly rewritten, the side-by-side diff pairs the old and new lines and then marks the individual changed spans inside each pair. For a rewrite this produces many tiny marks separated by coincidental matches ((, ,, a 1-byte common letter...). The marks are noisier than no marks at all.

How the marks are produced

  1. Line pairing - diffBlockAlignment() runs a Wagner edit-distance over a change block and decides which left line becomes which right line, using match_dline() (score 5..100, lower = more similar). A pair was accepted if score<=90 or if it was near the diagonal, so even completely different lines were paired as an "edit".
  2. Marks inside a pair - oneLineChange() takes the common prefix and suffix, then textLineChanges() repeatedly splits at the longest common substring (textLCS()) while spans are at least 6 bytes. textLCS() accepted a common substring of any length, including 1 byte.

Builders: xEdit (marks inside line), xReplace (delete + insert, no inner marks). The alignment array uses codes 1 delete, 2 insert, 3 edit, 4 replace.

The change

  1. Weakly matching lines (score > DIFF_REPLACE_SCORE=75) are still lined up but shown as replace (code 4): deleted and inserted with no inner marks. Implemented at diffBlockAlignment()

  2. A common fragment must be >= LCS_MIN_LEN(4) bytes and contain an alnum run >= LCS_MIN_ALNUM(3) to split a span (lcsIsUseful()). Implemented at textLineChanges()

  3. If < LINECHNG_MIN_COMMON_PCT(40)% of the changed region is common, use one big span instead of a split (lineChangesAreWorthShowing()) Implemented at OneLineChange()

Other fixes made at the same time:

Results

Unit pairs with fossil test-line-diff A B (digits mark change spans):

Pair Before After
if(...) line rewrite, score 85 5 spans 1 span
sqlite3_exec(..) -> sqlite3_prepare_v2(..) 3 spans 1 span
...MemSetStr(..) -> ...MemSetText(..) 5 spans 1 span
foo(alpha, beta, gamma) -> foo(alpha, delta, gamma) 1 small span unchanged
compute_widget_total(a, b) -> (a, b, c) and offset -> offset2 2 small spans unchanged

In a side-by-side HTML diff of a small file, the score-85 line shows no marks at all (delete plus insert); the other changed lines keep their edit marks. The diff tests in test/ pass (11 of 11).

Caveats