{"thread":{"id":"62842","subject":"[PATCH] refs: fix migration of reflogs respecting \"core.logAllRefUpdates\"","startedAt":"2025-01-22T09:48:11Z","lastAt":"2025-01-22T18:02:04Z","messageCount":2,"participants":["Patrick Steinhardt","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"511046","messageId":"20250122-b4-pks-reflog-migration-fix-stash-v1-1-27dbae4602f7@pks.im","threadId":"62842","inReplyTo":null,"subject":"[PATCH] refs: fix migration of reflogs respecting \"core.logAllRefUpdates\"","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2025-01-22T09:48:06Z","receivedAt":"2025-01-22T09:48:11Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"In 246cebe320 (refs: add support for migrating reflogs, 2024-12-16) we\nhave added support to git-refs(1) to migrate reflogs between reference\nbackends. It was reported [1] though that not we don't migrate reflogs\nfor a subset of references, most importantly \"refs/stash\".\n\nThis issue is caused by us still honoring \"core.logAllRefUpdates\" when\ntrying to migrate reflogs: we do queue the updates, but depending on the\nvalue of that config we may decide to just skip writing the reflog entry\naltogether. And given that:\n\n  - The default for \"core.logAllRefUpdates\" is to only create reflogs\n    for branches, remotes, note refs and \"HEAD\"\n\n  - \"refs/stash\" is neither of these ref types.\n\nWe end up skipping the reflog creation for that particular reference.\n\nFix the bug by setting `REF_FORCE_CREATE_REFLOG`, which instructs the\nref backends to create the reflog entry regardless of the config or any\npreexisting state.\n\n[1]: <Z5BTQRlsOj1sygun@tapette.crustytoothpaste.net>\n\nReported-by: brian m. carlson <sandals@crustytoothpaste.net>\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\nHi,\n\nthis patch addresses the issue reported by brian where \"refs/stash\"\nisn't getting migrated correctly. The patch is based on top of \"maint\"\nso that it can be easily backported.\n\nThanks for the report!\n\nPatrick\n---\n refs.c                  |  2 +-\n t/t1460-refs-migrate.sh | 17 +++++++++++++++++\n 2 files changed, 18 insertions(+), 1 deletion(-)\n\ndiff --git a/refs.c b/refs.c\nindex 0f41b2fd4a..37b8cfb90c 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -1330,7 +1330,7 @@ int ref_transaction_update_reflog(struct ref_transaction *transaction,\n \n \tassert(err);\n \n-\tflags |= REF_LOG_ONLY | REF_NO_DEREF;\n+\tflags |= REF_LOG_ONLY | REF_FORCE_CREATE_REFLOG | REF_NO_DEREF;\n \n \tif (!transaction_refname_valid(refname, new_oid, flags, err))\n \t\treturn -1;\ndiff --git a/t/t1460-refs-migrate.sh b/t/t1460-refs-migrate.sh\nindex f59bc4860f..ceb0c4977d 100755\n--- a/t/t1460-refs-migrate.sh\n+++ b/t/t1460-refs-migrate.sh\n@@ -224,6 +224,23 @@ do\n \t\t\ttest_commit --date \"100003000 +0700\" --no-tag -C repo second &&\n \t\t\ttest_migration repo \"$to_format\"\n \t\t'\n+\n+\t\ttest_expect_success \"$from_format -> $to_format: stash is retained\" '\n+\t\t\ttest_when_finished \"rm -rf repo\" &&\n+\t\t\tgit init --ref-format=$from_format repo &&\n+\t\t\t(\n+\t\t\t\tcd repo &&\n+\t\t\t\ttest_commit initial A &&\n+\t\t\t\techo foo >A &&\n+\t\t\t\tgit stash push &&\n+\t\t\t\techo bar >A &&\n+\t\t\t\tgit stash push &&\n+\t\t\t\tgit stash list >expect.reflog &&\n+\t\t\t\ttest_migration . \"$to_format\" &&\n+\t\t\t\tgit stash list >actual.reflog &&\n+\t\t\t\ttest_cmp expect.reflog actual.reflog\n+\t\t\t)\n+\t\t'\n \tdone\n done\n \n\n---\nbase-commit: f93ff170b93a1782659637824b25923245ac9dd1\nchange-id: 20250122-b4-pks-reflog-migration-fix-stash-d1fe7380f84a\n\n"},{"id":"511081","messageId":"xmqqjzamwwva.fsf@gitster.g","threadId":"62842","inReplyTo":"20250122-b4-pks-reflog-migration-fix-stash-v1-1-27dbae4602f7@pks.im","subject":"Re: [PATCH] refs: fix migration of reflogs respecting \"core.logAllRefUpdates\"","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2025-01-22T18:02:01Z","receivedAt":"2025-01-22T18:02:04Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Patrick Steinhardt <ps@pks.im> writes:\n\n> In 246cebe320 (refs: add support for migrating reflogs, 2024-12-16) we\n> have added support to git-refs(1) to migrate reflogs between reference\n> backends. It was reported [1] though that not we don't migrate reflogs\n> for a subset of references, most importantly \"refs/stash\".\n>\n> This issue is caused by us still honoring \"core.logAllRefUpdates\" when\n> trying to migrate reflogs: we do queue the updates, but depending on the\n> value of that config we may decide to just skip writing the reflog entry\n> altogether. And given that:\n>\n>   - The default for \"core.logAllRefUpdates\" is to only create reflogs\n>     for branches, remotes, note refs and \"HEAD\"\n>\n>   - \"refs/stash\" is neither of these ref types.\n>\n> We end up skipping the reflog creation for that particular reference.\n>\n> Fix the bug by setting `REF_FORCE_CREATE_REFLOG`, which instructs the\n> ref backends to create the reflog entry regardless of the config or any\n> preexisting state.\n\nThanks for a clear problem analysis description.  The appraoch makes\nperfect sense.\n\nWill queue.\n\n> +\t\ttest_expect_success \"$from_format -> $to_format: stash is retained\" '\n> +\t\t\ttest_when_finished \"rm -rf repo\" &&\n> +\t\t\tgit init --ref-format=$from_format repo &&\n> +\t\t\t(\n> +\t\t\t\tcd repo &&\n> +\t\t\t\ttest_commit initial A &&\n> +\t\t\t\techo foo >A &&\n> +\t\t\t\tgit stash push &&\n> +\t\t\t\techo bar >A &&\n> +\t\t\t\tgit stash push &&\n> +\t\t\t\tgit stash list >expect.reflog &&\n> +\t\t\t\ttest_migration . \"$to_format\" &&\n> +\t\t\t\tgit stash list >actual.reflog &&\n> +\t\t\t\ttest_cmp expect.reflog actual.reflog\n> +\t\t\t)\n> +\t\t'\n>  \tdone\n>  done\n>  \n>\n> ---\n> base-commit: f93ff170b93a1782659637824b25923245ac9dd1\n> change-id: 20250122-b4-pks-reflog-migration-fix-stash-d1fe7380f84a\n"}]}