Skip to content

Wait for the index lock instead of failing

Jun Wu git 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v2 Latest4 patches 1 replyIn review

Changes in v2 from the cover letter

- Explain details more clearly.
- New patch 1: make "git status"'s non-waiting behavior explicit.
- New patch 4: fix "reset" write race, similar to "commit".
- Patch 3 and 4: use "write race" as motivation.

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/4repository: add repo_try_hold_locked_index()builtin/commit.c builtin/describe.c builtin/diff.c +6 more+24 -80 replies
2/4repository: add core.indexLockTimeoutDocumentation/config/core.adoc repository.c repository.h +4 more+84 -10 replies
3/4commit: fix write racebuiltin/commit.c t/t0032-index-lock-timeout.sh+4 -100 replies
4/4reset: fix write racebuiltin/reset.c+4 -30 replies

Reviews trailers per patch

None of the 4 patches has a Reviewed-by or Acked-by.

PatchJunio C HamanoJeff King
1/4Helped-by
2/4
3/4Helped-by
4/4

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v2 thread

Cover letter [PATCH v2 0/4] Wait for the index lock instead of failing

From: Jun Wu <[email protected]>

When another process holds the index lock, commands like "git add", "git checkout" and "git commit" fail immediately, causing user frustration. This series lets commands that must write the index to wait briefly for the index lock (core.indexLockTimeout, default 1s), to be more user friendly.

"another process that holds the index lock" is often "git status" run periodically by an IDE, or a tool. Today, such tools have 2 choices:
- "git status": risks making "checkout", "commit" fail more often.
- "git --no-optional-locks status": because "status" no longer writes the refreshed stat info, "git --no-optional-locks status" will become slower and slower over time, assuming no other commands refresh the index.

This series aims for the end state that:
- Tool authors can use background "git status" just fine, and "status" won't become slower. They can still use "--no-optional-locks", with no behavior changes.
- End users can run "git commit/checkout" just fine, without seeing command failures due to the index lock.

Conservatively, the new wait behavior disables itself for commands with write race (typically "read (index) -> lock -> (no reload) -> write"), so those racy commands stay unchanged, instead of getting a larger race window (between "read" and "lock"). This series fixes the write races for "commit" and "reset" so the two commands, together with other commands that already properly lock before reading, all get the new wait behavior. The trade-off is that "commit" now lstat() the working tree under the index lock.

Changes since v1:
- Explain details more clearly.
- New patch 1: make "git status"'s non-waiting behavior explicit.
- New patch 4: fix "reset" write race, similar to "commit".
- Patch 3 and 4: use "write race" as motivation.

Jun Wu (4):
repository: add repo_try_hold_locked_index()
repository: add core.indexLockTimeout
commit: fix write race
reset: fix write race

 Documentation/config/core.adoc |  6 +++++
 builtin/commit.c               | 11 +++------
 builtin/describe.c             |  4 ++--
 builtin/diff.c                 |  2 +-
 builtin/merge.c                |  2 +-
 builtin/rebase.c               |  2 +-
 builtin/reset.c                |  7 +++---
 repository.c                   | 33 ++++++++++++++++++++++++++
 repository.h                   | 11 +++++++++
 sequencer.c                    |  2 +-
 t/meson.build                  |  1 +
 t/t0031-lockfile-pid.sh        |  4 ++++
 t/t0032-index-lock-timeout.sh  | 42 ++++++++++++++++++++++++++++++++++
 t/t7400-submodule-basic.sh     |  1 +
 wt-status.c                    |  2 +-
 15 files changed, 112 insertions(+), 18 deletions(-)
 create mode 100755 t/t0032-index-lock-timeout.sh

base-commit: c51408889c3b372814bc20b9431c3b74d0d268eb

Signature · 1 line
2.56.0