desktop / desktop/desktop

Read-only git operations acquire unnecessary index locks (GIT_OPTIONAL_LOCKS)

Open
#22,047 2 comments 0 reactions 0 assignees View on GitHub
enhancement investigation-needed
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.