Skip to content

git: Move diff num stat calculation to repository snapshot layer #50645

Merged
Anthony-Eid merged 26 commits intomainfrom
fix-diff-stat-remote-support
Mar 4, 2026
Merged

git: Move diff num stat calculation to repository snapshot layer #50645
Anthony-Eid merged 26 commits intomainfrom
fix-diff-stat-remote-support

Conversation

@Anthony-Eid
Copy link
Copy Markdown
Contributor

@Anthony-Eid Anthony-Eid commented Mar 3, 2026

Follow up on: #49519

This PR reworks how Zed calculates diff num stats by moving the calculation to the RepositorySnapshot layer, instead of the GitPanel. This has a couple of benefits:

  1. Snapshot recalculations are already set up to recompute on file system changes and only update the affected files. This means that diff stats don't need to manage their own subscription or states anymore like they did in the original PR.
  2. We're able to further separate the data layer from the UI. Before, the git panel owned all the subscriptions and tasks that refreshed the diff stat, now the repository does, which is more inline with the code base.
  3. Integration tests are cleaner because FakeRepository can handle all the data and calculations of diff stat and make it accessible to more tests in the codebase. Because a lot of tests wouldn't initialize the git panel when they used the git repository.
  4. This made implementing remote/collab support for this feature streamline. Remote clients wouldn't get the same buffer events as local clients, so they wouldn't know that the diff stat state has been updated and invalidate their data.
  5. File system changes that happened outside of Zed now trigger the diff stat refresh because we're using the RepositorySnapshot.

I added some integration tests as well to make sure collab support is working this time. Finally, adding the initial diff calculation to compute_snapshot didn't affect performance for me when checking against chromium's diff with HEAD~1000. So this should be a safe change to make.

I decided to add diff stats on the status entry struct because it made updating changed paths and the collab database much simpler than having two separate SumTrees. Also whenever the UI got a file's status it would check its diff stat as well, so this change makes that code more streamlined as well.

Before you mark this PR as ready for review, make sure that you have:

  • Added a solid test coverage and/or screenshots from doing manual testing.
  • Done a self-review taking into account security and performance aspects.

Release Notes:

  • N/A

@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Mar 3, 2026
@zed-community-bot zed-community-bot bot added the staff Pull requests authored by a current member of Zed staff label Mar 3, 2026
@Anthony-Eid Anthony-Eid enabled auto-merge (squash) March 4, 2026 14:59
@Anthony-Eid Anthony-Eid disabled auto-merge March 4, 2026 16:30
@Anthony-Eid Anthony-Eid enabled auto-merge (squash) March 4, 2026 18:53
@Anthony-Eid Anthony-Eid merged commit 5c91ebf into main Mar 4, 2026
28 checks passed
@Anthony-Eid Anthony-Eid deleted the fix-diff-stat-remote-support branch March 4, 2026 18:54
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 staff Pull requests authored by a current member of Zed staff

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant