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

[PATCH 5/6] object-file: treat cached_object values as const

From
Jeff King <peff@peff.net>
Date
Nov 18, 2024, 09:55 UTC
Message-ID
<20241118095519.GE3992317@coredump.intra.peff.net>
In-Reply-To
<20241118095423.GA3990835@coredump.intra.peff.net>

The cached-object API maps oids to in-memory entries. Once inserted, these entries should be immutable. Let's return them from the find_cached_object() call with a const tag to make this clear.

Suggested-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Jeff King <peff@peff.net>
---
 object-file.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/object-file.c b/object-file.c
index 67a6731066..ec62e5fb3b 100644
--- a/object-file.c
+++ b/object-file.c
@@ -327,14 +327,14 @@ static struct cached_object_entry {
 } *cached_objects;
 static int cached_object_nr, cached_object_alloc;
 
-static struct cached_object *find_cached_object(const struct object_id *oid)
+static const struct cached_object *find_cached_object(const struct object_id *oid)
 {
-	static struct cached_object empty_tree = {
+	static const struct cached_object empty_tree = {
 		.type = OBJ_TREE,
 		.buf = "",
 	};
 	int i;
-	struct cached_object_entry *co = cached_objects;
+	const struct cached_object_entry *co = cached_objects;
 
 	for (i = 0; i < cached_object_nr; i++, co++) {
 		if (oideq(&co->oid, oid))
@@ -1629,7 +1629,7 @@ static int do_oid_object_info_extended(struct repository *r,
 				       struct object_info *oi, unsigned flags)
 {
 	static struct object_info blank_oi = OBJECT_INFO_INIT;
-	struct cached_object *co;
+	const struct cached_object *co;
 	struct pack_entry e;
 	int rtype;
 	const struct object_id *real = oid;
-- 
2.47.0.547.g778689293a
Previous: Jeff KingNext: Jeff King
Message 22 of 25 in “-Wunterminated-string-initialization warning with GCC 15 in object-file.c”
  1. Sam JamesNov 17, 2024
  2. Jeff KingNov 17, 2024
  3. 1/5 object-file: prefer array-of-bytes initializer for hash literalsJeff King, Nov 17, 2024
  4. René ScharfeNov 17, 2024
  5. Jeff KingNov 18, 2024
  6. 2/5 object-file: drop confusing oid initializer of empty_tree structJeff King, Nov 17, 2024
  7. 3/5 object-file: move empty_tree struct into find_cached_object()Jeff King, Nov 17, 2024
  8. Patrick SteinhardtNov 18, 2024
  9. Jeff KingNov 18, 2024
  10. 4/5 object-file: drop oid field from find_cached_object() return valueJeff King, Nov 17, 2024
  11. 5/5 object-file: inline empty tree and blob literalsJeff King, Nov 17, 2024
  12. Patrick SteinhardtNov 18, 2024
  13. brian m. carlsonNov 17, 2024
  14. Jeff KingNov 18, 2024
  15. Sam JamesNov 18, 2024
  16. Patrick SteinhardtNov 18, 2024
  17. 0/6 -Wunterminated-string-initialization warning + cleanupsJeff King, Nov 18, 2024
  18. 1/6 object-file: prefer array-of-bytes initializer for hash literalsJeff King, Nov 18, 2024
  19. 2/6 object-file: drop confusing oid initializer of empty_tree structJeff King, Nov 18, 2024
  20. 3/6 object-file: move empty_tree struct into find_cached_object()Jeff King, Nov 18, 2024
  21. 4/6 object-file: drop oid field from find_cached_object() return valueJeff King, Nov 18, 2024
  22. 5/6 object-file: treat cached_object values as constJeff King, Nov 18, 2024
  23. 6/6 object-file: inline empty tree and blob literalsJeff King, Nov 18, 2024
  24. Patrick SteinhardtNov 18, 2024
  25. Junio C HamanoNov 18, 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.