Skip to content

refactor: Replace go-difflib with go-udiff and extract UnifiedDiff to pkg/udiff#159

Merged
wenchy merged 1 commit into
masterfrom
use-go-udiff
Apr 2, 2026
Merged

refactor: Replace go-difflib with go-udiff and extract UnifiedDiff to pkg/udiff#159
wenchy merged 1 commit into
masterfrom
use-go-udiff

Conversation

@Kybxd

@Kybxd Kybxd commented Mar 31, 2026

Copy link
Copy Markdown
Collaborator

Summary

Replace the deprecated pmezard/go-difflib dependency with the lighter aymanbagabas/go-udiff library for generating unified diffs, and extract the UnifiedDiff function from generated code into a reusable pkg/udiff package.

Changes

  • Extract UnifiedDiff to pkg/udiff package: Moved the UnifiedDiff function out of the generated util.pc.go template into a standalone pkg/udiff package, making it reusable and independently testable.
  • Replace diff library: Switched from pmezard/go-difflib to aymanbagabas/go-udiff, which provides a simpler API and eliminates the need to manually split lines.
  • Add comprehensive unit tests: Added tests covering no-difference, with-difference, nil/empty messages, and complex nested structpb messages with precise unified diff line assertions.
  • Remove golang.org/x/exp dependency: Replaced golang.org/x/exp/slices with the standard library slices package (Go 1.21+).
  • Fix comment typo: Corrected mutableCheck comment from "mutable" to "mutated".

@Kybxd
Kybxd requested a review from wenchy March 31, 2026 12:54
@wenchy
wenchy merged commit 8e927a4 into master Apr 2, 2026
6 checks passed
@wenchy
wenchy deleted the use-go-udiff branch April 2, 2026 07:31
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.

2 participants