sebastianbergmann / diff

Diff implementation
BSD 3-Clause "New" or "Revised" License
7.58k stars 85 forks source link

[Feature] Percent change #101

Closed MGatner closed 4 years ago

MGatner commented 4 years ago

I would like to be able to indicate (similar to git GitHub) the relative amount a file has changed. I could not find any convenient way to do that currently, other than creating a diff string and calculating the size of the changes. I think it would make a nice addition to this library.

MGatner commented 4 years ago

Screen Shot 2020-05-22 at 2 07 01 PM

SpacePossum commented 4 years ago

I think the blocks indicates the number of additions and deletions and shown relative to each other, so not relative to the file (either before or after the change).

The number of lines added/deleted is within the result of Differ::diffToArray which you could process to the output you want. Or you can write your own output builder (instance of DiffOutputBuilderInterface) and pass to it to the constructor of Differ and use the Differ::diff method.

If you're thinking about a CI or something like that maybe you can use diffstat (https://linux.die.net/man/1/diffstat). This ships with most major linux flavors. So create the diff using the StrictUnifiedDiffOutputBuilder and feed the result to the command.

I'm not 100% sure this FR fits in the scope of the project, but I think it could technically be done here if we would know the wanted output format.

sebastianbergmann commented 4 years ago

This is outside the scope of this project.

MGatner commented 4 years ago

Okay, thanks for the response. Do you know if something like this is calculated anywhere in PHPUnit already?

MGatner commented 4 years ago

Thanks @spacepossum, missed your answer until just now! Good starting places.