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

Re: [PATCH 2/6] packfile: extract logic to count number of objects

From
Toon Claes <toon@iotcl.com>
Date
Mar 11, 2026, 12:41 UTC
Message-ID
<871phqmtcu.fsf@iotcl.com>
In-Reply-To
<20260310-b4-pks-odb-source-count-objects-v1-2-109e07d425f4@pks.im>
Patrick Steinhardt <ps@pks.im> writes:
Show 30 quoted lines
> In a subsequent commit we're about to introduce a new
> `odb_source_count_objects()` function so that we can make the logic
> pluggable. Prepare for this change by extracting the logic that we have
> to count packed objects into a standalone function.
>
> Signed-off-by: Patrick Steinhardt <ps@pks.im>
> ---
>  packfile.c | 45 +++++++++++++++++++++++++++++++++++----------
>  packfile.h |  9 +++++++++
>  2 files changed, 44 insertions(+), 10 deletions(-)
>
> diff --git a/packfile.c b/packfile.c
> index 215a23e42b..1ee5dd3da3 100644
> --- a/packfile.c
> +++ b/packfile.c
> @@ -1101,6 +1101,36 @@ struct packfile_list_entry *packfile_store_get_packs(struct packfile_store *stor
>  	return store->packs.head;
>  }
>  
> +int packfile_store_count_objects(struct packfile_store *store,
> +				 unsigned long *out)
> +{
> +	struct packfile_list_entry *e;
> +	struct multi_pack_index *m;
> +	unsigned long count = 0;
> +	int ret;
> +
> +	m = get_multi_pack_index(store->source);
> +	if (m)
> +		count += m->num_objects + m->num_objects_in_base;
To make sure I understand correctly:

`m->num_objects` indicates how many objects are in the current pack, and `m->num_objects_in_base` how many are in it's base (and that accumulates what's in the bases of the base?).

> +	for (e = packfile_store_get_packs(store); e; e = e->next) {
> +		if (e->pack->multi_pack_index)
> +			continue;

Because we added the count through the midx already, we skip any packfile that's included in the midx.

But some packfiles are not in the midx so we fall through for those.
Makes sense.
-- 
Cheers,
Toon
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 4 of 27 in “odb: introduce generic object counting”
  1. 0/6 odb: introduce generic object countingPatrick Steinhardt, Mar 10, 2026
  2. 1/6 odb: stop including "odb/source.h"Patrick Steinhardt, Mar 10, 2026
  3. 2/6 packfile: extract logic to count number of objectsPatrick Steinhardt, Mar 10, 2026
  4. Toon ClaesMar 11, 2026
  5. Patrick SteinhardtMar 11, 2026
  6. 3/6 object-file: extract logic to approximate object countPatrick Steinhardt, Mar 10, 2026
  7. Junio C HamanoMar 10, 2026
  8. Toon ClaesMar 11, 2026
  9. Patrick SteinhardtMar 11, 2026
  10. 4/6 object-file: generalize counting objectsPatrick Steinhardt, Mar 10, 2026
  11. Toon ClaesMar 11, 2026
  12. Patrick SteinhardtMar 11, 2026
  13. 5/6 odb/source: introduce generic object countingPatrick Steinhardt, Mar 10, 2026
  14. Junio C HamanoMar 10, 2026
  15. Patrick SteinhardtMar 11, 2026
  16. Toon ClaesMar 11, 2026
  17. 6/6 odb: introduce generic object countingPatrick Steinhardt, Mar 10, 2026
  18. Toon ClaesMar 11, 2026
  19. Patrick SteinhardtMar 12, 2026
  20. 0/6 odb: introduce generic object countingPatrick Steinhardt, Mar 12, 2026
  21. 1/6 odb: stop including "odb/source.h"Patrick Steinhardt, Mar 12, 2026
  22. 2/6 packfile: extract logic to count number of objectsPatrick Steinhardt, Mar 12, 2026
  23. 3/6 object-file: extract logic to approximate object countPatrick Steinhardt, Mar 12, 2026
  24. 4/6 object-file: generalize counting objectsPatrick Steinhardt, Mar 12, 2026
  25. 5/6 odb/source: introduce generic object countingPatrick Steinhardt, Mar 12, 2026
  26. 6/6 odb: introduce generic object countingPatrick Steinhardt, Mar 12, 2026
  27. Toon ClaesMar 13, 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.