[PATCH v3 2/2] maintenance: trace lock acquisition failures
- From
Pushkar Singh <pushkarkumarsingh1970@gmail.com>
- Date
- Nov 4, 2026, 17:34 UTC
- Message-ID
- <20261104173422.20725-3-pushkarkumarsingh1970@gmail.com>
- In-Reply-To
- <20261104173422.20725-1-pushkarkumarsingh1970@gmail.com>
When git maintenance run --auto fails to acquire the maintenance lock, emit a Trace2 data event describing the reason for the failure.
This makes it easier to identify cases where automatic maintenance is repeatedly skipped.
Signed-off-by: Pushkar Singh <pushkarkumarsingh1970@gmail.com> --- builtin/gc.c | 4 ++++ t/t7900-maintenance.sh | 9 +++++++++ 2 files changed, 13 insertions(+)
diff --git a/builtin/gc.c b/builtin/gc.c index 9ca9a3584b..eaa0d71285 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -1410,6 +1410,10 @@ static int maintenance_run_tasks(struct maintenance_run_opts *opts, * recursive process stack. Do not report an error in * that case. */ + if (opts->auto_flag) + trace2_data_string("maintenance", r, "lock/skip", + strerror(err)); + if (!opts->quiet) { struct strbuf buf = STRBUF_INIT; unable_to_lock_message(lock_path, err, &buf); diff --git a/t/t7900-maintenance.sh b/t/t7900-maintenance.sh index 3288efb391..294ab0db75 100755 --- a/t/t7900-maintenance.sh +++ b/t/t7900-maintenance.sh @@ -411,6 +411,15 @@ test_expect_success 'manual maintenance with --quiet suppresses diagnostic' ' test_path_is_file .git/objects/maintenance.lock ' +test_expect_success 'auto maintenance traces existing lock' ' + test_when_finished "rm -f trace.txt .git/objects/maintenance.lock" && + : >.git/objects/maintenance.lock && + GIT_TRACE2_EVENT="$(pwd)/trace.txt" \ + git maintenance run --auto --quiet && + test_trace2_data maintenance lock/skip "File exists" <trace.txt && + test_path_is_file .git/objects/maintenance.lock +' + test_expect_success 'maintenance.loose-objects.auto' ' git repack -adk && GIT_TRACE2_EVENT="$(pwd)/trace-lo1.txt" \
-- 2.53.0