go-cmp icon indicating copy to clipboard operation
go-cmp copied to clipboard

Provide Diff statistics

Open shibumi opened this issue 2 years ago • 1 comments

Hey there,

we have a Google internal Use case, where it would be nice to support Diff statistics. Any chance that we can get this into go-cmp?

I thought about something like:

  • Total: Total number of Differences (each line counts as a difference)
  • Additions: Number of additions
  • Changes: Number of Changes
  • Removals: Number of Removals

As first draft a total number is sufficient.

shibumi avatar Feb 20 '23 13:02 shibumi

This is highly specialized and I don't think there needs to be first-class support for it in cmp.

You can accomplish this yourself using a custom Reporter.

The output of Diff is implemented in terms of a Reporter. You can look at the implementation in the cmp package and take the relevant parts to gather the statistics you care about.

dsnet avatar Feb 20 '23 17:02 dsnet