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

[PATCH v3 9/9] builtin/cat-file: filter objects via object database

From
Patrick Steinhardt <ps@pks.im>
Date
Jul 13, 2026, 14:41 UTC
Message-ID
<20260713-pks-odb-for-each-object-filter-v3-9-b3c65c641073@pks.im>
In-Reply-To
<20260713-pks-odb-for-each-object-filter-v3-0-b3c65c641073@pks.im>

When batching all objects, git-cat-file(1) reaches into the internals of the object database and manually manages bitmaps to apply object filters. This creates coupling between the command and the internals of the respective backend.

Refactor git-cat-file(1) to use the new object filter option when batching all objects. This significantly simplifies the logic and ensures that we don't have to reach into internals of the "files" source anymore.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 builtin/cat-file.c | 76 +++++-------------------------------------------------
 1 file changed, 7 insertions(+), 69 deletions(-)
diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index b4b99a73da..1458dd76d6 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -20,7 +20,6 @@
 #include "userdiff.h"
 #include "oid-array.h"
 #include "packfile.h"
-#include "pack-bitmap.h"
 #include "object-file.h"
 #include "object-name.h"
 #include "odb.h"
@@ -844,28 +843,6 @@ static int batch_one_object_oi(const struct object_id *oid,
 	return payload->callback(oid, NULL, 0, payload->payload);
 }
 
-static int batch_one_object_packed(const struct object_id *oid,
-				   struct packed_git *pack,
-				   uint32_t pos,
-				   void *_payload)
-{
-	struct for_each_object_payload *payload = _payload;
-	return payload->callback(oid, pack, nth_packed_object_offset(pack, pos),
-				 payload->payload);
-}
-
-static int batch_one_object_bitmapped(const struct object_id *oid,
-				      enum object_type type UNUSED,
-				      int flags UNUSED,
-				      uint32_t hash UNUSED,
-				      struct packed_git *pack,
-				      off_t offset,
-				      void *_payload)
-{
-	struct for_each_object_payload *payload = _payload;
-	return payload->callback(oid, pack, offset, payload->payload);
-}
-
 static void batch_each_object(struct batch_options *opt,
 			      for_each_object_fn callback,
 			      unsigned flags,
@@ -875,56 +852,17 @@ static void batch_each_object(struct batch_options *opt,
 		.callback = callback,
 		.payload = _payload,
 	};
+	struct odb_source_info source_info;
+	struct object_info oi = {
+		.source_infop = &source_info,
+	};
 	struct odb_for_each_object_options opts = {
 		.flags = flags,
+		.filter = &opt->objects_filter,
 	};
-	struct bitmap_index *bitmap = NULL;
-	struct odb_source *source;
-
-	/*
-	 * TODO: we still need to tap into implementation details of the object
-	 * database sources. Ideally, we should extend `odb_for_each_object()`
-	 * to handle object filters itself so that we can move the filtering
-	 * logic into the individual sources.
-	 */
-	odb_prepare_alternates(the_repository->objects);
-	for (source = the_repository->objects->sources; source; source = source->next) {
-		struct odb_source_files *files = odb_source_files_downcast(source);
-		int ret = odb_source_for_each_object(&files->loose->base, NULL, batch_one_object_oi,
-						     &payload, &opts);
-		if (ret)
-			break;
-	}
-
-	if (opt->objects_filter.choice != LOFC_DISABLED &&
-	    (bitmap = prepare_bitmap_git(the_repository)) &&
-	    !for_each_bitmapped_object(bitmap, &opt->objects_filter,
-				       batch_one_object_bitmapped, &payload)) {
-		struct packed_git *pack;
-
-		repo_for_each_pack(the_repository, pack) {
-			if (bitmap_index_contains_pack(bitmap, pack) ||
-			    open_pack_index(pack))
-				continue;
-			for_each_object_in_pack(pack, batch_one_object_packed,
-						&payload, flags);
-		}
-	} else {
-		struct odb_source_info source_info;
-		struct object_info oi = {
-			.source_infop = &source_info,
-		};
-
-		for (source = the_repository->objects->sources; source; source = source->next) {
-			struct odb_source_files *files = odb_source_files_downcast(source);
-			int ret = odb_source_for_each_object(&files->packed->base, &oi,
-							     batch_one_object_oi, &payload, &opts);
-			if (ret)
-				break;
-		}
-	}
 
-	free_bitmap_index(bitmap);
+	odb_for_each_object_ext(the_repository->objects, &oi,
+				batch_one_object_oi, &payload, &opts);
 }
 
 static int batch_objects(struct batch_options *opt)
