{"thread":{"id":"66602","subject":"[GSoC PATCH] fsck: report the real object count in the connectivity message","startedAt":"2026-10-20T10:21:34Z","lastAt":"2026-11-12T13:07:49Z","messageCount":3,"participants":["Aniket Gupta","Laveesh Bansal"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"555522","messageId":"20261020102134.42151-1-aniketgupta3001@gmail.com","threadId":"66602","inReplyTo":null,"subject":"[GSoC PATCH] fsck: report the real object count in the connectivity message","fromName":"Aniket Gupta","fromEmail":"aniketgupta3001@gmail.com","sentAt":"2026-10-20T10:21:34Z","receivedAt":"2026-10-20T10:21:34Z","isPatch":true,"sender":{"key":"aniketgupta3001@gmail.com","avatar":null},"body":"The verbose \"Checking connectivity\" message prints the value of\nget_max_object_index(), which is number of buckets in the object hash\nand not the number of objects in it. The hash is larger than what it\nholds so a repository with 21 objects says 64 objects.\n\nAdd get_object_count() to return the number of objects in the hash and\nuse it for the message. The loop below will still walk every bucket and\nit keeps using get_max_object_index().\n\nSigned-off-by: Aniket Gupta <aniketgupta3001@gmail.com>\n---\nThis goes on top of \"fsck: use Q_() for the verbose connectivity\nmessage\" which Junio had queued. He mentioned that the number was not\nthe real count and this is the separate fix for that.\n\nindex-pack also uses get_max_object_index() as the total for its\n\"Checking objects\" progress. That is unchanged since it walks the same\nbuckets.\n\n builtin/fsck.c  | 13 ++++++++-----\n object.c        |  5 +++++\n object.h        |  7 +++++++\n t/t1450-fsck.sh | 15 +++++++++++++++\n 4 files changed, 35 insertions(+), 5 deletions(-)\n\ndiff --git a/builtin/fsck.c b/builtin/fsck.c\nindex 710780e35..da51b2a91 100644\n--- a/builtin/fsck.c\n+++ b/builtin/fsck.c\n@@ -378,11 +378,14 @@ static void check_connectivity(struct repository *repo)\n \n \t/* Look up all the requirements, warn about missing objects.. */\n \tmax = get_max_object_index(repo);\n-\tif (verbose)\n-\t\tfprintf_ln(stderr, Q_(\"Checking connectivity (%d object)\",\n-\t\t\t\t      \"Checking connectivity (%d objects)\",\n-\t\t\t\t      max),\n-\t\t\t   max);\n+\tif (verbose) {\n+\t\tunsigned int nr = get_object_count(repo);\n+\n+\t\tfprintf_ln(stderr, Q_(\"Checking connectivity (%u object)\",\n+\t\t\t\t      \"Checking connectivity (%u objects)\",\n+\t\t\t\t      nr),\n+\t\t\t   nr);\n+\t}\n \n \tfor (i = 0; i < max; i++) {\n \t\tstruct object *obj = get_indexed_object(repo, i);\ndiff --git a/object.c b/object.c\nindex 97f7fc0e8..2fdba93d4 100644\n--- a/object.c\n+++ b/object.c\n@@ -20,6 +20,11 @@ unsigned int get_max_object_index(const struct repository *repo)\n \treturn repo->parsed_objects->obj_hash_size;\n }\n \n+unsigned int get_object_count(const struct repository *repo)\n+{\n+\treturn repo->parsed_objects->nr_objs;\n+}\n+\n struct object *get_indexed_object(const struct repository *repo,\n \t\t\t\t       unsigned int idx)\n {\ndiff --git a/object.h b/object.h\nindex 46cade33f..20ea6f5c0 100644\n--- a/object.h\n+++ b/object.h\n@@ -173,6 +173,13 @@ int type_from_string_gently(const char *str, ssize_t, int gentle);\n  */\n unsigned int get_max_object_index(const struct repository *repo);\n \n+/*\n+ * Return the number of objects currently in the object hashmap. This\n+ * is smaller than the value get_max_object_index() returns, as that\n+ * counts the buckets, which are not all in use.\n+ */\n+unsigned int get_object_count(const struct repository *repo);\n+\n /*\n  * Return the object from the specified bucket in the object hashmap.\n  */\ndiff --git a/t/t1450-fsck.sh b/t/t1450-fsck.sh\nindex 1b4074304..ceb7c649c 100755\n--- a/t/t1450-fsck.sh\n+++ b/t/t1450-fsck.sh\n@@ -1152,4 +1152,19 @@ test_expect_success 'fsck reports problems in current worktree index without fil\n \ttest_cmp expect actual\n '\n \n+test_expect_success 'fsck --verbose reports the number of objects' '\n+\tgit init count &&\n+\ttest_commit -C count one &&\n+\tgit -C count fsck --verbose 2>err &&\n+\ttest_grep \"Checking connectivity (3 objects)\" err\n+'\n+\n+test_expect_success 'fsck --verbose uses the singular for a single object' '\n+\tgit init single &&\n+\tblob=$(echo single | git -C single hash-object -w --stdin) &&\n+\tgit -C single update-ref refs/tags/blob $blob &&\n+\tgit -C single fsck --verbose 2>err &&\n+\ttest_grep \"Checking connectivity (1 object)\" err\n+'\n+\n test_done\n-- \n2.43.0\n\n\n"},{"id":"558274","messageId":"20261112025559.83265-1-laveeshb@laveeshbansal.com","threadId":"66602","inReplyTo":"20261020102134.42151-1-aniketgupta3001@gmail.com","subject":"Re: [GSoC PATCH] fsck: report the real object count in the connectivity message","fromName":"Laveesh Bansal","fromEmail":"laveeshb@laveeshbansal.com","sentAt":"2026-11-12T02:55:59Z","receivedAt":"2026-11-12T02:55:59Z","isPatch":true,"sender":{"key":"laveeshb@laveeshbansal.com","avatar":null},"body":"Thanks for the patch. Looks good to me. I ran t1450 with and without\nthe patch: the new tests pass with it and fail without.\n\nOne thing about the title:\n\n> fsck: report the real object count in the connectivity message\n\nIn a partial clone the number counts blobs that were never downloaded.\nSetup:\n\n    git init -q -b main src\n    git -C src config uploadpack.allowFilter true\n    for i in 1 2 3\n    do\n    \techo $i >src/f$i\n    \tgit -C src add f$i\n    \tgit -C src commit -qm c$i\n    done\n    git clone -q --no-checkout --filter=blob:none file://$PWD/src pc\n\nThen:\n\n    $ git -C pc fsck --verbose 2>&1 | grep connectivity\n    Checking connectivity (9 objects)\n    $ git -C pc cat-file --batch-all-objects --batch-check | wc -l\n    warning: This repository uses promisor remotes. Some objects may not be loaded.\n    6\n\nWould \"report the number of objects checked\" fit the title better?\n\n"},{"id":"558290","messageId":"20261112130749.51747-1-aniketgupta3001@gmail.com","threadId":"66602","inReplyTo":"20261112025559.83265-1-laveeshb@laveeshbansal.com","subject":"Re: [GSoC PATCH] fsck: report the real object count in the connectivity message","fromName":"Aniket Gupta","fromEmail":"aniketgupta3001@gmail.com","sentAt":"2026-11-12T13:07:49Z","receivedAt":"2026-11-12T13:07:49Z","isPatch":true,"sender":{"key":"aniketgupta3001@gmail.com","avatar":null},"body":"Thanks for the review.\n\n> In a partial clone the number counts blobs that were never downloaded.\n\nI can repro this. With your setup I get 9 from fsck and 6 from\ncat-file. The three missing blobs are counted because the trees refer\nto them.\n\n> Would \"report the number of objects checked\" fit the title better?\n\nYeah I agree that \"Real\" might be too strong. I think \"checked\" might\nalso not fit because the missing blobs are counted but not checked.\nMaybe we can use something like \"report the number of objects in the\nconnectivity message\".\n\nI can send a v2 with a new title if Junio wants one.\n\n"}]}