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

Deal with clean filters somehow #480

Open
Kyuuhachi opened this issue Mar 2, 2022 · 9 comments
Open

Deal with clean filters somehow #480

Kyuuhachi opened this issue Mar 2, 2022 · 9 comments
Labels
enhancement New feature or request

Comments

@Kyuuhachi
Copy link

Is your feature request related to a problem? Please describe.
If you edit a file that is covered by a filter.*.clean rule, the diff detection does not work very well. I do realize this is not really possible to handle well since filters can do literally anything, but it does make a suboptimal editing experience.

Describe the solution you'd like
A non-exhaustive list of possible implementations, roughly in order of complexity:

  1. Doing nothing, leave it as it currently is.
  2. Show an indicator, hide the signs, etc for files affected by a clean rule. Not great, but might be better than showing a completely incorrect diff.
  3. Add a command for opening a split buffer showing the result of the filter (preferably live, but some filters might only work on disk-saved files, I don't know the specifics), and diffing that result with the index. This would probably be as close to an optimal editing experience as one can reasonably get. Would probably be lots of effort for a niche feature, so perhaps this would be better off as a separate plugin.
  4. Possibly augment the above with smudging the file back if applicable, but I would guess smudging is even rarer than cleaning.

Describe alternatives you've considered
Discussed above.

Additional context
Nothing in particular.

@Kyuuhachi Kyuuhachi added the enhancement New feature or request label Mar 2, 2022
@lewis6991
Copy link
Owner

TIL about git smudging and cleaning.

If smudge/clean commands all work via stdin/stdout, we could simply apply the filters before diffing?

Would add quite a lot of complexity and probably slow things down, but not against doing this at some point.

@Kyuuhachi
Copy link
Author

Yeah, they use stdin/out (not sure if they even get to know the filename they're working on). The problem (at least how I understand it) is how to display the diff in the editor; even with a simple filter such as tac, the diff lines don't really map onto editor lines.

@lewis6991
Copy link
Owner

Don't we just need to adapt the output of git show <path> and pass it through the filter which can then be compared to the working copy (the buffer contents)?

@Kyuuhachi
Copy link
Author

I'm not really familiar with git show; it seems to show diffs for the latest commit?

From what I've noticed, git diff diffs between the raw index file and the cleaned working copy, rather than between the smudged index file and the raw working copy. Though I agree that for realtime editing, including the raw working copy, and therefore the smudged index file, would make more sense. (Please excuse me if I'm getting the terminology wrong.)

@lewis6991
Copy link
Owner

git show :0:<path> will output the version of the file in the index (e.g. git show :0:Makefile.

From what I've noticed, git diff diffs between the raw index file and the cleaned working copy

We can do this.

Though I agree that for realtime editing, including the raw working copy, and therefore the smudged index file, would make more sense. (Please excuse me if I'm getting the terminology wrong.)

I don't really know which one makes more sense, I've never used these filters.

Both versions of the diff input are available as string variables in the plugin so we can filter either one in whatever way we want. The question is will the outputs be usable? If a filter is just changing single words in a file, then it would work. If they are removing/adding lines of text, then the signs will be wrong. Maybe if the line count changes we go with your option 2?

@lewis6991
Copy link
Owner

lewis6991 commented Mar 2, 2022

If you (or anyone) wants to prototype anything, the diff happens here:

bcache.hunks = run_diff(bcache.compare_text, buftext,

We just need to augment bcache.compare_text or buftext.

@Jak-Ch-ll
Copy link

I'm not really familiar with git show; it seems to show diffs for the latest commit?

From what I've noticed, git diff diffs between the raw index file and the cleaned working copy, rather than between the smudged index file and the raw working copy. Though I agree that for realtime editing, including the raw working copy, and therefore the smudged index file, would make more sense. (Please excuse me if I'm getting the terminology wrong.)

Hi, I was just experimenting with the filter functionality in Git and came across this issue with gitsigns.nvim. I wanted to add that using the smudged index file would not work in all cases, as smudge and clean are not necessarily complementary to each other. A good example would be to have a formatter in clean and nothing for smudge. The Git documentation actually shows this in an example. Under the image they use indent for cleaning, while smudge is just cat, which does nothing.

@joaomendoncaa

This comment has been minimized.

@lewis6991

This comment was marked as resolved.

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

No branches or pull requests

4 participants