Skip to content

Conversation

@mrnugget
Copy link
Contributor

@mrnugget mrnugget commented Mar 5, 2024

This adds a new action to the editor: editor: toggle git blame. When used it turns on a sidebar containing git blame information for the currently open buffer.

The git blame information is updated when the buffer changes. It handles additions, deletions, modifications, changes to the underlying git data (new commits, changed commits, ...), file saves. It also handles folding and wrapping lines correctly.

When the user hovers over a commit, a tooltip displays information for the commit that introduced the line. If the repository has a remote with the name origin configured, then clicking on a blame entry opens the permalink to the commit on the code host.

Users can right-click on a blame entry to get a context menu which allows them to copy the SHA of the commit.

The feature also works on shared projects, e.g. when collaborating a peer can request git blame data.

As of this PR, Zed now comes bundled with a git binary so that users don't have to have git installed locally to use this feature.

Screenshots

screenshot-2024-03-28-13 57 43@2x

screenshot-2024-03-28-14 01 23@2x
screenshot-2024-03-28-14 01 32@2x

TODOs

  • Bundling git binary

Release Notes

Release Notes:

  • Added editor: toggle git blame command that toggles a sidebar with git blame information for the current buffer.
@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Mar 5, 2024
@mrnugget mrnugget force-pushed the git-blame-prototyping branch from e08ff3c to 348e0c6 Compare March 5, 2024 17:09
@baldwindavid
Copy link
Contributor

This will be a very handy feature. This is out of scope for now but, while I use blame in VSCode, 99% of the time it's a hover to see which PR introduced the commit and to click the link to view the PR on Github.

@mrnugget mrnugget force-pushed the git-blame-prototyping branch from 348e0c6 to d8f57ac Compare March 6, 2024 17:04
@mrnugget mrnugget force-pushed the git-blame-prototyping branch from 3632d6f to 6e9bee1 Compare March 7, 2024 10:08
@JosephTLyons
Copy link
Collaborator

JosephTLyons commented Mar 8, 2024

Oooooh! If this prototype goes through, this will be super awesome!

@mrnugget mrnugget force-pushed the git-blame-prototyping branch from dedeb0a to f16f6ac Compare March 18, 2024 10:29
@mrnugget
Copy link
Contributor Author

Current preview:

screenshot-2024-03-19-18.36.18.mp4
@mrnugget
Copy link
Contributor Author

Collaboration works! Now all that's left is bundling git and incorporating more design feedback :)

screenshot-2024-03-27-19.59.35.mp4
@mrnugget mrnugget changed the title WIP: git blame prototypin' Add git blame functionality Mar 28, 2024
@mrnugget mrnugget changed the title Add git blame functionality Add git blame Mar 28, 2024
@mrnugget mrnugget force-pushed the git-blame-prototyping branch from e86b49d to 01e6861 Compare March 28, 2024 10:54
@mrnugget mrnugget added run-bundling Configures PR to run the bundle step and removed run-build-dmg labels Mar 28, 2024
@mrnugget mrnugget marked this pull request as ready for review March 28, 2024 16:54
@mrnugget mrnugget removed the run-bundling Configures PR to run the bundle step label Mar 28, 2024
@mrnugget
Copy link
Contributor Author

bundled git binary also works!

screenshot-2024-03-28-18 23 50@2x

@mrnugget mrnugget merged commit 7f54935 into main Mar 28, 2024
@mrnugget mrnugget deleted the git-blame-prototyping branch March 28, 2024 17:32
@baldwindavid
Copy link
Contributor

baldwindavid commented Mar 28, 2024

@mrnugget I've been using this in main and it's wonderful! Sorry for the unrelated, probably dumb question, but I've done a cargo run --release to get a Zed executable. Are there instructions somewhere to get a Mac "app" like you have there that I can run similarly to Preview/Stable releases?

Update: nvm, I see a bundle-mac script; I'll poke around with that.

@mmtftr
Copy link
Contributor

mmtftr commented Mar 29, 2024

Even though this is merged, I have a question @mrnugget. I'm curious as to why the code cannot just use git2::Blame for this. git2::Blame has Blame::blame_buffer which I believe would do the same thing as calling git blame --contents. I'm not sure what benefits we get by doing a --incremental especially since we wait for the command to exit.

@mrnugget
Copy link
Contributor Author

mrnugget commented Apr 2, 2024

@baldwindavid yep, that's the one. scripts/bundle-mac.

@mmtftr because it's very, very slow. See here: libgit2/libgit2#3027 Running git blame on crates/editor/src/editor.rs in this repository here took 40s, vs 600ms shelling out to git. --incremental in this case is only used for its machine-readable output.

@mrnugget mrnugget mentioned this pull request Apr 3, 2024
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement

6 participants