threads / patch / 66602

patchfsck: report the real object count in the connectivity message

Subject: [GSoC PATCH] fsck: report the real object count in the connectivity message

## tl;dr

3 messages between Oct 20, 2026 and Nov 12, 2026. Diffs are folded; open one to read it.

replies: 2people: 2as markdown or json

Aniket Gupta· Oct 20, 2026, 10:21 UTC · lore

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.

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>
---
This goes on top of "fsck: use Q_() for the verbose connectivity
message" which Junio had queued. He mentioned that the number was not
the real count and this is the separate fix for that.

index-pack also uses get_max_object_index() as the total for its "Checking objects" progress. That is unchanged since it walks the same buckets.

 builtin/fsck.c  | 13 ++++++++-----
 object.c        |  5 +++++
 object.h        |  7 +++++++
 t/t1450-fsck.sh | 15 +++++++++++++++
 4 files changed, 35 insertions(+), 5 deletions(-)
Show changes to 4 files +35 −5

builtin/fsck.c, object.c, object.h, t/t1450-fsck.sh

diff --git a/builtin/fsck.c b/builtin/fsck.c
index 710780e35..da51b2a91 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -378,11 +378,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);
+	}
 
 	for (i = 0; i < max; i++) {
 		struct object *obj = get_indexed_object(repo, i);
diff --git a/object.c b/object.c
index 97f7fc0e8..2fdba93d4 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;
+}
+
 struct object *get_indexed_object(const struct repository *repo,
 				       unsigned int idx)
 {
diff --git a/object.h b/object.h
index 46cade33f..20ea6f5c0 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);
+
 /*
  * Return the object from the specified bucket in the object hashmap.
  */
diff --git a/t/t1450-fsck.sh b/t/t1450-fsck.sh
index 1b4074304..ceb7c649c 100755
--- a/t/t1450-fsck.sh
+++ b/t/t1450-fsck.sh
@@ -1152,4 +1152,19 @@ test_expect_success 'fsck reports problems in current worktree index without fil
 	test_cmp expect actual
 '
 
+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
+'
+
 test_done
-- 
2.43.0
Laveesh Bansal· Nov 12, 2026, 02:55 UTC · re: Aniket Gupta · lore

Re: [GSoC PATCH] fsck: report the real object count in the connectivity message

Thanks for the patch. Looks good to me. I ran t1450 with and without the patch: the new tests pass with it and fail without.

One thing about the title:
> fsck: report the real object count in the connectivity message

In a partial clone the number counts blobs that were never downloaded. Setup:

    git init -q -b main src
    git -C src config uploadpack.allowFilter true
    for i in 1 2 3
    do
    	echo $i >src/f$i
    	git -C src add f$i
    	git -C src commit -qm c$i
    done
    git clone -q --no-checkout --filter=blob:none file://$PWD/src pc
Then:
    $ git -C pc fsck --verbose 2>&1 | grep connectivity
    Checking connectivity (9 objects)
    $ git -C pc cat-file --batch-all-objects --batch-check | wc -l
    warning: This repository uses promisor remotes. Some objects may not be loaded.
    6
Would "report the number of objects checked" fit the title better?
Aniket Gupta· Nov 12, 2026, 13:07 UTC · re: Laveesh Bansal · lore

Re: [GSoC PATCH] fsck: report the real object count in the connectivity message

Thanks for the review.
> In a partial clone the number counts blobs that were never downloaded.

I can repro this. With your setup I get 9 from fsck and 6 from cat-file. The three missing blobs are counted because the trees refer to them.

> Would "report the number of objects checked" fit the title better?

Yeah I agree that "Real" might be too strong. I think "checked" might also not fit because the missing blobs are counted but not checked. Maybe we can use something like "report the number of objects in the connectivity message".

I can send a v2 with a new title if Junio wants one.

← back to recent threads