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

[PATCH v3 04/12] refs: allow to skip creation of reflog entries

From
Patrick Steinhardt <ps@pks.im>
Date
May 28, 2024, 06:31 UTC
Message-ID
<d0539b7456e29fad5c2d1af76657207a199a5d9a.1716877224.git.ps@pks.im>
In-Reply-To
<cover.1716877224.git.ps@pks.im>

The ref backends do not have any way to disable the creation of reflog entries. This will be required for upcoming ref format migration logic so that we do not create any entries that didn't exist in the original ref database.

Provide a new `REF_SKIP_CREATE_REFLOG` flag that allows the caller to disable reflog entry creation.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 refs.c                    | 6 ++++++
 refs.h                    | 8 +++++++-
 refs/files-backend.c      | 4 ++++
 refs/reftable-backend.c   | 3 ++-
 t/helper/test-ref-store.c | 1 +
 5 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/refs.c b/refs.c
index 7c3f4df457..66e9585767 100644
--- a/refs.c
+++ b/refs.c
@@ -1194,6 +1194,12 @@ int ref_transaction_update(struct ref_transaction *transaction,
 {
 	assert(err);
 
+	if ((flags & REF_FORCE_CREATE_REFLOG) &&
+	    (flags & REF_SKIP_CREATE_REFLOG)) {
+		strbuf_addstr(err, _("refusing to force and skip creation of reflog"));
+		return -1;
+	}
+
 	if (!(flags & REF_SKIP_REFNAME_VERIFICATION) &&
 	    ((new_oid && !is_null_oid(new_oid)) ?
 		     check_refname_format(refname, REFNAME_ALLOW_ONELEVEL) :
diff --git a/refs.h b/refs.h
index a7afa9bede..50a2b3ab09 100644
--- a/refs.h
+++ b/refs.h
@@ -659,13 +659,19 @@ struct ref_transaction *ref_store_transaction_begin(struct ref_store *refs,
  */
 #define REF_SKIP_REFNAME_VERIFICATION (1 << 11)
 
+/*
+ * Skip creation of a reflog entry, even if it would have otherwise been
+ * created.
+ */
+#define REF_SKIP_CREATE_REFLOG (1 << 12)
+
 /*
  * Bitmask of all of the flags that are allowed to be passed in to
  * ref_transaction_update() and friends:
  */
 #define REF_TRANSACTION_UPDATE_ALLOWED_FLAGS                                  \
 	(REF_NO_DEREF | REF_FORCE_CREATE_REFLOG | REF_SKIP_OID_VERIFICATION | \
-	 REF_SKIP_REFNAME_VERIFICATION)
+	 REF_SKIP_REFNAME_VERIFICATION | REF_SKIP_CREATE_REFLOG)
 
 /*
  * Add a reference update to transaction. `new_oid` is the value that
diff --git a/refs/files-backend.c b/refs/files-backend.c
index 73380d7e99..bd0d63bcba 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -1750,6 +1750,9 @@ static int files_log_ref_write(struct files_ref_store *refs,
 {
 	int logfd, result;
 
+	if (flags & REF_SKIP_CREATE_REFLOG)
+		return 0;
+
 	if (log_all_ref_updates == LOG_REFS_UNSET)
 		log_all_ref_updates = is_bare_repository() ? LOG_REFS_NONE : LOG_REFS_NORMAL;
 
@@ -2251,6 +2254,7 @@ static int split_head_update(struct ref_update *update,
 	struct ref_update *new_update;
 
 	if ((update->flags & REF_LOG_ONLY) ||
+	    (update->flags & REF_SKIP_CREATE_REFLOG) ||
 	    (update->flags & REF_IS_PRUNING) ||
 	    (update->flags & REF_UPDATE_VIA_HEAD))
 		return 0;
diff --git a/refs/reftable-backend.c b/refs/reftable-backend.c
index f6edfdf5b3..bffed9257f 100644
--- a/refs/reftable-backend.c
+++ b/refs/reftable-backend.c
@@ -1103,7 +1103,8 @@ static int write_transaction_table(struct reftable_writer *writer, void *cb_data
 
 			if (ret)
 				goto done;
-		} else if (u->flags & REF_HAVE_NEW &&
+		} else if (!(u->flags & REF_SKIP_CREATE_REFLOG) &&
+			   (u->flags & REF_HAVE_NEW) &&
 			   (u->flags & REF_FORCE_CREATE_REFLOG ||
 			    should_write_log(&arg->refs->base, u->refname))) {
 			struct reftable_log_record *log;
diff --git a/t/helper/test-ref-store.c b/t/helper/test-ref-store.c
index c9efd74c2b..ad24300170 100644
--- a/t/helper/test-ref-store.c
+++ b/t/helper/test-ref-store.c
@@ -126,6 +126,7 @@ static struct flag_definition transaction_flags[] = {
 	FLAG_DEF(REF_FORCE_CREATE_REFLOG),
 	FLAG_DEF(REF_SKIP_OID_VERIFICATION),
 	FLAG_DEF(REF_SKIP_REFNAME_VERIFICATION),
+	FLAG_DEF(REF_SKIP_CREATE_REFLOG),
 	{ NULL, 0 }
 };
 
-- 
2.45.1.246.gb9cfe4845c.dirty
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 42 of 103 in “refs: ref storage format migrations”
  1. 0/9 refs: ref storage format migrationsPatrick Steinhardt, May 23, 2024
  2. 1/9 setup: unset ref storage when reinitializing repository versionPatrick Steinhardt, May 23, 2024
  3. 2/9 refs: convert ref storage format to an enumPatrick Steinhardt, May 23, 2024
  4. 3/9 refs: pass storage format to `ref_store_init()` explicitlyPatrick Steinhardt, May 23, 2024
  5. 4/9 refs: allow to skip creation of reflog entriesPatrick Steinhardt, May 23, 2024
  6. 5/9 refs/files: refactor `add_pseudoref_and_head_entries()`Patrick Steinhardt, May 23, 2024
  7. 6/9 refs/files: extract function to iterate through root refsPatrick Steinhardt, May 23, 2024
  8. 7/9 refs: implement removal of ref storagesPatrick Steinhardt, May 23, 2024
  9. 8/9 refs: implement logic to migrate between ref storage formatsPatrick Steinhardt, May 23, 2024
  10. Eric SunshineMay 23, 2024
  11. Patrick SteinhardtMay 24, 2024
  12. Eric SunshineMay 24, 2024
  13. 9/9 builtin/refs: new command to migrate ref storage formatsPatrick Steinhardt, May 23, 2024
  14. Eric SunshineMay 23, 2024
  15. Patrick SteinhardtMay 24, 2024
  16. Junio C HamanoMay 23, 2024
  17. Patrick SteinhardtMay 24, 2024
  18. Junio C HamanoMay 24, 2024
  19. Patrick SteinhardtMay 28, 2024
  20. Junio C HamanoMay 28, 2024
  21. 0/9 refs: ref storage format migrationsPatrick Steinhardt, May 24, 2024
  22. 1/9 setup: unset ref storage when reinitializing repository versionPatrick Steinhardt, May 24, 2024
  23. Justin ToblerMay 24, 2024
  24. Patrick SteinhardtMay 28, 2024
  25. 2/9 refs: convert ref storage format to an enumPatrick Steinhardt, May 24, 2024
  26. 3/9 refs: pass storage format to `ref_store_init()` explicitlyPatrick Steinhardt, May 24, 2024
  27. 4/9 refs: allow to skip creation of reflog entriesPatrick Steinhardt, May 24, 2024
  28. 5/9 refs/files: refactor `add_pseudoref_and_head_entries()`Patrick Steinhardt, May 24, 2024
  29. 6/9 refs/files: extract function to iterate through root refsPatrick Steinhardt, May 24, 2024
  30. 7/9 refs: implement removal of ref storagesPatrick Steinhardt, May 24, 2024
  31. 8/9 refs: implement logic to migrate between ref storage formatsPatrick Steinhardt, May 24, 2024
  32. Justin ToblerMay 24, 2024
  33. Patrick SteinhardtMay 28, 2024
  34. 9/9 builtin/refs: new command to migrate ref storage formatsPatrick Steinhardt, May 24, 2024
  35. Ramsay JonesMay 24, 2024
  36. Eric SunshineMay 24, 2024
  37. Patrick SteinhardtMay 28, 2024
  38. 00/12 refs: ref storage format migrationsPatrick Steinhardt, May 28, 2024
  39. 01/12 setup: unset ref storage when reinitializing repository versionPatrick Steinhardt, May 28, 2024
  40. 02/12 refs: convert ref storage format to an enumPatrick Steinhardt, May 28, 2024
  41. 03/12 refs: pass storage format to `ref_store_init()` explicitlyPatrick Steinhardt, May 28, 2024
  42. 04/12 refs: allow to skip creation of reflog entriesPatrick Steinhardt, May 28, 2024
  43. 05/12 refs/files: refactor `add_pseudoref_and_head_entries()`Patrick Steinhardt, May 28, 2024
  44. 06/12 refs/files: extract function to iterate through root refsPatrick Steinhardt, May 28, 2024
  45. 07/12 refs/files: fix NULL pointer deref when releasing ref storePatrick Steinhardt, May 28, 2024
  46. 08/12 reftable: inline `merged_table_release()`Patrick Steinhardt, May 28, 2024
  47. 09/12 worktree: don't store main worktree twicePatrick Steinhardt, May 28, 2024
  48. 10/12 refs: implement removal of ref storagesPatrick Steinhardt, May 28, 2024
  49. 11/12 refs: implement logic to migrate between ref storage formatsPatrick Steinhardt, May 28, 2024
  50. 12/12 builtin/refs: new command to migrate ref storage formatsPatrick Steinhardt, May 28, 2024
  51. Junio C HamanoMay 31, 2024
  52. Junio C HamanoJun 2, 2024
  53. Patrick SteinhardtJun 3, 2024
  54. Junio C HamanoMay 28, 2024
  55. Junio C HamanoMay 28, 2024
  56. 00/12 refs: ref storage migrationsPatrick Steinhardt, Jun 3, 2024
  57. 01/12 setup: unset ref storage when reinitializing repository versionPatrick Steinhardt, Jun 3, 2024
  58. 02/12 refs: convert ref storage format to an enumPatrick Steinhardt, Jun 3, 2024
  59. 03/12 refs: pass storage format to `ref_store_init()` explicitlyPatrick Steinhardt, Jun 3, 2024
  60. Karthik NayakJun 4, 2024
  61. 04/12 refs: allow to skip creation of reflog entriesPatrick Steinhardt, Jun 3, 2024
  62. Karthik NayakJun 4, 2024
  63. 05/12 refs/files: refactor `add_pseudoref_and_head_entries()`Patrick Steinhardt, Jun 3, 2024
  64. 06/12 refs/files: extract function to iterate through root refsPatrick Steinhardt, Jun 3, 2024
  65. Jeff KingJun 5, 2024
  66. Patrick SteinhardtJun 6, 2024
  67. Patrick SteinhardtJun 6, 2024
  68. Patrick SteinhardtJun 6, 2024
  69. 07/12 refs/files: fix NULL pointer deref when releasing ref storePatrick Steinhardt, Jun 3, 2024
  70. 08/12 reftable: inline `merged_table_release()`Patrick Steinhardt, Jun 3, 2024
  71. 09/12 worktree: don't store main worktree twicePatrick Steinhardt, Jun 3, 2024
  72. 10/12 refs: implement removal of ref storagesPatrick Steinhardt, Jun 3, 2024
  73. Karthik NayakJun 4, 2024
  74. Jeff KingJun 5, 2024
  75. Junio C HamanoJun 5, 2024
  76. Patrick SteinhardtJun 6, 2024
  77. 11/12 refs: implement logic to migrate between ref storage formatsPatrick Steinhardt, Jun 3, 2024
  78. Karthik NayakJun 4, 2024
  79. Patrick SteinhardtJun 5, 2024
  80. Jeff KingJun 5, 2024
  81. Junio C HamanoJun 5, 2024
  82. Patrick SteinhardtJun 6, 2024
  83. Jeff KingJun 6, 2024
  84. Junio C HamanoJun 6, 2024
  85. Jeff KingJun 8, 2024
  86. Junio C HamanoJun 8, 2024
  87. Patrick SteinhardtJun 6, 2024
  88. 12/12 builtin/refs: new command to migrate ref storage formatsPatrick Steinhardt, Jun 3, 2024
  89. 00/12 refs: ref storage migrationsPatrick Steinhardt, Jun 6, 2024
  90. 01/12 setup: unset ref storage when reinitializing repository versionPatrick Steinhardt, Jun 6, 2024
  91. 02/12 refs: convert ref storage format to an enumPatrick Steinhardt, Jun 6, 2024
  92. 03/12 refs: pass storage format to `ref_store_init()` explicitlyPatrick Steinhardt, Jun 6, 2024
  93. 04/12 refs: allow to skip creation of reflog entriesPatrick Steinhardt, Jun 6, 2024
  94. 05/12 refs/files: refactor `add_pseudoref_and_head_entries()`Patrick Steinhardt, Jun 6, 2024
  95. 06/12 refs/files: extract function to iterate through root refsPatrick Steinhardt, Jun 6, 2024
  96. 07/12 refs/files: fix NULL pointer deref when releasing ref storePatrick Steinhardt, Jun 6, 2024
  97. 08/12 reftable: inline `merged_table_release()`Patrick Steinhardt, Jun 6, 2024
  98. 09/12 worktree: don't store main worktree twicePatrick Steinhardt, Jun 6, 2024
  99. 10/12 refs: implement removal of ref storagesPatrick Steinhardt, Jun 6, 2024
  100. 11/12 refs: implement logic to migrate between ref storage formatsPatrick Steinhardt, Jun 6, 2024
  101. 12/12 builtin/refs: new command to migrate ref storage formatsPatrick Steinhardt, Jun 6, 2024
  102. Jeff KingJun 6, 2024
  103. Junio C HamanoJun 6, 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.