Skip to content

Fix UnifiedDiffReader to use correct DeltaType#228

Merged
wumpz merged 1 commit into
java-diff-utils:masterfrom
andrewparmet:fix/unified-diff-delta-types
May 16, 2026
Merged

Fix UnifiedDiffReader to use correct DeltaType#228
wumpz merged 1 commit into
java-diff-utils:masterfrom
andrewparmet:fix/unified-diff-delta-types

Conversation

@andrewparmet
Copy link
Copy Markdown

finalizeChunk() previously always created ChangeDelta regardless of whether the hunk contained only insertions, only deletions, or only context lines. This made it impossible for consumers to determine the actual type of change from the delta alone.

Now uses InsertDelta when a hunk contains only additions (no context), DeleteDelta when only deletions (no context), EqualDelta when only context, and ChangeDelta otherwise. Hunks with context lines still use ChangeDelta to preserve backward-compatible applyTo behavior.

Fixes #201.

finalizeChunk() previously always created ChangeDelta regardless of
whether the hunk contained only insertions, only deletions, or only
context lines. This made it impossible for consumers to determine the
actual type of change from the delta alone.

Now uses InsertDelta when a hunk contains only additions (no context),
DeleteDelta when only deletions (no context), EqualDelta when only
context, and ChangeDelta otherwise. Hunks with context lines still use
ChangeDelta to preserve backward-compatible applyTo behavior.

Fixes java-diff-utils#201
@wumpz
Copy link
Copy Markdown
Collaborator

wumpz commented May 16, 2026

Thx for improving and using diff utils.

@wumpz wumpz merged commit 61deff7 into java-diff-utils:master May 16, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DeltaType always assigned as CHANGE in UnifiedDiff.parseUnifiedDiff(InputStream stream)

3 participants