Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for being used as diff-filter in git #280

Open
kissge opened this issue May 3, 2022 · 6 comments
Open

Add support for being used as diff-filter in git #280

kissge opened this issue May 3, 2022 · 6 comments

Comments

@kissge
Copy link

kissge commented May 3, 2022

First of all, I love this software. This is truly great.

What I'd like to suggest is, adding support for being used as diff-filter.
This enables the following big benefits:

  1. It can be used in git add -p, git restore -p , etc., which is currently impossible.
    • With a filter feature support, git config interactive.diffFilter difft-as-filter-or-something will be possible.
  2. It can be used in git show, git log, and many others, by default, without manually specifying --ext-diff every time.

By nature, the implementation would necessitate parsing the (traditional) diff(1) output, which is quite difficult because the context information is very limited. I guess the possible directions would be: 1. implementing parse source code segments or 2. find some way to get more information from git.
(Looks like there're even no equivalent of git diff -U 1000 for git add -p)

I understand the current status of this project, I want to respect what you want to build yourself, and this suggestion might not interest you. I simply wish that some way to achieve this will be found by some clever folks and so let me submit this issue here.

@Xuanwo
Copy link
Contributor

Xuanwo commented May 3, 2022

Maybe we can make a pager which calls difftastic like https://github.com/dandavison/delta

@Wilfred
Copy link
Owner

Wilfred commented May 3, 2022

Interesting, I didn't know about this git setting. Here's the docs: https://git-scm.com/docs/git-config#Documentation/git-config.txt-interactivediffFilter

without manually specifying --ext-diff every time

FWIW you can do this today, by setting diff.external: https://difftastic.wilfred.me.uk/git.html

find some way to get more information from git

I think this is a cool idea, but it'd require some work:

  • We'd need to get the whole file and apply the diff, so we have the full source code before and after
  • We'd need an option to difftastic to say "only display changes between lines M and N"

This is definitely something I'd be interested in adding, assuming we can get the original file content out of git. It's low on my list right now though, as there are still cases where difftastic gives bad diff results.

@kissge
Copy link
Author

kissge commented May 7, 2022

Glad to hear that.

FWIW you can do this today, by setting diff.external: difftastic.wilfred.me.uk/git.html

IIUC that is true with git diff, but not with git show, git log, and many others.

One (poorman's) hack I came up with is overwriting git and make it give additional information to difftastic. e.g. Put something like this in your shrc:

function git() {
  DIFFTASTIC_GIT_COMMAND=$@ command git "$@"
}

difftastic can provide help through a shell script file like /usr/local/share/difftastic/git-interactive-support.sh, or eval $(difft --bashrc).

@egrieco
Copy link

egrieco commented May 15, 2022

Maybe we can make a pager which calls difftastic like https://github.com/dandavison/delta

If you are referring to the style of delta, I've got a pull request open #286.

@Xuanwo
Copy link
Contributor

Xuanwo commented May 15, 2022

If you are referring to the style of delta, I've got a pull request open #286.

OH, we are talking about a different thing. git log and git diff are quite different.

git log will call a pager internally and we can't change inner diff behavior unless using --ext-diff or implementing our own pager as delta does.

Wilfred pushed a commit that referenced this issue Mar 16, 2023
Wilfred pushed a commit that referenced this issue Jun 13, 2023
@alper
Copy link

alper commented Nov 22, 2023

Does git add -p also call a pager?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants