Git development
 help / color / mirror / Atom feed
From: Aniket Gupta <aniketgupta3001@gmail.com>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>,
	Laveesh Bansal <laveeshb@laveeshbansal.com>,
	Patrick Steinhardt <ps@pks.im>
Subject: [GSoC PATCH v4] fsck: report the number of objects in the connectivity message
Date: Thu,  3 Dec 2026 01:39:09 +0530	[thread overview]
Message-ID: <20261202200909.38901-1-aniketgupta3001@gmail.com> (raw)
In-Reply-To: <20261130123613.75255-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_parsed_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 v4:

 - Move the assignment of max down to the loop that uses it (Patrick).
 - Rename get_object_count() to get_parsed_object_count() and mention in
   comment that objects that were only referenced are counted too
   (Patrick).

 builtin/fsck.c  | 15 +++++++++------
 object.c        |  5 +++++
 object.h        |  9 +++++++++
 t/t1450-fsck.sh | 17 +++++++++++++++++
 4 files changed, 40 insertions(+), 6 deletions(-)

diff --git a/builtin/fsck.c b/builtin/fsck.c
index c4558efcf1..b3c42cd19c 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -376,13 +376,16 @@ 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_parsed_object_count(repo);
 
+		fprintf_ln(stderr, Q_("Checking connectivity (%u object)",
+				      "Checking connectivity (%u objects)",
+				      nr),
+			   nr);
+	}
+
+	max = get_max_object_index(repo);
 	for (i = 0; i < max; i++) {
 		struct object *obj = get_indexed_object(repo, i);
 
diff --git a/object.c b/object.c
index 97f7fc0e87..6390849b48 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_parsed_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..b39a041b3e 100644
--- a/object.h
+++ b/object.h
@@ -173,6 +173,15 @@ 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
+ * includes objects that were only referenced and never parsed. It 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_parsed_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

Range-diff against v3:
1:  d61ff386fd ! 1:  e13b917429 fsck: report the number of objects in the connectivity message
    @@ Commit message
         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
    +    Add get_parsed_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().
    @@ Commit message
     
      ## builtin/fsck.c ##
     @@ builtin/fsck.c: static void check_connectivity(struct repository *repo)
    + 	}
      
      	/* Look up all the requirements, warn about missing objects.. */
    - 	max = get_max_object_index(repo);
    +-	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);
    -+
    ++		unsigned int nr = get_parsed_object_count(repo);
    + 
     +		fprintf_ln(stderr, Q_("Checking connectivity (%u object)",
     +				      "Checking connectivity (%u objects)",
     +				      nr),
     +			   nr);
     +	}
    - 
    ++
    ++	max = get_max_object_index(repo);
      	for (i = 0; i < max; i++) {
      		struct object *obj = get_indexed_object(repo, i);
    + 
     
      ## object.c ##
     @@ object.c: 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)
    ++unsigned int get_parsed_object_count(const struct repository *repo)
     +{
     +	return repo->parsed_objects->nr_objs;
     +}
    @@ object.h: int type_from_string_gently(const char *str, ssize_t, int gentle);
      
     +/*
     + * Return the number of objects currently in the object hashmap. This
    -+ * is smaller than the value get_max_object_index() returns when the
    ++ * includes objects that were only referenced and never parsed. It 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);
    ++unsigned int get_parsed_object_count(const struct repository *repo);
     +
      /*
       * Return the object from the specified bucket in the object hashmap.

base-commit: acba8bf9753134d9bde89f94369f775838a8c5fe
-- 
2.54.0 (Apple Git-157)


      parent reply	other threads:[~2026-12-02 20:09 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-20 10:21 [GSoC PATCH] fsck: report the real object count in the connectivity message Aniket Gupta
2026-11-12  2:55 ` Laveesh Bansal
2026-11-12 13:07   ` Aniket Gupta
2026-11-23 18:46     ` Laveesh Bansal
2026-11-23 22:43       ` Aniket Gupta
2026-11-29 10:02 ` [GSoC PATCH v2] fsck: report the number of objects " Aniket Gupta
2026-11-29 19:10   ` Junio C Hamano
2026-11-29 19:33     ` Aniket Gupta
2026-11-30 12:36   ` [GSoC PATCH v3] " Aniket Gupta
2026-12-01 16:06     ` Patrick Steinhardt
2026-12-01 19:27       ` Aniket Gupta
2026-12-02 20:09     ` Aniket Gupta [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261202200909.38901-1-aniketgupta3001@gmail.com \
    --to=aniketgupta3001@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=laveeshb@laveeshbansal.com \
    --cc=ps@pks.im \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox