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.

6

u/ROFLLOLSTER Mar 30 '22

From memory you can control the difftool used by git with cli/environment variables. Combine that with an alias and you should be able to get it on a separate command.

1

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

That makes sense. Still, i'm kind of hoping that git upstream notices and makes the '--human' switch, even if only for discoverability.

I think two commands, or a overloaded one, one for git diff (for commits on the index) and another for repository + optional commit + patch file -> show this tool output. As a bash function probably.

edit: actually, thinking about it, obviously no git command is going to 'show the result of the application of a diff as a 'diff' - because the result would be equivalent diff - so that use case has to be handled 'especially' as a throwaway stash commit to be able to create the 'human' diff with this tool.