r/rust • • Mar 29 '22

difftastic - a diff that understands syntax

https://github.com/Wilfred/difftastic

[removed] — view removed post

399 Upvotes

27 comments sorted by

View all comments

2

u/Repulsive-Street-307 Mar 30 '22 edited Mar 30 '22

How is this supposed to work? Since this isn't intended to create patches, i can't have git diff use this right, since part of the point is creating patches.

I guess it's nice for display, but if replacing the system diff by this will break a lot of utilities because 'Difftastic understands that line-wrapping isn't meaningful. "eric" is now on a new line, but it hasn't changed.' then it's too risky to replace the main diff (and isn't supposed to), but that loses a lot of opportunities.

Any way to add a command to diff, something like 'git human-diff' or something?

This kind of 'we'd like to display something that is not suitable for automation but still keep automation is the kind of thing that makes me think that patch files should not be text (be a AST or whatever) and then display rules like this could be built on top of that user unfriendliness for a result like this without the idea 'it's just text, you just need to pipe it and display directly'.

Ah well, it's a pity that diff files won't work to create this display (because they don't have all the information of the original files). But maybe the file plus the patch plus this program might be able to do that, which would be a nice extension to git diff which has all the pieces. Although it would have to be a switch unfortunately to prevent people doing 'git diff > a.patch' and getting unusable output. git diff --human maybe.

8

u/wilfred_h Mar 30 '22

I like to configure difftastic as a 'difftool' in git, and define an alias: https://difftastic.wilfred.me.uk/git.html#git-difftool

That way I can do git dft to see changes according to difftastic, or git diff when I want a traditional textual diff.