From 4a87304df04cd872260becf7ad9056bd32bd550f Mon Sep 17 00:00:00 2001 From: Karthik Nayak Date: Wed, 22 Jan 2025 09:48:56 +0100 Subject: [PATCH 1/2] reflog: fix bug which didn't resolve symref reflogs The patch is based on maint f93ff170b9 (Git 2.48.1, 2025-01-13). This was definitely a case of premature optimization which wasn't needed. Unfortunately, there was no test which captured this, eventhough the flow is quite critical. As such, I've added a test in my patch. Sorry for the inconvenience! Signed-off-by: Karthik Nayak --- b4-submit-tracking --- # This section is used internally by b4 prep for tracking purposes. { "series": { "revision": 2, "change-id": "20250122-482-corrupted-reflog-entry-for-symrefs-created-when-targets-are-updated-f3b034eae266", "prefixes": [] } } -- GitLab From 0e9983bc6457bfab50069700afca6e166bb7e19c Mon Sep 17 00:00:00 2001 From: Karthik Nayak Date: Wed, 22 Jan 2025 09:50:19 +0100 Subject: [PATCH 2/2] refs: fix creation of corrupted reflogs for symrefs The commit 297c09eabb (refs: allow multiple reflog entries for the same refname, 2024-12-16) added logic for reflogs to exit early in `lock_ref_for_update()` after obtaining the required lock. This was added as a performance optimization as it was assumed that no further processing was required for reflog-only updates. However this was incorrect since for a symref's reflog entry, the update needs to be populated with the old_oid value. This is done right after the early exit. This caused a bug in Git 2.48 in the files backend where target references of symrefs being updated would create a corrupted reflog entry for the symref since the old_oid is not populated. Undo the skip in logic to fix this issue and also add a test to ensure that such an issue doesn't arise in the future. The early exit was added as a performance optimization for reflog-only updates, and it wasn't essential to the original changes. As such, reverting it shouldn't cause any further issues. Reported-by: Nika Layzell Co-authored-by: Jeff King Signed-off-by: Karthik Nayak --- refs/files-backend.c | 3 --- t/t1400-update-ref.sh | 9 +++++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/refs/files-backend.c b/refs/files-backend.c index 5cfb8b7ca86..29f08dced40 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -2615,9 +2615,6 @@ static int lock_ref_for_update(struct files_ref_store *refs, update->backend_data = lock; - if (update->flags & REF_LOG_ONLY) - goto out; - if (update->type & REF_ISSYMREF) { if (update->flags & REF_NO_DEREF) { /* diff --git a/t/t1400-update-ref.sh b/t/t1400-update-ref.sh index e2316f1dd4c..29045aad439 100755 --- a/t/t1400-update-ref.sh +++ b/t/t1400-update-ref.sh @@ -2068,4 +2068,13 @@ do done +test_expect_success 'update-ref should also create reflog for HEAD' ' + test_commit to-rewind && + git rev-parse HEAD >expect && + head=$(git symbolic-ref HEAD) && + git update-ref --create-reflog "$head" HEAD~ && + git rev-parse HEAD@{1} >actual && + test_cmp expect actual +' + test_done -- GitLab