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

Re: [GSoC PATCH v2] fsck: report the number of objects in the connectivity message

From
Junio C Hamano <gitster@pobox.com>
Date
Nov 29, 2026, 19:10 UTC
Message-ID
<xmqqbj77h2sl.fsf@gitster.g>
In-Reply-To
<20261129100214.46634-1-aniketgupta3001@gmail.com>
Aniket Gupta <aniketgupta3001@gmail.com> writes:
> The verbose "Checking connectivity" message prints the value of
> get_max_object_index(), which is number of buckets in the object hash
> and not the number of objects in it. The hash is larger than what it
> holds so a repository with 21 objects says 64 objects.
Micronits.
 - "which is the number of buckets" is missing "the".
 - What holds the objects is not a "hash" but a "hashtable".
 - In an empty repository, we have no hash buckets, so the capacity
   of the hashtable exactly matches the number of objects in that
   case.  "In a non-empty repository, the hashtable is larger than
   what it holds" would be more accurate.

For any non-empty table, grow_object_hash() allocates at least 32 buckets and doubles when '.obj_hash_size' - 1 <= '.nr_objs' * 2, so 21 objects indeed sit in 64 buckets.

Show 12 quoted lines
> Add get_object_count() to return the number of objects in the hash and
> use it for the message. The loop below will still walk every bucket and
> it keeps using get_max_object_index().
>
> Signed-off-by: Aniket Gupta <aniketgupta3001@gmail.com>
> Reviewed-by: Laveesh Bansal <laveeshb@laveeshbansal.com>
> ---
> Changes in v2:
>
>  - Retitle as Laveesh suggested. In a partial clone the count also
>    includes the blobs that the trees refer to, so "number of objects"
>    fits better.
Good.
>  - Add Laveesh's Reviewed-by.
Good.
>  - Rebase onto current master.

A report on rebasing is incomplete without an explanation of the reason why you had to rebase (what you wanted to achieve by rebasing). There certainly would have been changes on the 'master' front since the version you based your previous round on. But were there ones among these changes that you specifically wanted to take advantage of, or that caused conflicts that you wanted to resolve on your end (instead of having the maintainer do it for you)?

Another small change not mentioned in the proposed log message is to report the number of objects using "%u".

Show 27 quoted lines
>  builtin/fsck.c  | 13 ++++++++-----
>  object.c        |  5 +++++
>  object.h        |  7 +++++++
>  t/t1450-fsck.sh | 15 +++++++++++++++
>  4 files changed, 35 insertions(+), 5 deletions(-)
>
> diff --git a/builtin/fsck.c b/builtin/fsck.c
> index c4558efcf1..3aca0736d4 100644
> --- a/builtin/fsck.c
> +++ b/builtin/fsck.c
> @@ -377,11 +377,14 @@ static void check_connectivity(struct repository *repo)
>  
>  	/* Look up all the requirements, warn about missing objects.. */
>  	max = get_max_object_index(repo);
> -	if (verbose)
> -		fprintf_ln(stderr, Q_("Checking connectivity (%d object)",
> -				      "Checking connectivity (%d objects)",
> -				      max),
> -			   max);
> +	if (verbose) {
> +		unsigned int nr = get_object_count(repo);
> +
> +		fprintf_ln(stderr, Q_("Checking connectivity (%u object)",
> +				      "Checking connectivity (%u objects)",
> +				      nr),
> +			   nr);
> +	}

By the time check_connectivity() reaches this point, cmd_fsck() has populated '.obj_hash' from its sources, and traverse_reachable() has already walked reachable trees and commits (which inserts referenced objects, including missing or promisor blobs, via lookup_tree() and lookup_blob()).

Neither check_reachable_object() nor check_unreachable_object() in the loop inserts new entries into '.obj_hash', so get_object_count() matches the exact number of non-NULL objects visited by the loop. Using "%u" matches the return type of get_object_count() that is unsigned.

Show 14 quoted lines
>  	for (i = 0; i < max; i++) {
>  		struct object *obj = get_indexed_object(repo, i);
> diff --git a/object.c b/object.c
> index 97f7fc0e87..2fdba93d4c 100644
> --- a/object.c
> +++ b/object.c
> @@ -20,6 +20,11 @@ unsigned int get_max_object_index(const struct repository *repo)
>  	return repo->parsed_objects->obj_hash_size;
>  }
>  
> +unsigned int get_object_count(const struct repository *repo)
> +{
> +	return repo->parsed_objects->nr_objs;
> +}

