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

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

From
AGAniket Gupta <aniketgupta3001@gmail.com>
Date
Nov 30, 2026, 12:36 UTC
Message-ID
<20261130123613.75255-1-aniketgupta3001@gmail.com>
In-Reply-To
<20261129100214.46634-1-aniketgupta3001@gmail.com>

The verbose "Checking connectivity" message prints the value of get_max_object_index(), which is the number of buckets in the object hashtable and not the number of objects in it. In a non-empty repository the hashtable 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 hashtable and use it for the message, printed with "%u" as the count is unsigned. 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 v3:
 - Reword the log message: "the number of buckets", "hashtable"
   instead of "hash", and the hashtable is larger than what it holds
   only in a non-empty repository (Junio).
 - Mention in the log message that the count is printed with "%u"
   (Junio).
 - Say in the comment above get_object_count() that the count is
   smaller only when the hashmap is not empty (Junio).
 - In the singular test, add a file to the index instead of creating a
   blob and pointing a tag at it (Junio).
 - Clean up the repositories the two new tests create with
   test_when_finished (Junio).
 builtin/fsck.c  | 13 ++++++++-----
 object.c        |  5 +++++
 object.h        |  8 ++++++++
 t/t1450-fsck.sh | 17 +++++++++++++++++
 4 files changed, 38 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);
+	}
 
 	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;
+}
+
 struct object *get_indexed_object(const struct repository *repo,
 				       unsigned int idx)
 {
diff --git a/object.h b/object.h
index 46cade33fb..21e0837ed2 100644
--- a/object.h
+++ b/object.h
@@ -173,6 +173,14 @@ 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 when the
+ * object hashmap is not empty, 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 3e9eb251cb..5503bd2533 100755
--- a/t/t1450-fsck.sh
+++ b/t/t1450-fsck.sh
@@ -1165,4 +1165,21 @@ test_expect_success 'fsck with blob size equal to core.bigFileThreshold' '
 	)
 '
 
+test_expect_success 'fsck --verbose reports the number of objects' '
+	test_when_finished rm -rf count &&
+	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' '
+	test_when_finished rm -rf single &&
+	git init single &&
+	echo single >single/file &&
+	git -C single add file &&
+	git -C single fsck --verbose 2>err &&
+	test_grep "Checking connectivity (1 object)" err
+'
+
 test_done

base-commit: acba8bf9753134d9bde89f94369f775838a8c5fe
-- 
2.54.0 (Apple Git-157)
Previous: Aniket GuptaNext: Patrick Steinhardt
Message 9 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.