Skip to content

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

Open
Kybxd wants to merge 1 commit intomasterfrom
use-go-udiff
Open

refactor: Replace go-difflib with go-udiff and extract UnifiedDiff to pkg/udiff#159
Kybxd wants to merge 1 commit intomasterfrom
use-go-udiff

Conversation

@Kybxd
Copy link
Copy Markdown
Collaborator

@Kybxd Kybxd commented Mar 31, 2026

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
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.

1 participant