🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.git
16 messages
16 total messages Started by "Thomas Bachem via GitGitGadget" Sat, 10 Oct 2026 10:13
[PATCH v7 0/2] rerere: wait for MERGE_RR.lock, but not in auto maintenance
#254
Author: "Thomas Bachem via GitGitGadget"
Date: Sat, 10 Oct 2026 10:13
186 lines
16778 bytes
A rebase dies at a conflict when a background "git rerere gc" holds
MERGE_RR.lock at that moment. With the first patch, rerere waits for the
lock instead of dying at once. With the second, the "git rerere gc" started
by auto maintenance does nothing while the lock is held.

For v7 I took Patrick's suggestions on patches 2 and 3. Changes since v6:

 * Patch 3, which let a command that stops at a conflict go on without
   rerere, is gone. It can come back if users still run into the lock
   (Patrick).

 * Patch 2's log message is Patrick's, plus a last paragraph on why the
   option is hidden.

 * rerere_gc() takes its own flags, enum rerere_gc_flags, with
   RERERE_GC_NOWAIT (Patrick).

 * The comment in setup_rerere() no longer says who passes RERERE_NOWAIT,
   and the one on RERERE_NOWAIT now says that setup_rerere() then returns -1
   as if rerere were disabled (Patrick).

 * "git rerere gc --skip-locked" without a held lock is a test of its own
   (Patrick).

Thomas Bachem (2):
  rerere: wait for MERGE_RR.lock before giving up
  rerere: add "gc --skip-locked" for auto maintenance

 Documentation/config/rerere.adoc | 10 ++++
 builtin/gc.c                     |  4 +-
 builtin/rerere.c                 | 10 +++-
 rerere.c                         | 38 ++++++++++++---
 rerere.h                         | 11 ++++-
 t/t4200-rerere.sh                | 79 ++++++++++++++++++++++++++++++++
 t/t7900-maintenance.sh           | 25 +++++++++-
 7 files changed, 165 insertions(+), 12 deletions(-)


base-commit: 34f06850c16c7f7ac822b1adc71354f11b0f2ca3
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-2214%2Fthomasbachem%2Frerere-gc-lock-v7
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2214/thomasbachem/rerere-gc-lock-v7
Pull-Request: https://github.com/gitgitgadget/git/pull/2214

