# git: Load buffer git diff bases with a single batched git process \(\#59357\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/bc29bcfe728e3ce158f36b6a1b15f3dff667fe02)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: bc29bcfe728e3ce158f36b6a1b15f3dff667fe02

Requested commit: bc29bcfe728e3ce158f36b6a1b15f3dff667fe02

Commit: bc29bcfe728e3ce158f36b6a1b15f3dff667fe02

Tree: 829e4ba5300b7ac942de2e26b50e48a1426f0f98

Author: Lukas Geiger

Committer: GitHub

## Message

````
git: Load buffer git diff bases with a single batched git process (#59357)

# Objective

Whenever the git repository state is updated on disk (e.g., via staging,
committing, branch switching, or stashing), `reload_buffer_diff_bases`
is scheduled to reload the diff for all active buffers. This causes 2
git processes to be spawned for each open file which can become
noticeable when many files are open

https://github.com/zed-industries/zed/blob/5e32405669d0470baec345073dafffb552a18bae/crates/project/src/git_store.rs#L5179

## Solution

This PR introduces `load_revisions` which uses a single `git cat-file
--batch` command to compute the diff for all files in the same git
process. This prevents the need to sequentially schedule 2 git
subprocesses per open buffer.

I also changed `load_index_text` and `load_commited_text` to rely on
`load_revisions` which simplifies the code.

## Testing

I added a unittest and manually verified that Zed now only runs a single
`git cat-file --batch` command instead of 2 `git show` processes per
open buffer.
On macOS I viewed the currently running git processes using:
```shell
sudo eslogger exec | jq --unbuffered -r '
    select(.event.exec?.target?.executable?.path? | strings | contains("git")) |
    (.event.exec?.args? // []) | join(" ")
  '
```

## Self-Review Checklist:

- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments
- [x] The content adheres to Zed's UI standards
([UX/UI](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
and
[icon](https://github.com/zed-industries/zed/blob/main/crates/icons/README.md)
guidelines)
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

/cc @Veykril

Release Notes:

- Reduced number of git processes for calculating diff of open buffers
when the repo state changes on disk
````

## Parents

- [d564495dde0c344fa54e2432b91680fc604e495c](https://git.cafe/gitcafe/zed/commit/d564495dde0c344fa54e2432b91680fc604e495c?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/bc29bcfe728e3ce158f36b6a1b15f3dff667fe02?format=markdown)
