# [PATCH] refs: add missing optimize implementation for debug ref backend

2 messages from 2025-10-31 to 2025-10-31. Participants: Xinyu Ruan via GitGitGadget, Patrick Steinhardt.
Thread: https://gitlist.dev/t/64408

## Xinyu Ruan via GitGitGadget, 2025-10-31 03:37

Subject: [PATCH] refs: add missing optimize implementation for debug ref backend
Message-ID: <pull.2090.git.git.1761881859881.gitgitgadget@gmail.com>
URL: https://gitlist.dev/e/pull.2090.git.git.1761881859881.gitgitgadget%40gmail.com

```
From: Xinyu Ruan <r200981113@gmail.com>

The debug ref backend (refs_be_debug) was missing the optimize
function pointer, which caused a segmentation fault when running
'GIT_TRACE_REFS=1 git pack-refs --all' command.

Signed-off-by: Xinyu Ruan <r200981113@gmail.com>
---
    refs: add missing optimize implementation for debug ref backend

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2090%2FRuanXinyu%2Fref-debug-optimize-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2090/RuanXinyu/ref-debug-optimize-v1
Pull-Request: https://github.com/git/git/pull/2090

 refs/debug.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/refs/debug.c b/refs/debug.c
index 697adbd0dc..8dad7046cd 100644
--- a/refs/debug.c
+++ b/refs/debug.c
@@ -124,6 +124,14 @@ static int debug_pack_refs(struct ref_store *ref_store, struct pack_refs_opts *o
 	return res;
 }
 
+static int debug_optimize(struct ref_store *ref_store, struct pack_refs_opts *opts)
+{
+	struct debug_ref_store *drefs = (struct debug_ref_store *)ref_store;
+	int res = drefs->refs->be->optimize(drefs->refs, opts);
+	trace_printf_key(&trace_refs, "optimize: %d\n", res);
+	return res;
+}
+
 static int debug_rename_ref(struct ref_store *ref_store, const char *oldref,
 			    const char *newref, const char *logmsg)
 {
@@ -444,6 +452,7 @@ struct ref_storage_be refs_be_debug = {
 	.transaction_abort = debug_transaction_abort,
 
 	.pack_refs = debug_pack_refs,
+	.optimize = debug_optimize,
 	.rename_ref = debug_rename_ref,
 	.copy_ref = debug_copy_ref,
 

base-commit: a99f379adf116d53eb11957af5bab5214915f91d
-- 
gitgitgadget

```

## Patrick Steinhardt, 2025-10-31 06:39

Subject: Re: [PATCH] refs: add missing optimize implementation for debug ref backend
Message-ID: <aQRZizsobXECzvJI@pks.im>
URL: https://gitlist.dev/e/aQRZizsobXECzvJI%40pks.im
In-Reply-To: <pull.2090.git.git.1761881859881.gitgitgadget@gmail.com>

```
On Fri, Oct 31, 2025 at 03:37:39AM +0000, Xinyu Ruan via GitGitGadget wrote:
> From: Xinyu Ruan <r200981113@gmail.com>
> 
> The debug ref backend (refs_be_debug) was missing the optimize
> function pointer, which caused a segmentation fault when running
> 'GIT_TRACE_REFS=1 git pack-refs --all' command.

Thanks for sending the patch! As far as I can see though it's redundant
with Karthik's patch series that is currently cooking in 'seen' [1]. So
once that's merged down we should be good.

Patrick

[1]: <20251020-refs-code-cleanup-v2-1-f5349ed0f6a5@gmail.com>

```
