git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
JWJun Wu <quark.zju@gmail.com>
Date
Oct 17, 2026, 07:32 UTC
Message-ID
<20261017073231.3357477-1-quark.zju@gmail.com>
In-Reply-To
<20261013172315.2997446-1-quark.zju@gmail.com>
From: Jun Wu <quark@meta.com>

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
-- 
2.56.0
Previous: Jeff KingNext: Jun Wu
Message 15 of 20 in “Add a way to wait for index lock”
  1. 0/2 Add a way to wait for index lockJun Wu, Oct 13, 2026
  2. 1/2 repository: add core.indexLockTimeoutJun Wu, Oct 13, 2026
  3. D. Ben KnobleOct 13, 2026
  4. Jun WuOct 14, 2026
  5. D. Ben KnobleOct 14, 2026
  6. Junio C HamanoOct 13, 2026
  7. Jun WuOct 14, 2026
  8. Ben KnobleOct 19, 2026
  9. 2/2 commit: lock index before readingJun Wu, Oct 13, 2026
  10. Jeff KingOct 14, 2026
  11. Jun WuOct 15, 2026
  12. Junio C HamanoOct 13, 2026
  13. Jun WuOct 14, 2026
  14. Jeff KingOct 14, 2026
  15. 0/4 Wait for the index lock instead of failingJun Wu, Oct 17, 2026
  16. 1/4 repository: add repo_try_hold_locked_index()Jun Wu, Oct 17, 2026
  17. 2/4 repository: add core.indexLockTimeoutJun Wu, Oct 17, 2026
  18. 3/4 commit: fix write raceJun Wu, Oct 17, 2026
  19. 4/4 reset: fix write raceJun Wu, Oct 17, 2026
  20. Mihai CosmaOct 22, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.