-- 
2.55.0.313.g8d093f411d.dirty
Previous: Toon ClaesNext: Toon Claes
Message 57 of 75 in “odb: introduce object filters to `odb_for_each_object()`”
  1. 0/7 odb: introduce object filters to `odb_for_each_object()`Patrick Steinhardt, Jul 9, 2026
  2. 1/7 odb/source-packed: improve lookup when enumerating objectsPatrick Steinhardt, Jul 9, 2026
  3. Justin ToblerJul 9, 2026
  4. Patrick SteinhardtJul 10, 2026
  5. 2/7 pack-bitmap: mark object filter as `const`Patrick Steinhardt, Jul 9, 2026
  6. 3/7 pack-bitmap: allow aborting iteration of bitmapped objectsPatrick Steinhardt, Jul 9, 2026
  7. Justin ToblerJul 9, 2026
  8. Patrick SteinhardtJul 10, 2026
  9. Jeff KingJul 11, 2026
  10. 4/7 pack-bitmap: iterate object sources when opening bitmapsPatrick Steinhardt, Jul 9, 2026
  11. Justin ToblerJul 9, 2026
  12. Patrick SteinhardtJul 10, 2026
  13. 5/7 pack-bitmap: introduce function to open bitmap for a single sourcePatrick Steinhardt, Jul 9, 2026
  14. 6/7 odb: introduce object filters to `odb_for_each_object()`Patrick Steinhardt, Jul 9, 2026
  15. Justin ToblerJul 9, 2026
  16. Patrick SteinhardtJul 10, 2026
  17. Toon ClaesJul 15, 2026
  18. 7/7 builtin/cat-file: filter objects via object databasePatrick Steinhardt, Jul 9, 2026
  19. Junio C HamanoJul 9, 2026
  20. Patrick SteinhardtJul 10, 2026
  21. 0/8 odb: introduce object filters to `odb_for_each_object()`Patrick Steinhardt, Jul 10, 2026
  22. 1/8 odb/source-packed: improve lookup when enumerating objectsPatrick Steinhardt, Jul 10, 2026
  23. Taylor BlauJul 10, 2026
  24. Patrick SteinhardtJul 13, 2026
  25. Taylor BlauJul 14, 2026
  26. Patrick SteinhardtJul 14, 2026
  27. 2/8 pack-bitmap: mark object filter as `const`Patrick Steinhardt, Jul 10, 2026
  28. Taylor BlauJul 10, 2026
  29. 3/8 pack-bitmap: allow aborting iteration of bitmapped objectsPatrick Steinhardt, Jul 10, 2026
  30. Taylor BlauJul 10, 2026
  31. Jeff KingJul 11, 2026
  32. Patrick SteinhardtJul 13, 2026
  33. Taylor BlauJul 14, 2026
  34. Jeff KingJul 14, 2026
  35. 4/8 pack-bitmap: iterate object sources when opening bitmapsPatrick Steinhardt, Jul 10, 2026
  36. Taylor BlauJul 10, 2026
  37. 5/8 pack-bitmap: drop `_1` suffix from functions that open bitmapsPatrick Steinhardt, Jul 10, 2026
  38. Taylor BlauJul 10, 2026
  39. 6/8 pack-bitmap: introduce function to open bitmap for a single sourcePatrick Steinhardt, Jul 10, 2026
  40. 7/8 odb: introduce object filters to `odb_for_each_object()`Patrick Steinhardt, Jul 10, 2026
  41. Taylor BlauJul 10, 2026
  42. 8/8 builtin/cat-file: filter objects via object databasePatrick Steinhardt, Jul 10, 2026
  43. 9/8 pack-objects: drop unused return value from add_object_entry()Jeff King, Jul 11, 2026
  44. Junio C HamanoJul 11, 2026
  45. 0/9 odb: introduce object filters to `odb_for_each_object()`Patrick Steinhardt, Jul 13, 2026
  46. 1/9 odb/source-packed: improve lookup when enumerating objectsPatrick Steinhardt, Jul 13, 2026
  47. 2/9 pack-bitmap: mark object filter as `const`Patrick Steinhardt, Jul 13, 2026
  48. 3/9 pack-objects: drop unused return value from add_object_entry()Patrick Steinhardt, Jul 13, 2026
  49. 4/9 pack-bitmap: allow aborting iteration of bitmapped objectsPatrick Steinhardt, Jul 13, 2026
  50. 5/9 pack-bitmap: iterate object sources when opening bitmapsPatrick Steinhardt, Jul 13, 2026
  51. 6/9 pack-bitmap: drop `_1` suffix from functions that open bitmapsPatrick Steinhardt, Jul 13, 2026
  52. 7/9 pack-bitmap: introduce function to open bitmap for a single sourcePatrick Steinhardt, Jul 13, 2026
  53. Toon ClaesJul 15, 2026
  54. Patrick SteinhardtJul 15, 2026
  55. 8/9 odb: introduce object filters to `odb_for_each_object()`Patrick Steinhardt, Jul 13, 2026
  56. Toon ClaesJul 15, 2026
  57. 9/9 builtin/cat-file: filter objects via object databasePatrick Steinhardt, Jul 13, 2026
  58. Toon ClaesJul 15, 2026
  59. Taylor BlauJul 14, 2026
  60. Patrick SteinhardtJul 14, 2026
  61. Toon ClaesJul 15, 2026
  62. Patrick SteinhardtJul 15, 2026
  63. Jeff KingJul 14, 2026
  64. 0/9 odb: introduce object filters to `odb_for_each_object()`Patrick Steinhardt, Jul 15, 2026
  65. 1/9 odb/source-packed: improve lookup when enumerating objectsPatrick Steinhardt, Jul 15, 2026
  66. 2/9 pack-bitmap: mark object filter as `const`Patrick Steinhardt, Jul 15, 2026
  67. 3/9 pack-objects: drop unused return value from add_object_entry()Patrick Steinhardt, Jul 15, 2026
  68. 4/9 pack-bitmap: allow aborting iteration of bitmapped objectsPatrick Steinhardt, Jul 15, 2026
  69. 5/9 pack-bitmap: iterate object sources when opening bitmapsPatrick Steinhardt, Jul 15, 2026
  70. 6/9 pack-bitmap: drop `_1` suffix from functions that open bitmapsPatrick Steinhardt, Jul 15, 2026
  71. 7/9 pack-bitmap: introduce function to open bitmap for a single sourcePatrick Steinhardt, Jul 15, 2026
  72. 8/9 odb: introduce object filters to `odb_for_each_object()`Patrick Steinhardt, Jul 15, 2026
  73. 9/9 builtin/cat-file: filter objects via object databasePatrick Steinhardt, Jul 15, 2026
  74. Toon ClaesJul 15, 2026
  75. Junio C HamanoJul 15, 2026

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.