feat(diff): implement dedicated line mode diffing functionality #152
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR implements a dedicated line mode diffing functionality for the go-diff library, providing users with a more efficient and predictable way to perform line-based text comparisons.
Changes
New Features
DiffLineMode
method: A new public method that always uses line mode regardless of text length, providing consistent behavior for line-based diffing scenariosDiffFunction
type: A new function type that encapsulates diff computation logic, enabling more flexible and testable diff implementationsDiffCleanupLineBased
method: Specialized cleanup function for line-based diffs that merges consecutive operations and removes trivial equalitiesRefactoring
DiffMainRunes
: Refactored to use closure-based approach for better encapsulation of deadline and line mode logicdiffCompute
: Updated to use the newDiffFunction
type for more flexible diff computationInfrastructure
Benefits
DiffLineMode
provides consistent behavior regardless of input sizeTesting
DiffLineMode
functionalityUsage Example
Breaking Changes
None. This is a purely additive change that maintains full backward compatibility.
Related Issues
This implementation addresses the need for more efficient and predictable line-based diffing in scenarios where character-level precision is not required.