Range-diff vs v6:

 1:  3dc3d02f12 = 1:  3dc3d02f12 rerere: wait for MERGE_RR.lock before giving up
 2:  2ef141410a ! 2:  0002881196 rerere: add "gc --skip-locked" for auto maintenance
     @@ Metadata
       ## Commit message ##
          rerere: add "gc --skip-locked" for auto maintenance
      
     -    Since the previous commit, "git rerere gc" waits for MERGE_RR.lock
     -    like every other command that takes it, and fails only if the wait
     -    times out. That suits a user who runs it by hand and wants to know
     -    when nothing was pruned. But the user did not ask for the gc that auto
     -    maintenance starts after a commit, and the next commit starts another
     -    one.
     +    Starting with the preceding commit, processes that want to acquire
     +    the rerere cache's MERGE_RR.lock by default know to wait up to one
     +    second until that lock has been released. This is a sensible default
     +    for many commands that happen to write rerere entries, as we would
     +    otherwise die immediately when the lock is taken by another process.
      
     -    So add "--skip-locked", with which "git rerere gc" quietly does
     -    nothing while the lock is held, and pass it from
     -    "git maintenance run --auto" and "git gc --auto". Only these two need
     -    the option, so hide it and leave it undocumented, like the
     -    "--skip-foreground-tasks" that "git maintenance run" passes to
     -    "git gc". A run without it, from the command line or a maintenance
     -    schedule, still waits for the lock and fails if the wait times out.
     +    But for repository maintenance it's a bit more complicated, as there
     +    are two cases that we have to care about. When the user explicitly
     +    asks us to garbage collect rerere entries via `git rerere gc` they
     +    probably want us to try our best to perform this operation. It's thus
     +    sensible to wait for the lock and then die if we weren't able to
     +    acquire it.
      
     +    But we also prune rerere entries as part of auto-maintenance, which is
     +    only executed on a best-effort basis anyway. Delaying the whole
     +    operation to acquire the lock is somewhat heavy-handed, and neither
     +    does it make sense to die in case we haven't been able to garbage
     +    collect rerere entries as that would impede other housekeeping tasks.
     +    Furthermore, it's totally fine to skip the operation when the rerere
     +    cache is locked already, as we will retry during the next run anyway.
     +
     +    But we do not have an easy way to tell `git rerere gc` to skip the
     +    operation in case the cache is locked already. Add a new
     +    "--skip-locked" flag to plug that gap and have auto-maintenance pass
     +    that flag.
     +
     +    Only auto-maintenance needs that flag, so hide it, like the
     +    "--skip-foreground-tasks" flag that `git maintenance run` passes to
     +    `git gc`.
     +
     +    Helped-by: Patrick Steinhardt <ps@pks.im>
          Assisted-by: Claude Fable 5.1
          Signed-off-by: Thomas Bachem <mail@thomasbachem.com>
      
     @@ builtin/rerere.c: int cmd_rerere(int argc,
       	} else if (!strcmp(argv[0], "gc"))
      -		rerere_gc(the_repository, &merge_rr);
      +		rerere_gc(the_repository, &merge_rr,
     -+			  skip_locked ? RERERE_NOWAIT : 0);
     ++			  skip_locked ? RERERE_GC_NOWAIT : 0);
       	else if (!strcmp(argv[0], "status")) {
       		if (setup_rerere(the_repository, &merge_rr,
       				 flags | RERERE_READONLY) < 0)
     @@ rerere.c: int setup_rerere(struct repository *r, struct string_list *merge_rr, i
       		/*
       		 * Another process may hold the lock for a while, e.g.
       		 * "git rerere gc" while it prunes rr-cache, so wait for
     --		 * it instead of dying right away.
     -+		 * it instead of dying right away.  The gc of an automatic
     -+		 * maintenance run does not wait, since skipping one of
     -+		 * its runs costs nothing.
     + 		 * it instead of dying right away.
       		 */
      +		if (flags & RERERE_NOWAIT) {
      +			lock_flags = 0;
     @@ rerere.c: out:
       }
       
      -void rerere_gc(struct repository *r, struct string_list *rr)
     -+void rerere_gc(struct repository *r, struct string_list *rr, int flags)
     ++void rerere_gc(struct repository *r, struct string_list *rr,
     ++	       enum rerere_gc_flags flags)
       {
       	struct string_list to_remove = STRING_LIST_INIT_DUP;
       	DIR *dir;
     @@ rerere.c: void rerere_gc(struct repository *r, struct string_list *rr)
       	struct strbuf buf = STRBUF_INIT;
       
      -	if (setup_rerere(r, rr, 0) < 0)
     -+	if (setup_rerere(r, rr, flags) < 0)
     ++	if (setup_rerere(r, rr,
     ++			 (flags & RERERE_GC_NOWAIT) ? RERERE_NOWAIT : 0) < 0)
       		return;
       
       	rerere_gc_cutoffs(r, &cutoff_resolve, &cutoff_noresolve);
     @@ rerere.h: struct repository;
       #define RERERE_AUTOUPDATE   01
       #define RERERE_NOAUTOUPDATE 02
       #define RERERE_READONLY     04
     -+/* Take MERGE_RR.lock only if it is free, and return quietly otherwise */
     ++/* If MERGE_RR.lock is taken, return -1 as if rerere were disabled */
      +#define RERERE_NOWAIT       010
       
       /*
     @@ rerere.h: const char *rerere_path(struct strbuf *buf, const struct rerere_id *,
       int rerere_remaining(struct repository *, struct string_list *);
       void rerere_clear(struct repository *, struct string_list *);
      -void rerere_gc(struct repository *, struct string_list *);
     -+void rerere_gc(struct repository *, struct string_list *, int);
     ++
     ++enum rerere_gc_flags {
     ++	/* Skip the operation in case the MERGE_RR.lock is already taken. */
     ++	RERERE_GC_NOWAIT = (1 << 0),
     ++};
     ++
     ++void rerere_gc(struct repository *, struct string_list *,
     ++	       enum rerere_gc_flags flags);
       
       /*
        * Check whether garbage collection for rerere entries is needed, which is
     @@ t/t4200-rerere.sh: test_expect_success 'old records rest in peace' '
      +	>.git/MERGE_RR.lock &&
      +	git rerere gc --skip-locked 2>err &&
      +	test_must_be_empty err &&
     -+	test_path_is_file $rr2/preimage &&
     ++	test_path_is_file $rr2/preimage
     ++'
     ++
     ++test_expect_success 'gc --skip-locked prunes while MERGE_RR is not locked' '
     ++	mkdir -p $rr2 &&
     ++	echo Hello >$rr2/preimage &&
     ++	test-tool chmtime =$just_over_15_days_ago $rr2/preimage &&
      +
     -+	rm .git/MERGE_RR.lock &&
      +	git rerere gc --skip-locked &&
      +	test_path_is_missing $rr2/preimage
      +'
 3:  cd018289bb < -:  ---------- rerere: go on at a conflict when the lock stays busy

-- 
gitgitgadget
[PATCH v7 1/2] rerere: wait for MERGE_RR.lock before giving up
#255
Author: "Thomas Bachem via GitGitGadget"
Date: Sat, 10 Oct 2026 10:13
158 lines
14133 bytes
From: Thomas Bachem <mail@thomasbachem.com>

setup_rerere() takes MERGE_RR.lock with LOCK_DIE_ON_ERROR, so of two
processes that want it at the same time the second one dies. That
used to be rare. Since 452b12c2e0 (builtin/maintenance: use
"geometric" strategy by default, 2026-02-24) the auto maintenance
after a commit runs "git rerere gc" whenever rr-cache has enough
stale entries, and the gc holds the lock while it prunes.

A rebase whose next pick conflicts while that happens dies inside
repo_rerere(), before the sequencer has written the state that
"git rebase --continue" needs. Every later "git rebase --continue"
then fails with "you have staged changes in your working tree".

Wait for the lock for up to rerere.lockTimeout milliseconds, 1000 by
default, and only then fail as before. Pruning a few thousand entries
takes well under a second, so the default covers a rebase that runs
into the gc.

Assisted-by: Claude Fable 5.1
Signed-off-by: Thomas Bachem <mail@thomasbachem.com>
---
 Documentation/config/rerere.adoc |  8 +++++
 rerere.c                         | 22 ++++++++++---
 t/t4200-rerere.sh                | 53 ++++++++++++++++++++++++++++++++
 3 files changed, 78 insertions(+), 5 deletions(-)

diff --git a/Documentation/config/rerere.adoc b/Documentation/config/rerere.adoc
index 3a78b5ebb1..30e827f32b 100644
--- a/Documentation/config/rerere.adoc
+++ b/Documentation/config/rerere.adoc
@@ -10,3 +10,11 @@ rerere.enabled::
 	enabled if there is an `rr-cache` directory under the
 	`$GIT_DIR`, e.g. if "rerere" was previously used in the
 	repository.
+
+rerere.lockTimeout::
+	The length of time, in milliseconds, to wait for the rerere
+	lock when another process holds it, typically a background
+	`git rerere gc`.  Value 0 means not to wait at all; -1 means
+	to wait indefinitely.  Default is 1000 (i.e., wait for 1
+	second).  When the time is up, the command fails as it does
+	for any other lock it cannot take.
diff --git a/rerere.c b/rerere.c
index 1c3745d9e3..64fac07c71 100644
--- a/rerere.c
+++ b/rerere.c
@@ -33,6 +33,9 @@ static int rerere_enabled = -1;
 /* automatically update cleanly resolved paths to the index */
 static int rerere_autoupdate;
 
+/* how long to wait for MERGE_RR.lock, in milliseconds */
+static int rerere_lock_timeout_ms = 1000;
+
 #define RR_HAS_POSTIMAGE 1
 #define RR_HAS_PREIMAGE 2
 struct rerere_dir {
@@ -850,6 +853,8 @@ static void git_rerere_config(void)
 {
 	repo_config_get_bool(the_repository, "rerere.enabled", &rerere_enabled);
 	repo_config_get_bool(the_repository, "rerere.autoupdate", &rerere_autoupdate);
+	repo_config_get_int(the_repository, "rerere.locktimeout",
+			    &rerere_lock_timeout_ms);
 	repo_config(the_repository, git_default_config, NULL);
 }
 
@@ -882,12 +887,19 @@ int setup_rerere(struct repository *r, struct string_list *merge_rr, int flags)
 
 	if (flags & (RERERE_AUTOUPDATE|RERERE_NOAUTOUPDATE))
 		rerere_autoupdate = !!(flags & RERERE_AUTOUPDATE);
-	if (flags & RERERE_READONLY)
+	if (flags & RERERE_READONLY) {
 		fd = 0;
-	else
-		fd = repo_hold_lock_file_for_update(r, &write_lock,
-						    git_path_merge_rr(r),
-						    LOCK_DIE_ON_ERROR);
+	} else {
+		/*
+		 * Another process may hold the lock for a while, e.g.
+		 * "git rerere gc" while it prunes rr-cache, so wait for
+		 * it instead of dying right away.
+		 */
+		fd = repo_hold_lock_file_for_update_timeout(r, &write_lock,
+							    git_path_merge_rr(r),
+							    LOCK_DIE_ON_ERROR,
+							    rerere_lock_timeout_ms);
+	}
 	read_rr(r, merge_rr);
 	return fd;
 }
diff --git a/t/t4200-rerere.sh b/t/t4200-rerere.sh
index 7bb601e117..7bd92235dc 100755
--- a/t/t4200-rerere.sh
+++ b/t/t4200-rerere.sh
@@ -242,6 +242,59 @@ test_expect_success 'old records rest in peace' '
 	test_path_is_missing $rr2/preimage
 '
 
+test_expect_success 'a held lock is waited out within rerere.lockTimeout' '
+	git reset --hard &&
+	rm -rf $rr &&
+	test_when_finished "rm -f .git/MERGE_RR.lock" &&
+	>.git/MERGE_RR.lock &&
+	{
+		( sleep 1 && rm -f .git/MERGE_RR.lock ) &
+	} &&
+	test_must_fail git -c rerere.lockTimeout=5000 merge first 2>err &&
+	wait &&
+	test_grep ! "MERGE_RR" err &&
+	test_grep "^=======\$" $rr/preimage
+'
+
+test_expect_success 'merge fails once rerere.lockTimeout is up' '
+	git reset --hard &&
+	rm -rf $rr &&
+	test_when_finished "rm -f .git/MERGE_RR.lock" &&
+	>.git/MERGE_RR.lock &&
+	test_must_fail git -c rerere.lockTimeout=0 merge first 2>err &&
+	test_grep "Unable to create" err &&
+	test_grep "^=======\$" a1 &&
+	test_path_is_missing $rr/preimage
+'
+
+test_expect_success 'rerere, forget, clear and gc fail on a lock they cannot take' '
+	test_when_finished "rm -f .git/MERGE_RR.lock" &&
+	>.git/MERGE_RR.lock &&
+	test_must_fail git -c rerere.lockTimeout=0 rerere 2>err &&
+	test_grep "Unable to create" err &&
+	test_must_fail git -c rerere.lockTimeout=0 rerere forget a1 2>err &&
+	test_grep "Unable to create" err &&
+	test_must_fail git -c rerere.lockTimeout=0 rerere clear 2>err &&
+	test_grep "Unable to create" err &&
+	test_must_fail git -c rerere.lockTimeout=0 rerere gc 2>err &&
+	test_grep "Unable to create" err
+'
+
+test_expect_success 'rebase --abort fails on a lock it cannot take' '
+	git reset --hard &&
+	git checkout -b lock-held-abort third &&
+	test_when_finished "git checkout third && git branch -D lock-held-abort" &&
+	test_must_fail git rebase first &&
+	test_when_finished "rm -f .git/MERGE_RR.lock" &&
+	>.git/MERGE_RR.lock &&
+	test_must_fail git -c rerere.lockTimeout=0 rebase --abort 2>err &&
+	test_grep "Unable to create" err &&
+	test_path_is_dir .git/rebase-merge &&
+	rm .git/MERGE_RR.lock &&
+	git rebase --abort &&
+	test_path_is_missing .git/rebase-merge
+'
+
 rerere_gc_custom_expiry_test () {
 	five_days="$1" right_now="$2"
 	test_expect_success "rerere gc with custom expiry ($five_days, $right_now)" '
-- 
gitgitgadget
[PATCH v7 2/2] rerere: add "gc --skip-locked" for auto maintenance
#253
Author: "Thomas Bachem via GitGitGadget"
Date: Sat, 10 Oct 2026 10:13
283 lines
18661 bytes
From: Thomas Bachem <mail@thomasbachem.com>

Starting with the preceding commit, processes that want to acquire
the rerere cache's MERGE_RR.lock by default know to wait up to one
second until that lock has been released. This is a sensible default
for many commands that happen to write rerere entries, as we would
otherwise die immediately when the lock is taken by another process.

But for repository maintenance it's a bit more complicated, as there
are two cases that we have to care about. When the user explicitly
asks us to garbage collect rerere entries via `git rerere gc` they
probably want us to try our best to perform this operation. It's thus
sensible to wait for the lock and then die if we weren't able to
acquire it.

But we also prune rerere entries as part of auto-maintenance, which is
only executed on a best-effort basis anyway. Delaying the whole
operation to acquire the lock is somewhat heavy-handed, and neither
does it make sense to die in case we haven't been able to garbage
collect rerere entries as that would impede other housekeeping tasks.
Furthermore, it's totally fine to skip the operation when the rerere
cache is locked already, as we will retry during the next run anyway.

But we do not have an easy way to tell `git rerere gc` to skip the
operation in case the cache is locked already. Add a new
"--skip-locked" flag to plug that gap and have auto-maintenance pass
that flag.

Only auto-maintenance needs that flag, so hide it, like the
"--skip-foreground-tasks" flag that `git maintenance run` passes to
`git gc`.

Helped-by: Patrick Steinhardt <ps@pks.im>
Assisted-by: Claude Fable 5.1
Signed-off-by: Thomas Bachem <mail@thomasbachem.com>
---
 Documentation/config/rerere.adoc |  4 +++-
 builtin/gc.c                     |  4 +++-
 builtin/rerere.c                 | 10 ++++++++--
 rerere.c                         | 20 ++++++++++++++++----
 rerere.h                         | 11 ++++++++++-
 t/t4200-rerere.sh                | 26 ++++++++++++++++++++++++++
 t/t7900-maintenance.sh           | 25 ++++++++++++++++++++++++-
 7 files changed, 90 insertions(+), 10 deletions(-)

diff --git a/Documentation/config/rerere.adoc b/Documentation/config/rerere.adoc
index 30e827f32b..80c38ee951 100644
--- a/Documentation/config/rerere.adoc
+++ b/Documentation/config/rerere.adoc
@@ -17,4 +17,6 @@ rerere.lockTimeout::
 	`git rerere gc`.  Value 0 means not to wait at all; -1 means
 	to wait indefinitely.  Default is 1000 (i.e., wait for 1
 	second).  When the time is up, the command fails as it does
-	for any other lock it cannot take.
+	for any other lock it cannot take.  A `git rerere gc` run by
+	`git maintenance run --auto` or `git gc --auto` does not wait
+	and does nothing while the lock is held.
diff --git a/builtin/gc.c b/builtin/gc.c
index 57a3520263..7ad3987b71 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -385,12 +385,14 @@ out:
 	return should_prune;
 }
 
-static int maintenance_task_rerere_gc(struct maintenance_run_opts *opts UNUSED,
+static int maintenance_task_rerere_gc(struct maintenance_run_opts *opts,
 				      struct gc_config *cfg UNUSED)
 {
 	struct child_process rerere_cmd = CHILD_PROCESS_INIT;
 	rerere_cmd.git_cmd = 1;
 	strvec_pushl(&rerere_cmd.args, "rerere", "gc", NULL);
+	if (opts->auto_flag)
+		strvec_push(&rerere_cmd.args, "--skip-locked");
 	return run_command(&rerere_cmd);
 }
 
diff --git a/builtin/rerere.c b/builtin/rerere.c
index a056cb791b..91cb3c8668 100644
--- a/builtin/rerere.c
+++ b/builtin/rerere.c
@@ -56,16 +56,21 @@ int cmd_rerere(int argc,
 	       struct repository *repo UNUSED)
 {
 	struct string_list merge_rr = STRING_LIST_INIT_DUP;
-	int autoupdate = -1, flags = 0;
+	int autoupdate = -1, skip_locked = 0, flags = 0;
 
 	struct option options[] = {
 		OPT_SET_INT(0, "rerere-autoupdate", &autoupdate,
 			N_("register clean resolutions in index"), 1),
+		OPT_HIDDEN_BOOL(0, "skip-locked", &skip_locked,
+			N_("skip gc while another process holds the lock")),
 		OPT_END(),
 	};
 
 	argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
 
+	if (skip_locked && (argc < 1 || strcmp(argv[0], "gc")))
+		die(_("the option '%s' requires '%s'"), "--skip-locked", "gc");
+
 	repo_config(the_repository, git_xmerge_config, NULL);
 
 	if (autoupdate == 1)
@@ -94,7 +99,8 @@ int cmd_rerere(int argc,
 	if (!strcmp(argv[0], "clear")) {
 		rerere_clear(the_repository, &merge_rr);
 	} else if (!strcmp(argv[0], "gc"))
-		rerere_gc(the_repository, &merge_rr);
+		rerere_gc(the_repository, &merge_rr,
+			  skip_locked ? RERERE_GC_NOWAIT : 0);
 	else if (!strcmp(argv[0], "status")) {
 		if (setup_rerere(the_repository, &merge_rr,
 				 flags | RERERE_READONLY) < 0)
diff --git a/rerere.c b/rerere.c
index 64fac07c71..889ec700dd 100644
--- a/rerere.c
+++ b/rerere.c
@@ -887,18 +887,28 @@ int setup_rerere(struct repository *r, struct string_list *merge_rr, int flags)
 
 	if (flags & (RERERE_AUTOUPDATE|RERERE_NOAUTOUPDATE))
 		rerere_autoupdate = !!(flags & RERERE_AUTOUPDATE);
+	if ((flags & RERERE_READONLY) && (flags & RERERE_NOWAIT))
+		BUG("RERERE_NOWAIT does not apply with RERERE_READONLY");
 	if (flags & RERERE_READONLY) {
 		fd = 0;
 	} else {
+		int lock_flags = LOCK_DIE_ON_ERROR;
+		int timeout_ms = rerere_lock_timeout_ms;
+
 		/*
 		 * Another process may hold the lock for a while, e.g.
 		 * "git rerere gc" while it prunes rr-cache, so wait for
 		 * it instead of dying right away.
 		 */
+		if (flags & RERERE_NOWAIT) {
+			lock_flags = 0;
+			timeout_ms = 0;
+		}
 		fd = repo_hold_lock_file_for_update_timeout(r, &write_lock,
 							    git_path_merge_rr(r),
-							    LOCK_DIE_ON_ERROR,
-							    rerere_lock_timeout_ms);
+							    lock_flags, timeout_ms);
+		if (fd < 0)
+			return -1;
 	}
 	read_rr(r, merge_rr);
 	return fd;
@@ -1284,7 +1294,8 @@ out:
 	return needed;
 }
 
-void rerere_gc(struct repository *r, struct string_list *rr)
+void rerere_gc(struct repository *r, struct string_list *rr,
+	       enum rerere_gc_flags flags)
 {
 	struct string_list to_remove = STRING_LIST_INIT_DUP;
 	DIR *dir;
@@ -1294,7 +1305,8 @@ void rerere_gc(struct repository *r, struct string_list *rr)
 	timestamp_t cutoff_resolve;
 	struct strbuf buf = STRBUF_INIT;
 
-	if (setup_rerere(r, rr, 0) < 0)
+	if (setup_rerere(r, rr,
+			 (flags & RERERE_GC_NOWAIT) ? RERERE_NOWAIT : 0) < 0)
 		return;
 
 	rerere_gc_cutoffs(r, &cutoff_resolve, &cutoff_noresolve);
diff --git a/rerere.h b/rerere.h
index feeb0e2c9f..61e986475b 100644
--- a/rerere.h
+++ b/rerere.h
@@ -10,6 +10,8 @@ struct repository;
 #define RERERE_AUTOUPDATE   01
 #define RERERE_NOAUTOUPDATE 02
 #define RERERE_READONLY     04
+/* If MERGE_RR.lock is taken, return -1 as if rerere were disabled */
+#define RERERE_NOWAIT       010
 
 /*
  * Marks paths that have been hand-resolved and added to the
@@ -37,7 +39,14 @@ const char *rerere_path(struct strbuf *buf, const struct rerere_id *,
 int rerere_forget(struct repository *, struct pathspec *);
 int rerere_remaining(struct repository *, struct string_list *);
 void rerere_clear(struct repository *, struct string_list *);
-void rerere_gc(struct repository *, struct string_list *);
+
+enum rerere_gc_flags {
+	/* Skip the operation in case the MERGE_RR.lock is already taken. */
+	RERERE_GC_NOWAIT = (1 << 0),
+};
+
+void rerere_gc(struct repository *, struct string_list *,
+	       enum rerere_gc_flags flags);
 
 /*
  * Check whether garbage collection for rerere entries is needed, which is
diff --git a/t/t4200-rerere.sh b/t/t4200-rerere.sh
index 7bd92235dc..527a872c00 100755
--- a/t/t4200-rerere.sh
+++ b/t/t4200-rerere.sh
@@ -242,6 +242,32 @@ test_expect_success 'old records rest in peace' '
 	test_path_is_missing $rr2/preimage
 '
 
+test_expect_success 'gc --skip-locked does nothing while MERGE_RR is locked' '
+	mkdir -p $rr2 &&
+	echo Hello >$rr2/preimage &&
+	test-tool chmtime =$just_over_15_days_ago $rr2/preimage &&
+
+	test_when_finished "rm -f .git/MERGE_RR.lock" &&
+	>.git/MERGE_RR.lock &&
+	git rerere gc --skip-locked 2>err &&
+	test_must_be_empty err &&
+	test_path_is_file $rr2/preimage
+'
+
+test_expect_success 'gc --skip-locked prunes while MERGE_RR is not locked' '
+	mkdir -p $rr2 &&
+	echo Hello >$rr2/preimage &&
+	test-tool chmtime =$just_over_15_days_ago $rr2/preimage &&
+
+	git rerere gc --skip-locked &&
+	test_path_is_missing $rr2/preimage
+'
+
+test_expect_success '--skip-locked is only accepted by gc' '
+	test_must_fail git rerere --skip-locked clear 2>err &&
+	test_grep "option .--skip-locked. requires .gc." err
+'
+
 test_expect_success 'a held lock is waited out within rerere.lockTimeout' '
 	git reset --hard &&
 	rm -rf $rr &&
diff --git a/t/t7900-maintenance.sh b/t/t7900-maintenance.sh
index 4f65fa9439..f0f9b37d4f 100755
--- a/t/t7900-maintenance.sh
+++ b/t/t7900-maintenance.sh
@@ -1007,9 +1007,17 @@ test_expect_rerere_gc () {
 		shift
 	fi
 
+	# An automatic run passes --skip-locked to "git rerere gc".
+	skip_locked=
+	case " $* " in
+	*" --auto "*)
+		skip_locked=--skip-locked
+		;;
+	esac
+
 	rm -f "rerere-gc.txt" &&
 	GIT_TRACE2_EVENT="$(pwd)/rerere-gc.txt" "$@" &&
-	test_subcommand $negate git rerere gc <rerere-gc.txt
+	test_subcommand $negate git rerere gc $skip_locked <rerere-gc.txt
 }
 
 test_expect_success 'rerere-gc task without --auto always collects garbage' '
@@ -1084,6 +1092,21 @@ test_expect_success 'rerere-gc task with --auto honors maintenance.rerere-gc.aut
 	test_expect_rerere_gc ! git -c maintenance.rerere-gc.auto=0 maintenance run --auto --task=rerere-gc
 '
 
+test_expect_success 'rerere-gc task with --auto succeeds while MERGE_RR is locked' '
+	test_when_finished "rm -rf .git/rr-cache .git/MERGE_RR.lock" &&
+	mkdir .git/rr-cache &&
+	>.git/MERGE_RR.lock &&
+	test_expect_rerere_gc git -c maintenance.rerere-gc.auto=-1 maintenance run --auto --task=rerere-gc
+'
+
+test_expect_success 'rerere-gc task without --auto fails while MERGE_RR is locked' '
+	test_when_finished "rm -rf .git/rr-cache .git/MERGE_RR.lock" &&
+	mkdir .git/rr-cache &&
+	>.git/MERGE_RR.lock &&
+	test_must_fail git -c rerere.lockTimeout=0 maintenance run --task=rerere-gc 2>err &&
+	test_grep "Unable to create" err
+'
+
 test_expect_success '--auto and --schedule incompatible' '
 	test_must_fail git maintenance run --auto --schedule=daily 2>err &&
 	test_grep "cannot be used together" err
-- 
gitgitgadget
Re: [PATCH v7 1/2] rerere: wait for MERGE_RR.lock before giving up
#272
Author: Junio C Hamano
Date: Sun, 11 Oct 2026 00:39
197 lines
17429 bytes
"Thomas Bachem via GitGitGadget" <gitgitgadget@gmail.com> writes:

> diff --git a/Documentation/config/rerere.adoc b/Documentation/config/rerere.adoc
> index 3a78b5ebb1..30e827f32b 100644
> --- a/Documentation/config/rerere.adoc
> +++ b/Documentation/config/rerere.adoc
> @@ -10,3 +10,11 @@ rerere.enabled::
>  	enabled if there is an `rr-cache` directory under the
>  	`$GIT_DIR`, e.g. if "rerere" was previously used in the
>  	repository.
> +
> +rerere.lockTimeout::

$ git grep -A4 -i '^[^ ]*timeout[a-z]*:' Documentation/

tells me that all "timeout" configuration variables are measured in
milliseconds, which justifies the choice of milliseconds as the unit
for this new variable too.

    Side note.  Only one of the other ones has unit in its name
    (i.e., credentialStore.lockTimeoutMS).  We probably want to give
    it a synonym without MS suffix to make everything uniform.
    #leftoverbits

> +	The length of time, in milliseconds, to wait for the rerere
> +	lock when another process holds it, typically a background
> +	`git rerere gc`.  Value 0 means not to wait at all; -1 means
> +	to wait indefinitely.  Default is 1000 (i.e., wait for 1
> +	second).

OK.

> +     When the time is up, the command fails as it does
> +	for any other lock it cannot take.

Is it necessary to say this?  If we invent a new lock on 'foo' whose
behavior is to wait for N milliseconds and then proceed anyway,
ignoring the lock after the timer expires, we should name such a
setting differently from a simple 'fooLockTimeout'.  This would make
it easier for users to tell the difference, perhaps using
'fooLockBreakTimeout' or something similar.

In any case, we should ensure that we do not have to single out
'rerere.lockTimeout' and describe what happens after the timer
expires.  The timeout behavior on locks should be consistent.  That
may be slightly outside the scope of this topic, but since none of
the configuration variables whose names end with 'timeout' say the
above, leaving it out of this would be a good first step.  We can
leave a '#leftoverbits' task to describe the overall rule for
timeout settings for locks (i.e., "if you still cannot take the lock
after the timeout expires, you will give up and fail") in some
central place to make it clear that the same rule applies to
everyone.


> @@ -882,12 +887,19 @@ int setup_rerere(struct repository *r, struct string_list *merge_rr, int flags)
>  
>  	if (flags & (RERERE_AUTOUPDATE|RERERE_NOAUTOUPDATE))
>  		rerere_autoupdate = !!(flags & RERERE_AUTOUPDATE);
> -	if (flags & RERERE_READONLY)
> +	if (flags & RERERE_READONLY) {
>  		fd = 0;
> -	else
> -		fd = repo_hold_lock_file_for_update(r, &write_lock,
> -						    git_path_merge_rr(r),
> -						    LOCK_DIE_ON_ERROR);
> +	} else {
> +		/*
> +		 * Another process may hold the lock for a while, e.g.
> +		 * "git rerere gc" while it prunes rr-cache, so wait for
> +		 * it instead of dying right away.
> +		 */
> +		fd = repo_hold_lock_file_for_update_timeout(r, &write_lock,
> +							    git_path_merge_rr(r),
> +							    LOCK_DIE_ON_ERROR,
> +							    rerere_lock_timeout_ms);
> +	}
>  	read_rr(r, merge_rr);
>  	return fd;
>  }

OK.  Very straight-forward.

> diff --git a/t/t4200-rerere.sh b/t/t4200-rerere.sh
> index 7bb601e117..7bd92235dc 100755
> --- a/t/t4200-rerere.sh
> +++ b/t/t4200-rerere.sh
> @@ -242,6 +242,59 @@ test_expect_success 'old records rest in peace' '
>  	test_path_is_missing $rr2/preimage
>  '
>  
> +test_expect_success 'a held lock is waited out within rerere.lockTimeout' '
> +	git reset --hard &&
> +	rm -rf $rr &&
> +	test_when_finished "rm -f .git/MERGE_RR.lock" &&
> +	>.git/MERGE_RR.lock &&
> +	{
> +		( sleep 1 && rm -f .git/MERGE_RR.lock ) &
> +	} &&
> +	test_must_fail git -c rerere.lockTimeout=5000 merge first 2>err &&

The backgrounded unlocker sleeps for a second.  Is the idea that,
even in a heavily loaded CI environment, the backgrounded unlocker
will have a sufficient chance to sleep for a second and unlock while
the 5000-millisecond timeout waits for it?

> +	wait &&

Is the idea behind this 'wait' that the 'rerere.locktimeout'
implementation might break in the future and we could reach this
point before the background unlocker has finished sleeping for a
full second?  And we want to ensure it has exited before proceeding
by waiting for it ourselves.  If that is the case, perhaps a comment
is warranted after '&&', such as:

        wait && # just in case the background unlocker is still active

or something similar.

> +	test_grep ! "MERGE_RR" err &&

It is a bit unclear what error message this is looking for.
repo_hold_lock_file_for_update_timeout() is fed the path to
MERGE_RR, and eventually calls unable_to_lock_message() to format
the error message, which starts with "Unable to create '...'" to
state the path.  Is the idea that this message will contain MERGE_RR
as part of that path and we will catch it if we failed to acquire
the lock?

This deserves a short comment to clarify that we are looking for the
lack of "unable to lock" comment, if that is indeed what is
happening.  Or make the string a bit more specific, such as:

	test_grep ! "Unable to create.*MERGE_RR\.lock" err &&

or something along those line.

Should we ensure that there is no leftover pid file by removing it
before creating .git/MERGE_RR.lock, by the way?

> +	test_grep "^=======\$" $rr/preimage

The merge still has to fail (which is ensured by test_must_fail in
the earlier step) and leave the preimage of the conflicted state,
which makes sense.

I'll stop here, but you can grasp the principles used in reviewing
this test and apply them to the remaining tests to ensure they are
clearly written.

Thanks.


> +
> +test_expect_success 'merge fails once rerere.lockTimeout is up' '
> +	git reset --hard &&
> +	rm -rf $rr &&
> +	test_when_finished "rm -f .git/MERGE_RR.lock" &&
> +	>.git/MERGE_RR.lock &&
> +	test_must_fail git -c rerere.lockTimeout=0 merge first 2>err &&
> +	test_grep "Unable to create" err &&
> +	test_grep "^=======\$" a1 &&
> +	test_path_is_missing $rr/preimage
> +'
> +
> +test_expect_success 'rerere, forget, clear and gc fail on a lock they cannot take' '
> +	test_when_finished "rm -f .git/MERGE_RR.lock" &&
> +	>.git/MERGE_RR.lock &&
> +	test_must_fail git -c rerere.lockTimeout=0 rerere 2>err &&
> +	test_grep "Unable to create" err &&
> +	test_must_fail git -c rerere.lockTimeout=0 rerere forget a1 2>err &&
> +	test_grep "Unable to create" err &&
> +	test_must_fail git -c rerere.lockTimeout=0 rerere clear 2>err &&
> +	test_grep "Unable to create" err &&
> +	test_must_fail git -c rerere.lockTimeout=0 rerere gc 2>err &&
> +	test_grep "Unable to create" err
> +'
> +
> +test_expect_success 'rebase --abort fails on a lock it cannot take' '
> +	git reset --hard &&
> +	git checkout -b lock-held-abort third &&
> +	test_when_finished "git checkout third && git branch -D lock-held-abort" &&
> +	test_must_fail git rebase first &&
> +	test_when_finished "rm -f .git/MERGE_RR.lock" &&
> +	>.git/MERGE_RR.lock &&
> +	test_must_fail git -c rerere.lockTimeout=0 rebase --abort 2>err &&
> +	test_grep "Unable to create" err &&
> +	test_path_is_dir .git/rebase-merge &&
> +	rm .git/MERGE_RR.lock &&
> +	git rebase --abort &&
> +	test_path_is_missing .git/rebase-merge
> +'
> +
>  rerere_gc_custom_expiry_test () {
>  	five_days="$1" right_now="$2"
>  	test_expect_success "rerere gc with custom expiry ($five_days, $right_now)" '
Re: [PATCH v7 1/2] rerere: wait for MERGE_RR.lock before giving up
#294
Author: Junio C Hamano
Date: Mon, 12 Oct 2026 00:32
12 lines
10207 bytes
Thomas Bachem <mail@thomasbachem.com> writes:

>>         wait && # just in case the background unlocker is still active
>
> It is. Instead of the comment, I'll move the wait into
> test_when_finished, as pack-refs-tests.sh does, so it runs however
> the test ends.

Ah, that sounds quite sensible.

Thanks.
Re: [PATCH v7 1/2] rerere: wait for MERGE_RR.lock before giving up
#519
Author: Okhuomon Ajayi
Date: Wed, 14 Oct 2026 15:55
13 lines
8370 bytes
On Sun, Oct 11, 2026 at 1:39 AM Junio C Hamano <gitster@pobox.com> wrote:
>     Side note. Only one of the other ones has unit in its name
>     (i.e., credentialStore.lockTimeoutMS). We probably want to give
>     it a synonym without MS suffix to make everything uniform.
>     #leftoverbits

Hi Junio,

I would like to work on this #leftoverbits.


Okhuomon
[Outreachy PATCH] credential-store: add lockTimeout config option
#561
Author: Okhuomon Ajayi
Date: Wed, 14 Oct 2026 23:27
111 lines
12209 bytes
Support credentialStore.lockTimeout as the preferred setting
for credential lock retries, retaining lockTimeoutMS as a
deprecated alias.

Signed-off-by: Okhuomon Ajayi <okhuomonajayi54@gmail.com>
---
 Documentation/config/credential.adoc |  5 ++-
 builtin/credential-store.c           |  4 +-
 t/t0302-credential-store.sh          | 56 ++++++++++++++++++++++++++++
 3 files changed, 63 insertions(+), 2 deletions(-)

diff --git a/Documentation/config/credential.adoc b/Documentation/config/credential.adoc
index 80a7c77772..6fa40560be 100644
--- a/Documentation/config/credential.adoc
+++ b/Documentation/config/credential.adoc
@@ -48,8 +48,11 @@ credential.<url>.*::
 credentialCache.ignoreSIGHUP::
 	Tell git-credential-cache--daemon to ignore SIGHUP, instead of quitting.
 
-credentialStore.lockTimeoutMS::
+credentialStore.lockTimeout::
 	The length of time, in milliseconds, for git-credential-store to retry
 	when trying to lock the credentials file. A value of 0 means not to retry at
 	all; -1 means to try indefinitely. Default is 1000 (i.e., retry for
 	1s).
+
+credentialStore.lockTimeoutMS (deprecated)::
+	This is a deprecated synonym for `credentialStore.lockTimeout`.
diff --git a/builtin/credential-store.c b/builtin/credential-store.c
index bc1453c6b2..9fef54d218 100644
--- a/builtin/credential-store.c
+++ b/builtin/credential-store.c
@@ -67,7 +67,9 @@ static void rewrite_credential_file(const char *fn, struct credential *c,
 {
 	int timeout_ms = 1000;
 
-	repo_config_get_int(the_repository, "credentialstore.locktimeoutms", &timeout_ms);
+	/* lockTimeoutMS is a deprecated synonym of lockTimeout. */
+	if (repo_config_get_int(the_repository, "credentialstore.locktimeout", &timeout_ms))
+		repo_config_get_int(the_repository, "credentialstore.locktimeoutms", &timeout_ms);
 	if (hold_lock_file_for_update_timeout(&credential_lock, fn, 0, timeout_ms) < 0)
 		die_errno(_("unable to get credential storage lock in %d ms"), timeout_ms);
 	if (extra)
diff --git a/t/t0302-credential-store.sh b/t/t0302-credential-store.sh
index c1cd60edd0..408f26bb10 100755
--- a/t/t0302-credential-store.sh
+++ b/t/t0302-credential-store.sh
@@ -210,4 +210,60 @@ test_expect_success 'get: store file can contain empty/bogus lines' '
 	EOF
 '
 
+# Holding creds.lock makes the next store fail. The error reports the
+# timeout that was actually used, so "in 0 ms" means that name won.
+test_expect_success 'credentialStore.lockTimeoutMS=0 gives up immediately' '
+	test_when_finished "rm -f creds creds.lock" &&
+	>"creds.lock" &&
+	test_must_fail git -c credentialStore.lockTimeoutMS=0 \
+		credential-store --file=creds store 2>err <<-\EOF &&
+	protocol=https
+	host=example.com
+	username=store-user
+	password=store-pass
+	EOF
+	test_grep "unable to get credential storage lock in 0 ms" err
+'
+
+test_expect_success 'credentialStore.lockTimeout=0 gives up immediately' '
+	test_when_finished "rm -f creds creds.lock" &&
+	>"creds.lock" &&
+	test_must_fail git -c credentialStore.lockTimeout=0 \
+		credential-store --file=creds store 2>err <<-\EOF &&
+	protocol=https
+	host=example.com
+	username=store-user
+	password=store-pass
+	EOF
+	test_grep "unable to get credential storage lock in 0 ms" err
+'
+
+test_expect_success 'credentialStore.lockTimeout wins when both are set' '
+	test_when_finished "rm -f creds creds.lock" &&
+	>"creds.lock" &&
+	test_must_fail git \
+		-c credentialStore.lockTimeout=0 \
+		-c credentialStore.lockTimeoutMS=500 \
+		credential-store --file=creds store 2>err <<-\EOF &&
+	protocol=https
+	host=example.com
+	username=store-user
+	password=store-pass
+	EOF
+	test_grep "unable to get credential storage lock in 0 ms" err
+'
+
+test_expect_success 'credentialStore.lockTimeout allows a store' '
+	test_when_finished "rm -f creds" &&
+	git -c credentialStore.lockTimeout=1000 \
+		credential-store --file=creds store <<-\EOF &&
+	protocol=https
+	host=example.com
+	username=store-user
+	password=store-pass
+	EOF
+	echo "https://store-user:store-pass@example.com" >expect &&
+	test_cmp expect creds
+'
+
 test_done
-- 
2.54.0
Re: [Outreachy PATCH] credential-store: add lockTimeout config option
#610
Author: Junio C Hamano
Date: Thu, 15 Oct 2026 17:50
127 lines
14694 bytes
Okhuomon Ajayi <okhuomonajayi54@gmail.com> writes:

> diff --git a/builtin/credential-store.c b/builtin/credential-store.c
> index bc1453c6b2..9fef54d218 100644
> --- a/builtin/credential-store.c
> +++ b/builtin/credential-store.c
> @@ -67,7 +67,9 @@ static void rewrite_credential_file(const char *fn, struct credential *c,
>  {
>  	int timeout_ms = 1000;
>  
> -	repo_config_get_int(the_repository, "credentialstore.locktimeoutms", &timeout_ms);
> +	/* lockTimeoutMS is a deprecated synonym of lockTimeout. */
> +	if (repo_config_get_int(the_repository, "credentialstore.locktimeout", &timeout_ms))
> +		repo_config_get_int(the_repository, "credentialstore.locktimeoutms", &timeout_ms);
>  	if (hold_lock_file_for_update_timeout(&credential_lock, fn, 0, timeout_ms) < 0)
>  		die_errno(_("unable to get credential storage lock in %d ms"), timeout_ms);

Around this point the file is already full of overly long lines, but
the patch is making it even worse.

> diff --git a/t/t0302-credential-store.sh b/t/t0302-credential-store.sh
> index c1cd60edd0..408f26bb10 100755
> --- a/t/t0302-credential-store.sh
> +++ b/t/t0302-credential-store.sh
> @@ -210,4 +210,60 @@ test_expect_success 'get: store file can contain empty/bogus lines' '
>  	EOF
>  '
>  
> +# Holding creds.lock makes the next store fail. The error reports the
> +# timeout that was actually used, so "in 0 ms" means that name won.
> +test_expect_success 'credentialStore.lockTimeoutMS=0 gives up immediately' '
> +	test_when_finished "rm -f creds creds.lock" &&
> +	>"creds.lock" &&
> +	test_must_fail git -c credentialStore.lockTimeoutMS=0 \
> +		credential-store --file=creds store 2>err <<-\EOF &&
> +	protocol=https
> +	host=example.com
> +	username=store-user
> +	password=store-pass
> +	EOF
> +	test_grep "unable to get credential storage lock in 0 ms" err
> +'
> +
> +test_expect_success 'credentialStore.lockTimeout=0 gives up immediately' '
> +	test_when_finished "rm -f creds creds.lock" &&
> +	>"creds.lock" &&
> +	test_must_fail git -c credentialStore.lockTimeout=0 \
> +		credential-store --file=creds store 2>err <<-\EOF &&
> +	protocol=https
> +	host=example.com
> +	username=store-user
> +	password=store-pass
> +	EOF
> +	test_grep "unable to get credential storage lock in 0 ms" err
> +'

As it is necessary to keep the above two in sync forever, it may
make sense to do this instead:

	for v lockTimeout lockTimeoutMS
	do
		test_expect_success "credentialStore.$v=0 gives up immediately" '
			...
			test_must_fail git -c credentialStore.$v=0 \
			credential-store --file=creds store 2>err <<-\EOF &&
			...
			test_grep "unable to get ..." err
		'
	done

It is a common mistake to use double-quote in an attempt to have $v
expanded before it is passed to text_expect_success function, but
the variable $v is dereferenced correctly inside the body of the
test that is quoted with single-quote as it is eval'ed, so the way
the above is written is right.

> +test_expect_success 'credentialStore.lockTimeout wins when both are set' '
> +	test_when_finished "rm -f creds creds.lock" &&
> +	>"creds.lock" &&
> +	test_must_fail git \
> +		-c credentialStore.lockTimeout=0 \
> +		-c credentialStore.lockTimeoutMS=500 \
> +		credential-store --file=creds store 2>err <<-\EOF &&
> +	protocol=https
> +	host=example.com
> +	username=store-user
> +	password=store-pass
> +	EOF
> +	test_grep "unable to get credential storage lock in 0 ms" err
> +'

This is understandable.  The presense of locktimeout=0 hides
whatever locktimeoutms is set to, so it should fail the same way as
the earlier two tests.  Wait, nobody unlocks creds.lock, so what
should happen if the line that sets locktimeout=0 is removed?

Ahh, the key to this test is that we make sure "in 0 ms" part of the
error message does not say "in 500 ms" to ensure which of the two
variables are being used.  It is not like the credential-store command
would fail with 0ms timeout but succees with 500ms timeout.

> +test_expect_success 'credentialStore.lockTimeout allows a store' '
> +	test_when_finished "rm -f creds" &&
> +	git -c credentialStore.lockTimeout=1000 \
> +		credential-store --file=creds store <<-\EOF &&
> +	protocol=https
> +	host=example.com
> +	username=store-user
> +	password=store-pass
> +	EOF
> +	echo "https://store-user:store-pass@example.com" >expect &&
> +	test_cmp expect creds
> +'

This one I I am not sure what it is trying to test, though.  Would
the test start failing as the machine is loaded more and 1000 ms
becomes insufficient?  No.  The thing is not locked, nobody takes a
lock competing with our test, so with any value of the timeout we
should succeed, no?  Or would it fail if the timeout is set to 0ms?

Assuming that there is a reason to run this test, should it also be
testing locktimeoutms to ensure both variables behave the same way
when set independently, similarly to the two tests I rewrote into a
for loop?

Thanks.
Re: [Outreachy PATCH] credential-store: add lockTimeout config option
#696
Author: Okhuomon Ajayi
Date: Fri, 16 Oct 2026 21:09
35 lines
10407 bytes
On Thu, Oct 15, 2026 at 6:50 PM Junio C Hamano <gitster@pobox.com> wrote:
> As it is necessary to keep the above two in sync forever, it may
> make sense to do this instead:
>
>         for v lockTimeout lockTimeoutMS

Thanks, I've turned the two tests into a loop like this for v2, and
wrapped the long lines in credential-store.c.


> Ahh, the key to this test is that we make sure "in 0 ms" part of the
> error message does not say "in 500 ms" to ensure which of the two
> variables are being used.  It is not like the credential-store command
> would fail with 0ms timeout but succees with 500ms timeout.


Yes, that is the point of it. I've added a comment above the test to
say so.

> This one I I am not sure what it is trying to test, though.  Would
> the test start failing as the machine is loaded more and 1000 ms
> becomes insufficient?  No.  The thing is not locked, nobody takes a
> lock competing with our test, so with any value of the timeout we
> should succeed, no?  Or would it fail if the timeout is set to 0ms?


You're right. Nothing holds the lock there, so it passes with any
timeout and does not test lockTimeout at all. I've dropped it in v2.

I'll send v2 shortly.

 Thanks,
Okhuomon
[Outreachy PATCH v2] credential-store: add lockTimeout config option
#699
Author: Okhuomon Ajayi
Date: Fri, 16 Oct 2026 21:22
102 lines
11938 bytes
Support credentialStore.lockTimeout as the preferred setting
for credential lock retries, retaining lockTimeoutMS as a
deprecated alias.

Signed-off-by: Okhuomon Ajayi <okhuomonajayi54@gmail.com>
---
Changes since v1:
 - Turned the two "lockTimeout=0" and "lockTimeoutMS=0" tests into a
   single loop over both names, so they cannot drift apart.
 - Wrapped the long lines the patch added in credential-store.c.
 - Added a comment explaining that the "both are set" test checks for
   "in 0 ms" rather than "in 500 ms".
 - Dropped the "lockTimeout allows a store" test: nothing holds the
   lock there, so it passes with any timeout.

 Documentation/config/credential.adoc |  5 +++-
 builtin/credential-store.c           |  7 +++++-
 t/t0302-credential-store.sh          | 35 ++++++++++++++++++++++++++++
 3 files changed, 45 insertions(+), 2 deletions(-)

diff --git a/Documentation/config/credential.adoc b/Documentation/config/credential.adoc
index 80a7c77772..6fa40560be 100644
--- a/Documentation/config/credential.adoc
+++ b/Documentation/config/credential.adoc
@@ -48,8 +48,11 @@ credential.<url>.*::
 credentialCache.ignoreSIGHUP::
 	Tell git-credential-cache--daemon to ignore SIGHUP, instead of quitting.
 
-credentialStore.lockTimeoutMS::
+credentialStore.lockTimeout::
 	The length of time, in milliseconds, for git-credential-store to retry
 	when trying to lock the credentials file. A value of 0 means not to retry at
 	all; -1 means to try indefinitely. Default is 1000 (i.e., retry for
 	1s).
+
+credentialStore.lockTimeoutMS (deprecated)::
+	This is a deprecated synonym for `credentialStore.lockTimeout`.
diff --git a/builtin/credential-store.c b/builtin/credential-store.c
index bc1453c6b2..afd2e4f3ce 100644
--- a/builtin/credential-store.c
+++ b/builtin/credential-store.c
@@ -67,7 +67,12 @@ static void rewrite_credential_file(const char *fn, struct credential *c,
 {
 	int timeout_ms = 1000;
 
-	repo_config_get_int(the_repository, "credentialstore.locktimeoutms", &timeout_ms);
+	/* lockTimeoutMS is a deprecated synonym of lockTimeout. */
+	if (repo_config_get_int(the_repository, "credentialstore.locktimeout",
+				&timeout_ms))
+		repo_config_get_int(the_repository,
+				    "credentialstore.locktimeoutms",
+				    &timeout_ms);
 	if (hold_lock_file_for_update_timeout(&credential_lock, fn, 0, timeout_ms) < 0)
 		die_errno(_("unable to get credential storage lock in %d ms"), timeout_ms);
 	if (extra)
diff --git a/t/t0302-credential-store.sh b/t/t0302-credential-store.sh
index c1cd60edd0..e1bbca3fcc 100755
--- a/t/t0302-credential-store.sh
+++ b/t/t0302-credential-store.sh
@@ -210,4 +210,39 @@ test_expect_success 'get: store file can contain empty/bogus lines' '
 	EOF
 '
 
+# Holding creds.lock makes the next store fail. The error reports the
+# timeout that was actually used, so "in 0 ms" means that name won.
+for v in lockTimeout lockTimeoutMS
+do
+	test_expect_success "credentialStore.$v=0 gives up immediately" '
+		test_when_finished "rm -f creds creds.lock" &&
+		>"creds.lock" &&
+		test_must_fail git -c credentialStore.$v=0 \
+			credential-store --file=creds store 2>err <<-\EOF &&
+		protocol=https
+		host=example.com
+		username=store-user
+		password=store-pass
+		EOF
+		test_grep "unable to get credential storage lock in 0 ms" err
+	'
+done
+
+# lockTimeout=0 must win over lockTimeoutMS=500: the error says
+# "in 0 ms", not "in 500 ms".
+test_expect_success 'credentialStore.lockTimeout wins when both are set' '
+	test_when_finished "rm -f creds creds.lock" &&
+	>"creds.lock" &&
+	test_must_fail git \
+		-c credentialStore.lockTimeout=0 \
+		-c credentialStore.lockTimeoutMS=500 \
+		credential-store --file=creds store 2>err <<-\EOF &&
+	protocol=https
+	host=example.com
+	username=store-user
+	password=store-pass
+	EOF
+	test_grep "unable to get credential storage lock in 0 ms" err
+'
+
 test_done
-- 
2.54.0
Re: [Outreachy PATCH v2] credential-store: add lockTimeout config option
#967
Author: Okhuomon Ajayi
Date: Tue, 20 Oct 2026 22:11
4 lines
10605 bytes
Friendly ping on this :)

Okhuomon
Re: [Outreachy PATCH v2] credential-store: add lockTimeout config option
#3019
Author: Okhuomon Ajayi
Date: Thu, 12 Nov 2026 19:30
20 lines
12515 bytes
Hi Junio, ping on v2 of credential-store lockTimeout.
It follows your review of v1. The two zero-timeout tests are now one
loop, the long lines the patch added in credential-store.c are
wrapped, the "both set" test has a comment, and the test that never
held the lock is gone. I have not heard anything since the short note
on October 20.
Is there anything else you want changed?

Thanks,
Okhuomon


On Fri, Oct 16, 2026 at 10:23 PM Okhuomon Ajayi
<okhuomonajayi54@gmail.com> wrote:
>
> Support credentialStore.lockTimeout as the preferred setting
> for credential lock retries, retaining lockTimeoutMS as a
> deprecated alias.
>
Re: [Outreachy PATCH v2] credential-store: add lockTimeout config option
#3047
Author: Junio C Hamano
Date: Thu, 12 Nov 2026 21:10
32 lines
13877 bytes
Okhuomon Ajayi <okhuomonajayi54@gmail.com> writes:

> Support credentialStore.lockTimeout as the preferred setting
> for credential lock retries, retaining lockTimeoutMS as a
> deprecated alias.
>
> Signed-off-by: Okhuomon Ajayi <okhuomonajayi54@gmail.com>

Hmph, does this change even make sense?

Sure, there are many variables whose name ends with "timeout".  But
are they all measured in milliseconds?  Or are some measured in
seconds and others measured in milliseconds?  If the latter, this
moves us in the wrong direction, no?  If the time unit is not
uniform across variables, it would be more sensible to give them
names with unit so the users would immediately know when they see

    cs.locktimeoutMilliSeconds = 500

that the wait will be subseconds.

On the other hand, if we are committed that all timeouts are
measured in milliseconds, such a unit suffix does not buy us much,
and better be dropped.

Anybody who reads your proposed log message above in the future will
ask these questions, and a log message that forces them to ask such
questions needs more work.  State why this patch decides to do this,
and do not say "somebody told me to make this change".  Your readers
want to hear why you think this change makes sense, and be
convinced.
Re: [Outreachy PATCH v2] credential-store: add lockTimeout config option
#3165
Author: Okhuomon Ajayi
Date: Sun, 15 Nov 2026 15:13
24 lines
12665 bytes
On Thu, Nov 12, 2026 at 10:10 PM Junio C Hamano <gitster@pobox.com> wrote:

> Hmph, does this change even make sense?
>
> Sure, there are many variables whose name ends with "timeout".  But
> are they all measured in milliseconds?

The other settings that retry taking a file lock are measured in
milliseconds and do not put the unit in the name: rerere.lockTimeout,
reftable.lockTimeout, core.filesRefLockTimeout,
core.packedRefsTimeout, and core.configLockTimeout.
credentialStore.lockTimeoutMS spells the unit out.

The value is still milliseconds, which the documentation states.
credential-cache --timeout is a different setting and is in seconds,
so I am only lining this name up with the other lock retries.

I'll resend with that reason in the log message.

Thanks,

Okhuomon
[Outreachy PATCH v3] credential-store: add lockTimeout config option
#3192
Author: Okhuomon Ajayi
Date: Mon, 16 Nov 2026 19:13
108 lines
14924 bytes
The other settings that retry taking a file lock are measured in
milliseconds and do not put the unit in the name:
rerere.lockTimeout, reftable.lockTimeout, core.filesRefLockTimeout,
core.packedRefsTimeout, and core.configLockTimeout.
credentialStore.lockTimeoutMS spells the unit out.

Add credentialStore.lockTimeout as the matching name. Keep
lockTimeoutMS as a deprecated synonym so existing configuration
still works. The value is still milliseconds, which the
documentation states.

Signed-off-by: Okhuomon Ajayi <okhuomonajayi54@gmail.com>
---
Changes since v2:
- Reword the message to say why the new name drops the unit. The
  other file-lock retries are milliseconds and do not put the unit
  in the name.
- Rebased onto current master (7fb6055e67, The 20th batch).

 Documentation/config/credential.adoc |  5 +++-
 builtin/credential-store.c           |  7 +++++-
 t/t0302-credential-store.sh          | 35 ++++++++++++++++++++++++++++
 3 files changed, 45 insertions(+), 2 deletions(-)

diff --git a/Documentation/config/credential.adoc b/Documentation/config/credential.adoc
index 80a7c77772..6fa40560be 100644
--- a/Documentation/config/credential.adoc
+++ b/Documentation/config/credential.adoc
@@ -48,8 +48,11 @@ credential.<url>.*::
 credentialCache.ignoreSIGHUP::
 	Tell git-credential-cache--daemon to ignore SIGHUP, instead of quitting.
 
-credentialStore.lockTimeoutMS::
+credentialStore.lockTimeout::
 	The length of time, in milliseconds, for git-credential-store to retry
 	when trying to lock the credentials file. A value of 0 means not to retry at
 	all; -1 means to try indefinitely. Default is 1000 (i.e., retry for
 	1s).
+
+credentialStore.lockTimeoutMS (deprecated)::
+	This is a deprecated synonym for `credentialStore.lockTimeout`.
diff --git a/builtin/credential-store.c b/builtin/credential-store.c
index bc1453c6b2..afd2e4f3ce 100644
--- a/builtin/credential-store.c
+++ b/builtin/credential-store.c
@@ -67,7 +67,12 @@ static void rewrite_credential_file(const char *fn, struct credential *c,
 {
 	int timeout_ms = 1000;
 
-	repo_config_get_int(the_repository, "credentialstore.locktimeoutms", &timeout_ms);
+	/* lockTimeoutMS is a deprecated synonym of lockTimeout. */
+	if (repo_config_get_int(the_repository, "credentialstore.locktimeout",
+				&timeout_ms))
+		repo_config_get_int(the_repository,
+				    "credentialstore.locktimeoutms",
+				    &timeout_ms);
 	if (hold_lock_file_for_update_timeout(&credential_lock, fn, 0, timeout_ms) < 0)
 		die_errno(_("unable to get credential storage lock in %d ms"), timeout_ms);
 	if (extra)
diff --git a/t/t0302-credential-store.sh b/t/t0302-credential-store.sh
index c1cd60edd0..e1bbca3fcc 100755
--- a/t/t0302-credential-store.sh
+++ b/t/t0302-credential-store.sh
@@ -210,4 +210,39 @@ test_expect_success 'get: store file can contain empty/bogus lines' '
 	EOF
 '
 
+# Holding creds.lock makes the next store fail. The error reports the
+# timeout that was actually used, so "in 0 ms" means that name won.
+for v in lockTimeout lockTimeoutMS
+do
+	test_expect_success "credentialStore.$v=0 gives up immediately" '
+		test_when_finished "rm -f creds creds.lock" &&
+		>"creds.lock" &&
+		test_must_fail git -c credentialStore.$v=0 \
+			credential-store --file=creds store 2>err <<-\EOF &&
+		protocol=https
+		host=example.com
+		username=store-user
+		password=store-pass
+		EOF
+		test_grep "unable to get credential storage lock in 0 ms" err
+	'
+done
+
+# lockTimeout=0 must win over lockTimeoutMS=500: the error says
+# "in 0 ms", not "in 500 ms".
+test_expect_success 'credentialStore.lockTimeout wins when both are set' '
+	test_when_finished "rm -f creds creds.lock" &&
+	>"creds.lock" &&
+	test_must_fail git \
+		-c credentialStore.lockTimeout=0 \
+		-c credentialStore.lockTimeoutMS=500 \
+		credential-store --file=creds store 2>err <<-\EOF &&
+	protocol=https
+	host=example.com
+	username=store-user
+	password=store-pass
+	EOF
+	test_grep "unable to get credential storage lock in 0 ms" err
+'
+
 test_done

base-commit: 7fb6055e678f800320d8ab8cd8f201d9493d1ba0
-- 
2.56.0
Re: [Outreachy PATCH v3] credential-store: add lockTimeout config option
#3198
Author: Junio C Hamano
Date: Mon, 16 Nov 2026 23:39
24 lines
13512 bytes
Okhuomon Ajayi <okhuomonajayi54@gmail.com> writes:

> The other settings that retry taking a file lock are measured in
> milliseconds and do not put the unit in the name:
> rerere.lockTimeout, reftable.lockTimeout, core.filesRefLockTimeout,
> core.packedRefsTimeout, and core.configLockTimeout.
> credentialStore.lockTimeoutMS spells the unit out.
>
> Add credentialStore.lockTimeout as the matching name. Keep
> lockTimeoutMS as a deprecated synonym so existing configuration
> still works. The value is still milliseconds, which the
> documentation states.
>
> Signed-off-by: Okhuomon Ajayi <okhuomonajayi54@gmail.com>
> ---
> Changes since v2:
> - Reword the message to say why the new name drops the unit. The
>   other file-lock retries are milliseconds and do not put the unit
>   in the name.

Looks good.  Let me mark the topic as ready for 'next'.

Thanks.
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads