Read-only git operations acquire unnecessary index locks (GIT_OPTIONAL_LOCKS)
- Dominant language
- TypeScript
- Stars
- 21.8k
- Forks
- 10.5k
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 25
Description
### The problem
Desktop runs multiple git commands concurrently (e.g., background fetch + foreground status + sidebar indicator refresh). Read-only operations like `diff`, `log`, and `for-each-ref` acquire the index lock by default, even though they don't modify the index. This causes lock contention and occasional failures when concurrent operations compete for the lock.
### Proposed solution
Set `GIT_OPTIONAL_LOCKS=0` environment variable for read-only git operations:
- `git diff` (in `diff.ts`)
- `git log` (in `log.ts`)
- `git for-each-ref` (in `for-each-ref.ts`)
From git documentation:
> When set to 0, Git will complete any requested operation without performing any optional sub-operations that require taking a lock. For example, this will prevent `git status` from refreshing the index as a side effect.
Desktop already sets `--no-optional-locks` on `git status`. This extends the same optimization to other read-only operations.
Additionally, `for-each-ref` can benefit from `--count=10000` to cap output on repos with massive ref counts.
### Release version
3.5.8 (x64)
### Operating system
All platforms
Implementation in PR #22043.
Contributor guide
Assessment
This issue has not been assessed yet.