# Status would take index.lock only when it has something to write

_Mihai Cosma's series also fixes a bug where status can silently revert a concurrent 'git add' when index.skipHash is enabled._

Section: Patches. Edition of 2026-10-23. Written by an AI editor from the thread "[PATCH 0/2] status: stop holding index.lock while collecting" (5 messages): https://gitlist.dev/t/66633

Mihai Cosma's problem is that background 'git status' runs from editors and shell prompts take index.lock before collecting and hold it to the end, even when nothing needs writing. A concurrent 'git add' or 'git commit' then fails with "index.lock: File exists".

Patch 1 fixes a separate bug. Since ee1f0c242e (read-cache: add index.skipHash config option), the index trailer checksum can be all zeros, and feature.manyFiles and Scalar turn that on. The check that stops status from overwriting an index updated by another process then passes for any index. A 'git add' landing between status reading the index and taking the lock can be silently reverted, including on 2.56.0. Cosma's fix compares the index file's stat data when the recorded checksum is null, ignoring ctime. He says it applies to maint and can go in alone.

Patch 2 adds repo_lock_and_update_index_if_able(), which takes the lock only if the index has something to write and is called after collecting. It builds on the earlier decision to move the write after wt_status_collect().

This overlaps with Jun Wu's series, which adds an index lock timeout so 'add' and 'commit' can wait. Cosma says the two conflict only on the lock call in cmd_status() that Wu's 1/4 renames, so whichever lands second can adapt. On top of Wu's v2, with status looping in a gcc checkout, the slowest of 200 'git add' runs fell from 1020 ms to 160 ms. One run had previously hit Wu's 1-second timeout.

No review comments appear in the excerpts.
