Subject: Re: [PATCH] refs: don't clear oid before read_raw_ref in the debug ref backend

From: Patrick Steinhardt <[email-masked]>
Date: Fri, 31 Oct 2025 07:48:42 +0100

On Fri, Oct 31, 2025 at 03:37:05AM +0000, Xinyu Ruan via GitGitGadget wrote:
> From: Xinyu Ruan <[email-masked]>
> 
> The debug_read_raw_ref function clears the oid to null_oid before
> calling read_raw_ref, which causes the oid to be lost even when
> read_raw_ref successfully reads the reference.

This sentence doesn't quite make sense to me. If `read_raw_ref()`
succeeds, wouldn't we expect that the OID was set to the target's object
ID anyway? So why does it hurt to set the object ID to the null ID if
it's going to get rewritten anyway?

Another question is why we were setting it to the null OID in the first
place. Ideally, this should be discussed in the commit message.

> This leads to failures
> when executing commands like "git branch new_branch <commit_id>" with
> GIT_TRACE_REFS=1, as the command cannot find a valid branch point
> because the oid is null.

This smells like an issue that can be be demonstrated via a unit test.
Right now though we got zero testing for `GIT_TRACE_REFS` in our test
suite. Maybe this could be used as a starting point for a new test suite
"t0620-ref-debug.sh" that exercises the different callbacks?

Thanks!

Patrick