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

[PATCH 1/2] read-cache: report lock error when refreshing index

From
Han Young <hanyang.tony@bytedance.com>
Date
May 21, 2025, 08:35 UTC
Message-ID
<20250521083521.6552-2-hanyang.tony@bytedance.com>
In-Reply-To
<20250521083521.6552-1-hanyang.tony@bytedance.com>
In the repo_refresh_and_write_index of read-cache.c, we return -1 to
indicate that writing the index to disk failed.
However, callers do not use this information. Commands such as stash print
  "could not write index"
and then exit, which does not help to discover the exact problem.

We can let repo_hold_locked_index print the error message if the locking failed.

Signed-off-by: Han Young <hanyang.tony@bytedance.com>
---
 read-cache.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/read-cache.c b/read-cache.c
index 73f83a7e7a..874f87d040 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -1485,7 +1485,7 @@ int repo_refresh_and_write_index(struct repository *repo,
 	struct lock_file lock_file = LOCK_INIT;
 	int fd, ret = 0;
 
-	fd = repo_hold_locked_index(repo, &lock_file, 0);
+	fd = repo_hold_locked_index(repo, &lock_file, gentle ? 0 : LOCK_REPORT_ON_ERROR);
 	if (!gentle && fd < 0)
 		return -1;
 	if (refresh_index(repo->index, refresh_flags, pathspec, seen, header_msg))
-- 
2.48.1
Previous: Han YoungNext: Han Young
Message 2 of 4 in “report lock error in write_index”
  1. 0/2 report lock error in write_indexHan Young, May 21, 2025
  2. 1/2 read-cache: report lock error when refreshing indexHan Young, May 21, 2025
  3. 2/2 read-cache: unify write index error messageHan Young, May 21, 2025
  4. Han YoungMay 21, 2025

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.