Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

diff

Package diff implements methods for comparing objects and producing edit scripts. The motivation for creating the package was to be able to use the diff output format in tests where the output of go-cmp wasn’t suitable. Comparing sequences of lengths N and M whose shortest edit script has D operations takes O((N+M)D) time and O(N+M) space. See the package documentation for more information.

Installation

$ go get mibk.dev/diff

Migrating from v0.1.0

v0.1.0 shipped without a go.mod and was imported as github.com/mibk/diff. The module is now mibk.dev/diff, so go get -u refuses the upgrade and restores v0.1.0, reporting a path mismatch. To move over:

  1. Move the imports over, from the root of your module:

    $ go run mibk.dev/mvimport@latest github.com/mibk/diff mibk.dev/diff
    

    That rewrites every import in the module, swaps the require for the new path at its latest version, prunes the old go.sum lines, and gofmts what it touched, so there is nothing left for go mod tidy to do. It needs Go 1.25 or newer.

  2. Rewrite the calls to the deprecated IntSlices, Float64Slices and StringSlices:

    $ go fix -inline ./...
    

    The wrappers carry inline directives, and -inline is what limits the run to those. Needs Go 1.26 or newer.

    Plain go fix ./... also does the job, but it runs every analyzer it has -- min/max, strings.Builder, range-over-int and a dozen more -- so it will modernize code that has nothing to do with this migration.

To take the new version without touching the import paths yet, map the old path onto the new module instead:

replace github.com/mibk/diff => mibk.dev/diff v0.2.0

Where a pair of sequences has several shortest edit scripts, v0.2.0 may report a different one than v0.1.0 did. Both are equally minimal, but tests pinned to the exact output can need updating.

About

package for producing edit scripts

Topics

Resources

Stars

4 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages