{"thread":{"id":"64407","subject":"[PATCH] refs: don't clear oid before read_raw_ref in the debug ref backend","startedAt":"2025-10-31T03:37:07Z","lastAt":"2025-10-31T06:48:49Z","messageCount":2,"participants":["Xinyu Ruan via GitGitGadget","Patrick Steinhardt"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"529997","messageId":"pull.2089.git.git.1761881825025.gitgitgadget@gmail.com","threadId":"64407","inReplyTo":null,"subject":"[PATCH] refs: don't clear oid before read_raw_ref in the debug ref backend","fromName":"Xinyu Ruan via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2025-10-31T03:37:05Z","receivedAt":"2025-10-31T03:37:07Z","isPatch":true,"sender":{"key":"name:Xinyu Ruan","avatar":null},"body":"From: Xinyu Ruan <r200981113@gmail.com>\n\nThe debug_read_raw_ref function clears the oid to null_oid before\ncalling read_raw_ref, which causes the oid to be lost even when\nread_raw_ref successfully reads the reference. This leads to failures\nwhen executing commands like \"git branch new_branch <commit_id>\" with\nGIT_TRACE_REFS=1, as the command cannot find a valid branch point\nbecause the oid is null.\n\nSigned-off-by: Xinyu Ruan <r200981113@gmail.com>\n---\n    refs: don't clear oid before read_raw_ref in the debug ref backend\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2089%2FRuanXinyu%2Fref-debug-disable-clear-oid-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2089/RuanXinyu/ref-debug-disable-clear-oid-v1\nPull-Request: https://github.com/git/git/pull/2089\n\n refs/debug.c | 1 -\n 1 file changed, 1 deletion(-)\n\ndiff --git a/refs/debug.c b/refs/debug.c\nindex 697adbd0dc..c8dde3558d 100644\n--- a/refs/debug.c\n+++ b/refs/debug.c\n@@ -227,7 +227,6 @@ static int debug_read_raw_ref(struct ref_store *ref_store, const char *refname,\n \tstruct debug_ref_store *drefs = (struct debug_ref_store *)ref_store;\n \tint res = 0;\n \n-\toidcpy(oid, null_oid(ref_store->repo->hash_algo));\n \tres = drefs->refs->be->read_raw_ref(drefs->refs, refname, oid, referent,\n \t\t\t\t\t    type, failure_errno);\n \n\nbase-commit: a99f379adf116d53eb11957af5bab5214915f91d\n-- \ngitgitgadget\n"},{"id":"530017","messageId":"aQRbygXjkffQoNPi@pks.im","threadId":"64407","inReplyTo":"pull.2089.git.git.1761881825025.gitgitgadget@gmail.com","subject":"Re: [PATCH] refs: don't clear oid before read_raw_ref in the debug ref backend","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2025-10-31T06:48:42Z","receivedAt":"2025-10-31T06:48:49Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Fri, Oct 31, 2025 at 03:37:05AM +0000, Xinyu Ruan via GitGitGadget wrote:\n> From: Xinyu Ruan <r200981113@gmail.com>\n> \n> The debug_read_raw_ref function clears the oid to null_oid before\n> calling read_raw_ref, which causes the oid to be lost even when\n> read_raw_ref successfully reads the reference.\n\nThis sentence doesn't quite make sense to me. If `read_raw_ref()`\nsucceeds, wouldn't we expect that the OID was set to the target's object\nID anyway? So why does it hurt to set the object ID to the null ID if\nit's going to get rewritten anyway?\n\nAnother question is why we were setting it to the null OID in the first\nplace. Ideally, this should be discussed in the commit message.\n\n> This leads to failures\n> when executing commands like \"git branch new_branch <commit_id>\" with\n> GIT_TRACE_REFS=1, as the command cannot find a valid branch point\n> because the oid is null.\n\nThis smells like an issue that can be be demonstrated via a unit test.\nRight now though we got zero testing for `GIT_TRACE_REFS` in our test\nsuite. Maybe this could be used as a starting point for a new test suite\n\"t0620-ref-debug.sh\" that exercises the different callbacks?\n\nThanks!\n\nPatrick\n"}]}