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

[PATCH 2/3] refs: use 'uint64_t' for 'ref_update.index'

From
Karthik Nayak <karthik.188@gmail.com>
Date
Jan 17, 2025, 07:59 UTC
Message-ID
<20250117-461-corrupted-reftable-followup-v1-2-70ee605ae3fe@gmail.com>
In-Reply-To
<20250117-461-corrupted-reftable-followup-v1-0-70ee605ae3fe@gmail.com>

The 'ref_update.index' variable is used to store an index for a given reference update. This index is used to order the updates in a predetermined order, while the default ordering is alphabetical as per the refname.

For large repositories with millions of references, it should be safer to use 'uint64_t'. Let's do that. This also is applied for all other code sections where we store 'index' and pass it around.

Reported-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
---
 refs.c                  | 4 ++--
 refs/refs-internal.h    | 4 ++--
 refs/reftable-backend.c | 2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/refs.c b/refs.c
index 1bb6f0356d5c5cae8bea9d6f4d5ff35164a03c64..0de23f91b2e4401e93aee6940d4aa2abea4312cf 100644
--- a/refs.c
+++ b/refs.c
@@ -1325,7 +1325,7 @@ static int ref_transaction_update_reflog(struct ref_transaction *transaction,
 					 const char *committer_info,
 					 unsigned int flags,
 					 const char *msg,
-					 unsigned int index,
+					 uint64_t index,
 					 struct strbuf *err)
 {
 	struct ref_update *update;
@@ -2807,7 +2807,7 @@ static int migrate_one_ref(const char *refname, const char *referent UNUSED, con
 }
 
 struct reflog_migration_data {
-	unsigned int index;
+	uint64_t index;
 	const char *refname;
 	struct ref_store *old_refs;
 	struct ref_transaction *transaction;
diff --git a/refs/refs-internal.h b/refs/refs-internal.h
index aaab711bb96844755dfa600d37efdb25b30a0765..8894b43d1d1a327d404d3923c507d2d39649de19 100644
--- a/refs/refs-internal.h
+++ b/refs/refs-internal.h
@@ -120,7 +120,7 @@ struct ref_update {
 	 * when migrating reflogs and we want to ensure we carry over the
 	 * same order.
 	 */
-	unsigned int index;
+	uint64_t index;
 
 	/*
 	 * If this ref_update was split off of a symref update via
@@ -203,7 +203,7 @@ struct ref_transaction {
 	enum ref_transaction_state state;
 	void *backend_data;
 	unsigned int flags;
-	unsigned int max_index;
+	uint64_t max_index;
 };
 
 /*
diff --git a/refs/reftable-backend.c b/refs/reftable-backend.c
index 289496058e6eb4d3e3aef96ca70219cd4ff78eae..6814c87bc618229ac8a70b904be3f850371ad876 100644
--- a/refs/reftable-backend.c
+++ b/refs/reftable-backend.c
@@ -942,7 +942,7 @@ struct write_transaction_table_arg {
 	size_t updates_nr;
 	size_t updates_alloc;
 	size_t updates_expected;
-	unsigned int max_index;
+	uint64_t max_index;
 };
 
 struct reftable_transaction_data {
-- 
2.47.0
Previous: Karthik NayakNext: Karthik Nayak
Message 5 of 30 in “refs: small followups to the migration corruption fix”
  1. 0/3 refs: small followups to the migration corruption fixKarthik Nayak, Jan 17, 2025
  2. 1/3 refs: mark `ref_transaction_update_reflog()` as staticKarthik Nayak, Jan 17, 2025
  3. Patrick SteinhardtJan 17, 2025
  4. Karthik NayakJan 20, 2025
  5. 2/3 refs: use 'uint64_t' for 'ref_update.index'Karthik Nayak, Jan 17, 2025
  6. 3/3 reftable: prevent 'update_index' changes after header writeKarthik Nayak, Jan 17, 2025
  7. Patrick SteinhardtJan 17, 2025
  8. Karthik NayakJan 20, 2025
  9. Karthik NayakJan 20, 2025
  10. 0/3 refs: small followups to the migration corruption fixKarthik Nayak, Jan 21, 2025
  11. 1/3 refs: mark `ref_transaction_update_reflog()` as staticKarthik Nayak, Jan 21, 2025
  12. 2/3 refs: use 'uint64_t' for 'ref_update.index'Karthik Nayak, Jan 21, 2025
  13. 3/3 reftable: prevent 'update_index' changes after adding recordsKarthik Nayak, Jan 21, 2025
  14. Patrick SteinhardtJan 21, 2025
  15. Karthik NayakJan 21, 2025
  16. 0/3 refs: small followups to the migration corruption fixKarthik Nayak, Jan 22, 2025
  17. 1/3 refs: mark `ref_transaction_update_reflog()` as staticKarthik Nayak, Jan 22, 2025
  18. 2/3 refs: use 'uint64_t' for 'ref_update.index'Karthik Nayak, Jan 22, 2025
  19. 3/3 reftable: prevent 'update_index' changes after adding recordsKarthik Nayak, Jan 22, 2025
  20. Patrick SteinhardtJan 22, 2025
  21. Junio C HamanoJan 22, 2025
  22. Junio C HamanoJan 22, 2025
  23. undefined behavior in unit tests, was Re: [PATCH v3 3/3] reftable: prevent 'update_index' changes after adding recordsJeff King, Feb 1, 2025
  24. Phillip WoodFeb 1, 2025
  25. Patrick SteinhardtFeb 3, 2025
  26. Junio C HamanoFeb 3, 2025
  27. Jeff KingFeb 3, 2025
  28. Patrick SteinhardtFeb 3, 2025
  29. Karthik NayakFeb 3, 2025
  30. Jeff KingFeb 3, 2025

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.