Tracking '.nr_objs' directly is clean. parsed_object_pool_new() zero-initializes the pool, create_object() increments '.nr_objs' on every insertion into '.obj_hash', and nothing decrements or removes entries before parsed_object_pool_clear() tears the pool down.

All other callers of get_max_object_index() walk the bucket array with get_indexed_object(). builtin/index-pack.c:check_objects() passes the bucket count to start_delayed_progress() because its loop calls display_progress() with the bucket index, so leaving those callers untouched makes sense.

The code is prepared to have up to 2 billion objects in an object pool on 32-bit machines, as the type of the .nr_objs member in the parsed_object_pool struct is 'int' (it is a bit surprising that it is not even "unsigned int"). Something to think about later after the dust settles (#leftoverbits).

Show 17 quoted lines
>  struct object *get_indexed_object(const struct repository *repo,
>  				       unsigned int idx)
>  {
> diff --git a/object.h b/object.h
> index 46cade33fb..20ea6f5c0c 100644
> --- a/object.h
> +++ b/object.h
> @@ -173,6 +173,13 @@ int type_from_string_gently(const char *str, ssize_t, int gentle);
>   */
>  unsigned int get_max_object_index(const struct repository *repo);
>  
> +/*
> + * Return the number of objects currently in the object hashmap. This
> + * is smaller than the value get_max_object_index() returns, as that
> + * counts the buckets, which are not all in use.
> + */
> +unsigned int get_object_count(const struct repository *repo);

Minor nit. "This is smaller than the value get_max_object_index() returns when the object hashmap is not empty, as that counts ...".

Show 26 quoted lines
> +
>  /*
>   * Return the object from the specified bucket in the object hashmap.
>   */
> diff --git a/t/t1450-fsck.sh b/t/t1450-fsck.sh
> index 3e9eb251cb..c871ad8edf 100755
> --- a/t/t1450-fsck.sh
> +++ b/t/t1450-fsck.sh
> @@ -1165,4 +1165,19 @@ test_expect_success 'fsck with blob size equal to core.bigFileThreshold' '
>  	)
>  '
>  
> +test_expect_success 'fsck --verbose reports the number of objects' '
> +	git init count &&
> +	test_commit -C count one &&
> +	git -C count fsck --verbose 2>err &&
> +	test_grep "Checking connectivity (3 objects)" err
> +'
> +
> +test_expect_success 'fsck --verbose uses the singular for a single object' '
> +	git init single &&
> +	blob=$(echo single | git -C single hash-object -w --stdin) &&
> +	git -C single update-ref refs/tags/blob $blob &&
> +	git -C single fsck --verbose 2>err &&
> +	test_grep "Checking connectivity (1 object)" err
> +'
Both tests cover the expected counts cleanly.
 - test_commit defaults to a lightweight tag, producing 1 blob, 1
   tree, and 1 commit (3 objects).
 - You can have only commits under refs/heads/, so you create a blob
   and point at it with refs/tags/blob, which would exercise a
   singular form.  I wonder if you can just 'git add' a regular file
   in a freshly created repository without committing to get the
   same effect?  'git fsck' would consider the index as a
   connectivity anchor, so it will traverse to the blob object,
   without a tag to the blob, which is a bit of an unusual thing to
   have these days.

Optional cleanup with test_when_finished "rm -rf ..." would match the test right above, though other tests in this file omit it too, so we should be OK.

Previous: Aniket GuptaNext: Aniket Gupta
Message 7 of 13 in “fsck: report the real object count in the connectivity message”
  1. fsck: report the real object count in the connectivity messageAniket Gupta, Oct 20, 2026
  2. Laveesh BansalNov 12, 2026
  3. Aniket GuptaNov 12, 2026
  4. Laveesh BansalNov 23, 2026
  5. Aniket GuptaNov 23, 2026
  6. fsck: report the number of objects in the connectivity messageAniket Gupta, Nov 29, 2026
  7. Junio C HamanoNov 29, 2026
  8. Aniket GuptaNov 29, 2026
  9. fsck: report the number of objects in the connectivity messageAniket Gupta, Nov 30, 2026
  10. Patrick SteinhardtDec 1, 2026
  11. Aniket GuptaDec 1, 2026
  12. fsck: report the number of objects in the connectivity messageAniket Gupta, Dec 2, 2026
  13. Patrick SteinhardtDec 3, 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.