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

Use git diff for diffs #150

Merged
merged 49 commits into from
May 29, 2024
Merged

Use git diff for diffs #150

merged 49 commits into from
May 29, 2024

Conversation

danvk
Copy link
Owner

@danvk danvk commented Sep 17, 2022

  • For file diffs: difflib.js → git diff --no-index left right
  • For directory diffs: hand-rolled code → git diff --no-index --raw left right

This eliminates a bunch of code, gets us much better diffs and lots more options. The one downside is that we have to invoke git difftool with --no-symlinks. This means that you can't make changes to unstaged files after running git webdiff and reload to see the changes. This is a fundamental issue with how git diff --no-index handles symlinks, see https://public-inbox.org/git/1489877673.24742.1.camel@kaarsemaker.net/t/

Update two years later: I hacked around this by making a copy of any directory containing symlinks before passing it to git diff --no-index (dir1) (dir2). When I invoke git diff --no-index (file1) (file2), I resolve the two files in case they're symlinks. This mostly lets us have our cake and eat it, too. I can see two flaws, though:

  1. The overall structure of the diff (which files are adds, deletes, renames, changes) is set in stone once when you invoke git webdiff. I think this was an issue with old webdiff, too, though.
  2. If your repo contains symlinks, then the diff that git webdiff shows will diverge from what you see from git diff, GitHub, etc. We might be able to avoid this by being careful about which symlinks we resolve. But I'd like to see this be a real issue before spending time on it.

I also took the opportunity to update a few dependencies and plug in a system for options using .gitconfig.

Fixes #7
Fixes #82
Fixes #100
Closes #120
Fixes #121
Closes #129

@danvk danvk marked this pull request as ready for review September 24, 2022 16:27
@danvk
Copy link
Owner Author

danvk commented May 18, 2023

TODO: this chops off the last line of files w/o trailing newlines

2024: to repro, run git webdiff 12bdbcc2629086b9c253ad1e1695d38ca0763692..1400f38a40f31b4aac4a95f42d0161ade4d2ca16 in the refstudio repo and look at CollapsibleBlock.tsx. This seems to be an issue with adds.

The bug turned out to be that wc -l ignores lines without trailing newlines. I changed it to git grep -c "" and it works like a charm.

@danvk danvk merged commit 358947a into master May 29, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant