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

Re: [PATCH 03/14] odb: introduce `struct odb_for_each_object_options`

From
Karthik Nayak <karthik.188@gmail.com>
Date
Mar 20, 2026, 09:01 UTC
Message-ID
<CAOLa=ZRpCunxE_F1AG-aFqHiyVZ=c+T_wFwpfxC7vFm7dKxqAw@mail.gmail.com>
In-Reply-To
<20260319-b4-pks-odb-source-abbrev-v1-3-5ddebad292b0@pks.im>
Patrick Steinhardt <ps@pks.im> writes:
Show 11 quoted lines
> The `odb_for_each_object()` function only accepts a bitset of flags. In
> a subsequent commit we'll want to change object iteration to also
> support iterating over only those objects that have a specific prefix.
> While we could of course add the prefix to the function signature, or
> alternative introduce a new function, both of these options don't really
> seem to be that sensible.
>
> Instead, introduce a new `struct odb_for_each_object_options` that can
> be passed to a new `odb_for_each_object_ext()` function. Splice through
> the options structure into the respective object database sources.
>

Yeah I like this pattern, really cleans up the arguments sent into a function. Making future additions to the struct produce a localized diff rather than modifying the function params each time. Nice.

Show 74 quoted lines
> Signed-off-by: Patrick Steinhardt <ps@pks.im>
> ---
>  builtin/cat-file.c     |  7 +++++--
>  builtin/pack-objects.c | 12 +++++++-----
>  commit-graph.c         |  5 ++++-
>  object-file.c          |  6 +++---
>  object-file.h          |  2 +-
>  odb.c                  | 26 +++++++++++++++++++-------
>  odb.h                  | 16 ++++++++++++++++
>  odb/source-files.c     |  8 ++++----
>  odb/source.h           |  6 +++---
>  packfile.c             | 12 ++++++------
>  packfile.h             |  2 +-
>  11 files changed, 69 insertions(+), 33 deletions(-)
>
> diff --git a/builtin/cat-file.c b/builtin/cat-file.c
> index b6f12f41d6..cd13a3a89f 100644
> --- a/builtin/cat-file.c
> +++ b/builtin/cat-file.c
> @@ -848,6 +848,9 @@ static void batch_each_object(struct batch_options *opt,
>  		.callback = callback,
>  		.payload = _payload,
>  	};
> +	struct odb_for_each_object_options opts = {
> +		.flags = flags,
> +	};
>  	struct bitmap_index *bitmap = NULL;
>  	struct odb_source *source;
>
> @@ -860,7 +863,7 @@ static void batch_each_object(struct batch_options *opt,
>  	odb_prepare_alternates(the_repository->objects);
>  	for (source = the_repository->objects->sources; source; source = source->next) {
>  		int ret = odb_source_loose_for_each_object(source, NULL, batch_one_object_oi,
> -							   &payload, flags);
> +							   &payload, &opts);
>  		if (ret)
>  			break;
>  	}
> @@ -884,7 +887,7 @@ static void batch_each_object(struct batch_options *opt,
>  		for (source = the_repository->objects->sources; source; source = source->next) {
>  			struct odb_source_files *files = odb_source_files_downcast(source);
>  			int ret = packfile_store_for_each_object(files->packed, &oi,
> -								 batch_one_object_oi, &payload, flags);
> +								 batch_one_object_oi, &payload, &opts);
>  			if (ret)
>  				break;
>  		}
> diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
> index cd013c0b68..3bb57ff183 100644
> --- a/builtin/pack-objects.c
> +++ b/builtin/pack-objects.c
> @@ -4344,6 +4344,12 @@ static void add_objects_in_unpacked_packs(void)
>  {
>  	struct odb_source *source;
>  	time_t mtime;
> +	struct odb_for_each_object_options opts = {
> +		.flags = ODB_FOR_EACH_OBJECT_PACK_ORDER |
> +			 ODB_FOR_EACH_OBJECT_LOCAL_ONLY |
> +			 ODB_FOR_EACH_OBJECT_SKIP_IN_CORE_KEPT_PACKS |
> +			 ODB_FOR_EACH_OBJECT_SKIP_ON_DISK_KEPT_PACKS,
> +	};
>  	struct object_info oi = {
>  		.mtimep = &mtime,
>  	};
> @@ -4356,11 +4362,7 @@ static void add_objects_in_unpacked_packs(void)
>  			continue;
>
>  		if (packfile_store_for_each_object(files->packed, &oi,
> -						   add_object_in_unpacked_pack, NULL,
> -						   ODB_FOR_EACH_OBJECT_PACK_ORDER |
> -						   ODB_FOR_EACH_OBJECT_LOCAL_ONLY |
> -						   ODB_FOR_EACH_OBJECT_SKIP_IN_CORE_KEPT_PACKS |
> -						   ODB_FOR_EACH_OBJECT_SKIP_ON_DISK_KEPT_PACKS))
> +						   add_object_in_unpacked_pack, NULL, &opts))
Plus this is so much easier to read now.
[snip]
The rest looked good.
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 14 of 52 in “odb: generic object name handling”
  1. 00/14 odb: generic object name handlingPatrick Steinhardt, Mar 19, 2026
  2. 01/14 oidtree: modernize the code a bitPatrick Steinhardt, Mar 19, 2026
  3. Junio C HamanoMar 19, 2026
  4. Patrick SteinhardtMar 20, 2026
  5. brian m. carlsonMar 20, 2026
  6. Patrick SteinhardtMar 23, 2026
  7. 02/14 oidtree: extend iteration to allow for arbitrary return codesPatrick Steinhardt, Mar 19, 2026
  8. Junio C HamanoMar 19, 2026
  9. Patrick SteinhardtMar 20, 2026
  10. Karthik NayakMar 19, 2026
  11. 03/14 odb: introduce `struct odb_for_each_object_options`Patrick Steinhardt, Mar 19, 2026
  12. Junio C HamanoMar 19, 2026
  13. Patrick SteinhardtMar 19, 2026
  14. Karthik NayakMar 20, 2026
  15. 04/14 object-name: move logic to iterate through loose prefixed objectsPatrick Steinhardt, Mar 19, 2026
  16. 05/14 object-name: move logic to iterate through packed prefixed objectsPatrick Steinhardt, Mar 19, 2026
  17. 06/14 object-name: extract function to parse object ID prefixesPatrick Steinhardt, Mar 19, 2026
  18. 07/14 object-name: backend-generic `repo_collect_ambiguous()`Patrick Steinhardt, Mar 19, 2026
  19. Junio C HamanoMar 19, 2026
  20. Patrick SteinhardtMar 19, 2026
  21. Karthik NayakMar 20, 2026
  22. 08/14 object-name: backend-generic `get_short_oid()`Patrick Steinhardt, Mar 19, 2026
  23. 09/14 object-name: merge `update_candidates()` and `match_prefix()`Patrick Steinhardt, Mar 19, 2026
  24. 10/14 object-name: abbreviate loose object names without `disambiguate_state`Patrick Steinhardt, Mar 19, 2026
  25. 11/14 object-name: simplify computing common prefixesPatrick Steinhardt, Mar 19, 2026
  26. Karthik NayakMar 20, 2026
  27. Patrick SteinhardtMar 20, 2026
  28. 12/14 object-name: move logic to compute loose abbreviation lengthPatrick Steinhardt, Mar 19, 2026
  29. 13/14 object-file: move logic to compute packed abbreviation lengthPatrick Steinhardt, Mar 19, 2026
  30. 14/14 odb: introduce generic `odb_find_abbrev_len()`Patrick Steinhardt, Mar 19, 2026
  31. 00/14 odb: generic object name handlingPatrick Steinhardt, Mar 20, 2026
  32. 01/14 oidtree: modernize the code a bitPatrick Steinhardt, Mar 20, 2026
  33. 02/14 oidtree: extend iteration to allow for arbitrary return codesPatrick Steinhardt, Mar 20, 2026
  34. 03/14 odb: introduce `struct odb_for_each_object_options`Patrick Steinhardt, Mar 20, 2026
  35. 04/14 object-name: move logic to iterate through loose prefixed objectsPatrick Steinhardt, Mar 20, 2026
  36. 05/14 object-name: move logic to iterate through packed prefixed objectsPatrick Steinhardt, Mar 20, 2026
  37. Toon ClaesMar 30, 2026
  38. 06/14 object-name: extract function to parse object ID prefixesPatrick Steinhardt, Mar 20, 2026
  39. 07/14 object-name: backend-generic `repo_collect_ambiguous()`Patrick Steinhardt, Mar 20, 2026
  40. 08/14 object-name: backend-generic `get_short_oid()`Patrick Steinhardt, Mar 20, 2026
  41. Toon ClaesMar 30, 2026
  42. 09/14 object-name: merge `update_candidates()` and `match_prefix()`Patrick Steinhardt, Mar 20, 2026
  43. 10/14 object-name: abbreviate loose object names without `disambiguate_state`Patrick Steinhardt, Mar 20, 2026
  44. 11/14 object-name: simplify computing common prefixesPatrick Steinhardt, Mar 20, 2026
  45. 12/14 object-name: move logic to compute loose abbreviation lengthPatrick Steinhardt, Mar 20, 2026
  46. 13/14 object-file: move logic to compute packed abbreviation lengthPatrick Steinhardt, Mar 20, 2026
  47. 14/14 odb: introduce generic `odb_find_abbrev_len()`Patrick Steinhardt, Mar 20, 2026
  48. Karthik NayakMar 20, 2026
  49. Patrick SteinhardtMar 20, 2026
  50. Toon ClaesMar 30, 2026
  51. Junio C HamanoMar 30, 2026
  52. Patrick SteinhardtMar 31, 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.