git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] report lock error in write_index
@ 2025-05-21  8:35 Han Young
  2025-05-21  8:35 ` [PATCH 1/2] read-cache: report lock error when refreshing index Han Young
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Han Young @ 2025-05-21  8:35 UTC (permalink / raw)
  To: git; +Cc: Han Young

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.

The second commit is to provide a more consistent error message in various
commands when writing index failed. Currently, there are 10 uses of
"could not write index", two uses of "unable to write index file" and
"Unable to write index.". Change them to the most used "could not write index".

Han Young (2):
  read-cache: report lock error when refreshing index
  read-cache: unify write index error message

 builtin/am.c         | 2 +-
 builtin/commit.c     | 2 +-
 builtin/merge.c      | 2 +-
 merge-ort-wrappers.c | 2 +-
 read-cache.c         | 2 +-
 5 files changed, 5 insertions(+), 5 deletions(-)

-- 
2.48.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] read-cache: report lock error when refreshing index
  2025-05-21  8:35 [PATCH 0/2] report lock error in write_index Han Young
@ 2025-05-21  8:35 ` Han Young
  2025-05-21  8:35 ` [PATCH 2/2] read-cache: unify write index error message Han Young
  2025-05-21  9:18 ` [PATCH 0/2] report lock error in write_index Han Young
  2 siblings, 0 replies; 4+ messages in thread
From: Han Young @ 2025-05-21  8:35 UTC (permalink / raw)
  To: git; +Cc: Han Young

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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] read-cache: unify write index error message
  2025-05-21  8:35 [PATCH 0/2] report lock error in write_index Han Young
  2025-05-21  8:35 ` [PATCH 1/2] read-cache: report lock error when refreshing index Han Young
@ 2025-05-21  8:35 ` Han Young
  2025-05-21  9:18 ` [PATCH 0/2] report lock error in write_index Han Young
  2 siblings, 0 replies; 4+ messages in thread
From: Han Young @ 2025-05-21  8:35 UTC (permalink / raw)
  To: git; +Cc: Han Young

Currently, there are ten uses of "could not write index", two uses of
"unable to write index file" and two uses of "Unable to write index.".
Change them to the most Change them to the most common phrase.

Signed-off-by: Han Young <hanyang.tony@bytedance.com>
---
 builtin/am.c         | 2 +-
 builtin/commit.c     | 2 +-
 builtin/merge.c      | 2 +-
 merge-ort-wrappers.c | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/builtin/am.c b/builtin/am.c
index e32a3b4c97..69f24df5c0 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -1816,7 +1816,7 @@ static void am_run(struct am_state *state, int resume)
 
 	if (repo_refresh_and_write_index(the_repository, REFRESH_QUIET, 0, 0,
 					 NULL, NULL, NULL) < 0)
-		die(_("unable to write index file"));
+		die(_("could not write index"));
 
 	if (repo_index_has_changes(the_repository, NULL, &sb)) {
 		write_state_bool(state, "dirtyindex", 1);
diff --git a/builtin/commit.c b/builtin/commit.c
index 66bd91fd52..f60f85ea36 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -415,7 +415,7 @@ static const char *prepare_index(const char **argv, const char *prefix,
 				repo_get_git_dir(the_repository));
 		if (cache_tree_update(the_repository->index, WRITE_TREE_SILENT) == 0) {
 			if (reopen_lock_file(&index_lock) < 0)
-				die(_("unable to write index file"));
+				die(_("could not write index"));
 			if (write_locked_index(the_repository->index, &index_lock, 0))
 				die(_("unable to update temporary index"));
 		} else
diff --git a/builtin/merge.c b/builtin/merge.c
index ce90e52fe4..876a2e04f3 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -736,7 +736,7 @@ static int try_merge_strategy(const char *strategy, struct commit_list *common,
 	if (repo_refresh_and_write_index(the_repository, REFRESH_QUIET,
 					 SKIP_IF_UNCHANGED, 0, NULL, NULL,
 					 NULL) < 0)
-		die(_("Unable to write index."));
+		die(_("could not write index"));
 
 	if (!strcmp(strategy, "recursive") || !strcmp(strategy, "subtree") ||
 	    !strcmp(strategy, "ort")) {
diff --git a/merge-ort-wrappers.c b/merge-ort-wrappers.c
index c54d56b344..666ed27437 100644
--- a/merge-ort-wrappers.c
+++ b/merge-ort-wrappers.c
@@ -128,7 +128,7 @@ int merge_ort_generic(struct merge_options *opt,
 
 	if (write_locked_index(opt->repo->index, &lock,
 			       COMMIT_LOCK | SKIP_IF_UNCHANGED))
-		return error(_("Unable to write index."));
+		return error(_("could not write index"));
 
 	return clean ? 0 : 1;
 }
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 0/2] report lock error in write_index
  2025-05-21  8:35 [PATCH 0/2] report lock error in write_index Han Young
  2025-05-21  8:35 ` [PATCH 1/2] read-cache: report lock error when refreshing index Han Young
  2025-05-21  8:35 ` [PATCH 2/2] read-cache: unify write index error message Han Young
@ 2025-05-21  9:18 ` Han Young
  2 siblings, 0 replies; 4+ messages in thread
From: Han Young @ 2025-05-21  9:18 UTC (permalink / raw)
  To: git

On Wed, May 21, 2025 at 4:35 PM Han Young <hanyang.tony@bytedance.com> wrote:

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

One downside of this is the command still prints "could not write index" below
the lock error. The caller can't distinguish between the lock failure and the
the actual writing failure.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-05-21  9:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-21  8:35 [PATCH 0/2] report lock error in write_index Han Young
2025-05-21  8:35 ` [PATCH 1/2] read-cache: report lock error when refreshing index Han Young
2025-05-21  8:35 ` [PATCH 2/2] read-cache: unify write index error message Han Young
2025-05-21  9:18 ` [PATCH 0/2] report lock error in write_index Han Young

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).