git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v4 2/7] refs: specify error for regular refs with `old_target`

From
Karthik Nayak <karthik.188@gmail.com>
Date
Jun 5, 2024, 10:29 UTC
Message-ID
<20240605102958.716432-3-knayak@gitlab.com>
In-Reply-To
<https://lore.kernel.org/r/20240530120940.456817-1-knayak@gitlab.com>
From: Karthik Nayak <karthik.188@gmail.com>

When a regular reference update contains `old_target` set, we call the `ref_update_check_old_target` function to check the referent value. But for regular refs we know that the referent value is not set and this simply raises a generic error which says nothing about this being a regular ref. Instead let's raise a more specific error when a regular ref update contains `old_target`.

Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
---
 refs/files-backend.c    | 13 +++++++------
 refs/reftable-backend.c |  9 +++++++++
 2 files changed, 16 insertions(+), 6 deletions(-)
diff --git a/refs/files-backend.c b/refs/files-backend.c
index 194e74eb4d..f516d4d82f 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -2491,14 +2491,15 @@ static int lock_ref_for_update(struct files_ref_store *refs,
 
 		/*
 		 * Even if the ref is a regular ref, if `old_target` is set, we
-		 * check the referent value. Ideally `old_target` should only
-		 * be set for symrefs, but we're strict about its usage.
+		 * fail with an error.
 		 */
 		if (update->old_target) {
-			if (ref_update_check_old_target(referent.buf, update, err)) {
-				ret = TRANSACTION_GENERIC_ERROR;
-				goto out;
-			}
+			strbuf_addf(err, _("cannot update regular ref: '%s': "
+					   "symref target '%s' set"),
+				    ref_update_original_update_refname(update),
+				    update->old_target);
+			ret = TRANSACTION_GENERIC_ERROR;
+			goto out;
 		} else if  (check_old_oid(update, &lock->old_oid, err)) {
 			ret = TRANSACTION_GENERIC_ERROR;
 			goto out;
diff --git a/refs/reftable-backend.c b/refs/reftable-backend.c
index b838cf8f00..bd89ce8d76 100644
--- a/refs/reftable-backend.c
+++ b/refs/reftable-backend.c
@@ -928,6 +928,15 @@ static int reftable_be_transaction_prepare(struct ref_store *ref_store,
 		 * backend returns, which keeps our tests happy.
 		 */
 		if (u->old_target) {
+			if (!(u->type & REF_ISSYMREF)) {
+				strbuf_addf(err, _("cannot update regular ref: '%s': "
+					    "symref target '%s' set"),
+					    ref_update_original_update_refname(u),
+					    u->old_target);
+				ret = -1;
+				goto done;
+			}
+
 			if (ref_update_check_old_target(referent.buf, u, err)) {
 				ret = -1;
 				goto done;
-- 
2.43.GIT
Previous: Karthik NayakNext: Patrick Steinhardt
Message 15 of 22 in “update-ref: add symref support for --stdin”
  1. 0/7 update-ref: add symref support for --stdinKarthik Nayak, Jun 5, 2024
  2. Karthik NayakJun 6, 2024
  3. Karthik NayakJun 6, 2024
  4. 0/7 update-ref: add symref support for --stdinKarthik Nayak, Jun 7, 2024
  5. 1/7 refs: create and use `ref_update_expects_existing_old_ref()`Karthik Nayak, Jun 7, 2024
  6. 2/7 refs: specify error for regular refs with `old_target`Karthik Nayak, Jun 7, 2024
  7. Patrick SteinhardtJun 10, 2024
  8. Karthik NayakJun 10, 2024
  9. 3/7 update-ref: add support for 'symref-verify' commandKarthik Nayak, Jun 7, 2024
  10. 4/7 update-ref: add support for 'symref-delete' commandKarthik Nayak, Jun 7, 2024
  11. 5/7 update-ref: add support for 'symref-create' commandKarthik Nayak, Jun 7, 2024
  12. 6/7 reftable: pick either 'oid' or 'target' for new updatesKarthik Nayak, Jun 7, 2024
  13. 7/7 update-ref: add support for 'symref-update' commandKarthik Nayak, Jun 7, 2024
  14. 1/7 refs: create and use `ref_update_expects_existing_old_ref()`Karthik Nayak, Jun 5, 2024
  15. 2/7 refs: specify error for regular refs with `old_target`Karthik Nayak, Jun 5, 2024
  16. Patrick SteinhardtJun 6, 2024
  17. Karthik NayakJun 6, 2024
  18. 3/7 update-ref: add support for 'symref-verify' commandKarthik Nayak, Jun 5, 2024
  19. 4/7 update-ref: add support for 'symref-delete' commandKarthik Nayak, Jun 5, 2024
  20. 5/7 update-ref: add support for 'symref-create' commandKarthik Nayak, Jun 5, 2024
  21. 6/7 reftable: pick either 'oid' or 'target' for new updatesKarthik Nayak, Jun 5, 2024
  22. 7/7 update-ref: add support for 'symref-update' commandKarthik Nayak, Jun 5, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.