{"thread":{"id":"63492","subject":"[PATCH 0/2] report lock error in write_index","startedAt":"2025-05-21T08:35:29Z","lastAt":"2025-05-21T09:18:39Z","messageCount":4,"participants":["Han Young"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"518551","messageId":"20250521083521.6552-1-hanyang.tony@bytedance.com","threadId":"63492","inReplyTo":null,"subject":"[PATCH 0/2] report lock error in write_index","fromName":"Han Young","fromEmail":"hanyang.tony@bytedance.com","sentAt":"2025-05-21T08:35:19Z","receivedAt":"2025-05-21T08:35:29Z","isPatch":true,"sender":{"key":"hanyang.tony@bytedance.com","avatar":"https://avatars.githubusercontent.com/u/108711387?v=4"},"body":"In the repo_refresh_and_write_index of read-cache.c, we return -1 to\nindicate that writing the index to disk failed.\nHowever, callers do not use this information. Commands such as stash print\n  \"could not write index\"\nand then exit, which does not help to discover the exact problem.\n\nWe can let repo_hold_locked_index print the error message if the locking\nfailed.\n\nThe second commit is to provide a more consistent error message in various\ncommands when writing index failed. Currently, there are 10 uses of\n\"could not write index\", two uses of \"unable to write index file\" and\n\"Unable to write index.\". Change them to the most used \"could not write index\".\n\nHan Young (2):\n  read-cache: report lock error when refreshing index\n  read-cache: unify write index error message\n\n builtin/am.c         | 2 +-\n builtin/commit.c     | 2 +-\n builtin/merge.c      | 2 +-\n merge-ort-wrappers.c | 2 +-\n read-cache.c         | 2 +-\n 5 files changed, 5 insertions(+), 5 deletions(-)\n\n-- \n2.48.1\n\n"},{"id":"518552","messageId":"20250521083521.6552-2-hanyang.tony@bytedance.com","threadId":"63492","inReplyTo":"20250521083521.6552-1-hanyang.tony@bytedance.com","subject":"[PATCH 1/2] read-cache: report lock error when refreshing index","fromName":"Han Young","fromEmail":"hanyang.tony@bytedance.com","sentAt":"2025-05-21T08:35:20Z","receivedAt":"2025-05-21T08:35:54Z","isPatch":true,"sender":{"key":"hanyang.tony@bytedance.com","avatar":"https://avatars.githubusercontent.com/u/108711387?v=4"},"body":"In the repo_refresh_and_write_index of read-cache.c, we return -1 to\nindicate that writing the index to disk failed.\nHowever, callers do not use this information. Commands such as stash print\n  \"could not write index\"\nand then exit, which does not help to discover the exact problem.\n\nWe can let repo_hold_locked_index print the error message if the locking\nfailed.\n\nSigned-off-by: Han Young <hanyang.tony@bytedance.com>\n---\n read-cache.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/read-cache.c b/read-cache.c\nindex 73f83a7e7a..874f87d040 100644\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -1485,7 +1485,7 @@ int repo_refresh_and_write_index(struct repository *repo,\n \tstruct lock_file lock_file = LOCK_INIT;\n \tint fd, ret = 0;\n \n-\tfd = repo_hold_locked_index(repo, &lock_file, 0);\n+\tfd = repo_hold_locked_index(repo, &lock_file, gentle ? 0 : LOCK_REPORT_ON_ERROR);\n \tif (!gentle && fd < 0)\n \t\treturn -1;\n \tif (refresh_index(repo->index, refresh_flags, pathspec, seen, header_msg))\n-- \n2.48.1\n\n"},{"id":"518553","messageId":"20250521083521.6552-3-hanyang.tony@bytedance.com","threadId":"63492","inReplyTo":"20250521083521.6552-1-hanyang.tony@bytedance.com","subject":"[PATCH 2/2] read-cache: unify write index error message","fromName":"Han Young","fromEmail":"hanyang.tony@bytedance.com","sentAt":"2025-05-21T08:35:21Z","receivedAt":"2025-05-21T08:35:58Z","isPatch":true,"sender":{"key":"hanyang.tony@bytedance.com","avatar":"https://avatars.githubusercontent.com/u/108711387?v=4"},"body":"Currently, there are ten uses of \"could not write index\", two uses of\n\"unable to write index file\" and two uses of \"Unable to write index.\".\nChange them to the most Change them to the most common phrase.\n\nSigned-off-by: Han Young <hanyang.tony@bytedance.com>\n---\n builtin/am.c         | 2 +-\n builtin/commit.c     | 2 +-\n builtin/merge.c      | 2 +-\n merge-ort-wrappers.c | 2 +-\n 4 files changed, 4 insertions(+), 4 deletions(-)\n\ndiff --git a/builtin/am.c b/builtin/am.c\nindex e32a3b4c97..69f24df5c0 100644\n--- a/builtin/am.c\n+++ b/builtin/am.c\n@@ -1816,7 +1816,7 @@ static void am_run(struct am_state *state, int resume)\n \n \tif (repo_refresh_and_write_index(the_repository, REFRESH_QUIET, 0, 0,\n \t\t\t\t\t NULL, NULL, NULL) < 0)\n-\t\tdie(_(\"unable to write index file\"));\n+\t\tdie(_(\"could not write index\"));\n \n \tif (repo_index_has_changes(the_repository, NULL, &sb)) {\n \t\twrite_state_bool(state, \"dirtyindex\", 1);\ndiff --git a/builtin/commit.c b/builtin/commit.c\nindex 66bd91fd52..f60f85ea36 100644\n--- a/builtin/commit.c\n+++ b/builtin/commit.c\n@@ -415,7 +415,7 @@ static const char *prepare_index(const char **argv, const char *prefix,\n \t\t\t\trepo_get_git_dir(the_repository));\n \t\tif (cache_tree_update(the_repository->index, WRITE_TREE_SILENT) == 0) {\n \t\t\tif (reopen_lock_file(&index_lock) < 0)\n-\t\t\t\tdie(_(\"unable to write index file\"));\n+\t\t\t\tdie(_(\"could not write index\"));\n \t\t\tif (write_locked_index(the_repository->index, &index_lock, 0))\n \t\t\t\tdie(_(\"unable to update temporary index\"));\n \t\t} else\ndiff --git a/builtin/merge.c b/builtin/merge.c\nindex ce90e52fe4..876a2e04f3 100644\n--- a/builtin/merge.c\n+++ b/builtin/merge.c\n@@ -736,7 +736,7 @@ static int try_merge_strategy(const char *strategy, struct commit_list *common,\n \tif (repo_refresh_and_write_index(the_repository, REFRESH_QUIET,\n \t\t\t\t\t SKIP_IF_UNCHANGED, 0, NULL, NULL,\n \t\t\t\t\t NULL) < 0)\n-\t\tdie(_(\"Unable to write index.\"));\n+\t\tdie(_(\"could not write index\"));\n \n \tif (!strcmp(strategy, \"recursive\") || !strcmp(strategy, \"subtree\") ||\n \t    !strcmp(strategy, \"ort\")) {\ndiff --git a/merge-ort-wrappers.c b/merge-ort-wrappers.c\nindex c54d56b344..666ed27437 100644\n--- a/merge-ort-wrappers.c\n+++ b/merge-ort-wrappers.c\n@@ -128,7 +128,7 @@ int merge_ort_generic(struct merge_options *opt,\n \n \tif (write_locked_index(opt->repo->index, &lock,\n \t\t\t       COMMIT_LOCK | SKIP_IF_UNCHANGED))\n-\t\treturn error(_(\"Unable to write index.\"));\n+\t\treturn error(_(\"could not write index\"));\n \n \treturn clean ? 0 : 1;\n }\n-- \n2.48.1\n\n"},{"id":"518554","messageId":"CAG1j3zHUeGWQ-AD7bpJ=QBVAviBTcPi1yDRfM043+6sY4qkq9Q@mail.gmail.com","threadId":"63492","inReplyTo":"20250521083521.6552-1-hanyang.tony@bytedance.com","subject":"Re: [PATCH 0/2] report lock error in write_index","fromName":"Han Young","fromEmail":"hanyang.tony@bytedance.com","sentAt":"2025-05-21T09:18:16Z","receivedAt":"2025-05-21T09:18:39Z","isPatch":true,"sender":{"key":"hanyang.tony@bytedance.com","avatar":"https://avatars.githubusercontent.com/u/108711387?v=4"},"body":"On Wed, May 21, 2025 at 4:35 PM Han Young <hanyang.tony@bytedance.com> wrote:\n\n> We can let repo_hold_locked_index print the error message if the locking\n> failed.\n\nOne downside of this is the command still prints \"could not write index\" below\nthe lock error. The caller can't distinguish between the lock failure and the\nthe actual writing failure.\n"}]}