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

Re: [PATCH v2 3/8] pack-bitmap: allow aborting iteration of bitmapped objects

From
Taylor Blau <ttaylorr@openai.com>
Date
Jul 10, 2026, 22:34 UTC
Message-ID
<alFzja98avOoKjQE@com-79390>
In-Reply-To
<20260710-pks-odb-for-each-object-filter-v2-3-3710a9cc165a@pks.im>
On Fri, Jul 10, 2026 at 10:48:55AM +0200, Patrick Steinhardt wrote:
Show 11 quoted lines
> In a subsequent commit we'll lift iteration of bitmapped objects into
> the "packed" backend and make it accessible via `odb_for_each_object()`.
> The calling convention for that function is that the callback may return
> a non-zero exit code, and if so we'll abort iteration. This is currently
> impossible to realize though, as `for_each_bitmapped_object()` will
> ignore any return value and just churn through all objects completely.
>
> This doesn't matter to the callers of `for_each_bitmapped_object()`, as
> there's only one of them in git-cat-file(1), and the callbacks we pass
> always return zero. But once we move the logic into the generic
> infrastructure it becomes a latent bug waiting to happen.
Makes sense.
Show 11 quoted lines
> diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
> index ea5eab4cf8..8ff92c5272 100644
> --- a/builtin/pack-objects.c
> +++ b/builtin/pack-objects.c
> @@ -1909,7 +1909,7 @@ static int add_object_entry_from_bitmap(const struct object_id *oid,
>  		return 0;
>
>  	create_object_entry(oid, type, name_hash, 0, 0, pack, offset);
> -	return 1;
> +	return 0;
>  }

I was initially rather surprised to read this diff. I suspected that this was a "we used to return non-zero to indicate success but now return zero to match the project conventions", but was stumped by the unchanged "return 0" in the context above.

But I suppose that is demonstrating the thing that you're trying to fix here, which is that the caller doesn't actually care what is returned from the callback, so the change here (and analogous ones below) make sense to me.

Show 10 quoted lines
> -static void show_objects_for_type(
> +static int show_objects_for_type(
>  	struct bitmap_index *bitmap_git,
>  	struct bitmap *objects,
>  	enum object_type object_type,
> @@ -1704,6 +1704,7 @@ static void show_objects_for_type(
>  {
>  	size_t i = 0;
>  	uint32_t offset;
> +	int ret;

This has a broader scope than is strictly necessary, but I think that is OK.

Show 32 quoted lines
>  static int in_bitmapped_pack(struct bitmap_index *bitmap_git,
> @@ -2062,6 +2069,12 @@ int for_each_bitmapped_object(struct bitmap_index *bitmap_git,
>  			      show_reachable_fn show_reach,
>  			      void *payload)
>  {
> +	const enum object_type types[] = {
> +		OBJ_COMMIT,
> +		OBJ_TREE,
> +		OBJ_BLOB,
> +		OBJ_TAG,
> +	};
>  	struct bitmap *filtered_bitmap = NULL;
>  	uint32_t objects_nr;
>  	size_t full_word_count;
> @@ -2086,14 +2099,12 @@ int for_each_bitmapped_object(struct bitmap_index *bitmap_git,
>  		goto out;
>  	}
>
> -	show_objects_for_type(bitmap_git, filtered_bitmap,
> -			      OBJ_COMMIT, show_reach, payload);
> -	show_objects_for_type(bitmap_git, filtered_bitmap,
> -			      OBJ_TREE, show_reach, payload);
> -	show_objects_for_type(bitmap_git, filtered_bitmap,
> -			      OBJ_BLOB, show_reach, payload);
> -	show_objects_for_type(bitmap_git, filtered_bitmap,
> -			      OBJ_TAG, show_reach, payload);
> +	for (size_t i = 0; i < ARRAY_SIZE(types); i++) {
> +		ret = show_objects_for_type(bitmap_git, filtered_bitmap,
> +					    types[i], show_reach, payload);
> +		if (ret)
> +			goto out;
> +	}

OK. So now we call this function in a loop instead of the unrolled version, presumably because we want to propagate a failure from any one of these before falling through to the remaining object types.

That makes sense, and I think the clean-up is well justified here.

However, the remaining `show_objects_for_type()` callers from within `traverse_bitmap_commit_list()` do *not* bother to inspect the return value, despite taking in an arbitrary 'show_reachable_fn', which itself may return a non-zero value.

I guess this must be effectively OK in practice with respect to the existing code for the same reason you indicate in the commit message above, but we should change this function to *also* propagate non-zero return values to eliminate the foot-gun completely.

Thanks, Taylor

Previous: Patrick SteinhardtNext: Jeff King
Message 30 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.