godebug icon indicating copy to clipboard operation
godebug copied to clipboard

Add options to Diff and DiffChunk.

Open pgweiss opened this issue 5 years ago • 1 comments

This commit adds options to Diff and DiffChunks. The only option I've implemented is Transform, which is a function to modify lines before diffing.

I find myself often having to modify files before diffing so that I can ignore differences I don't care about and concentrate on those I do. One example might be diffing the log output of a program running at different times, where you want to ignore the timestamp. There are many others. However, the problem with modifying the lines before diffing is that I'd like the output and context lines to refer to the original lines before they were modified. That is what the Transform option does.

Note that if a transform is not provided then no copying is done, and there is no change to the calling convention for existing callers. If there are additional options in the future, they can be added to the options structure.

pgweiss avatar Mar 02 '20 19:03 pgweiss

Unfortunately, changing an exported signature is a breaking change to the API. If you need transformations, I recommend package cmp. I will tag this as a breaking change in case we accumulate enough to be worth a v2 branch.

kylelemons avatar Aug 30 '20 17:08 kylelemons