From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.214.169 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796242156; b=cCuKI54nciUJTgPX+JNxSVcnovZdXOlvcF7+MnfJgCkniWXRNIoFxlGJhFlzUO6VqP6m L9NZ5/fqQHou37Er8xIpdf0yP60Y9FTEEg5widbvfcWSJrg02lYqhU7Np/KJ+dlHknhJ3 WMAjkXvlXlY5bVMkialnUBe45yvZTaoseAH3qVEh6u4j5rMrWMvQ/ZXohpKWy0ctxoETo r6kFvH3tYJy2tKCZjHc1xb9dMoHfFVfCmz4dMjqRnA+6D9xDkXrLiwK8yl4P0eaFPE2Xa BwXYHUDWPgplwhidMlK5xQLL4o31+arsrE9XWdRUql1DGxFRCc9+kbTMjCyELggUSnA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796242156; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=+9y929NMX8M3989LpXcpLzNYqH5FQoBNobsmy5z8viM=; b=z50xYwRcoy1dFMetATiocOh0qL2swhsCDZdo6T2HMnyCwI1lU/6wngw7PnVXQtp8TPQv YUkBjmOH7r0W5hqUJD1MOta97HrzUyYvY3yypX/WOFUe6VkdOUshlMfJTXxUWdj3EjCg0 H/93huZEM/oRuNUGG3mCtj58dUE1EKWNWU1y5bUpyIF3npuckfQbv9j+8ldqaM/Im/oyE nf92BHKkktlmMxK3gQcoidRk+eQP76V8HpXGK/iBya9vfXL+mhQZINMl1zlU/7Rvbc+NN QcNjv3/6JCAv12GUisQr53BDaJcNEkS9k+E/eocfKl/iux6H5ZPpLobir7gRn6oBDaA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=umjcId6v; arc=none smtp.remote-ip=209.85.214.169 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3007E606A322 for ; Wed, 2 Dec 2026 20:09:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 3007E606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=umjcId6v Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-2f02b9c1f6fso1621095ad.0 for ; Wed, 02 Dec 2026 12:09:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796242155; x=1796846955; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=+9y929NMX8M3989LpXcpLzNYqH5FQoBNobsmy5z8viM=; b=umjcId6v4clOltCWGfgzhofcaKaXdXmgEtTzHbi1jNEdhLDqqkf/B5vjdx1CAEFPfR IP0mqHZjIit7iFoMPKOY3wSKUzCcFDP9rS17026f+CmTlWhlw/GjpEqIDkcybSBn/QnF Hwcqg32RxJFFkDhYiU2MsHxX31hZMvFrkhxTFTARQZf0I2M9Oha1coz7lY561h0kitDP dyoD6pP1tTXmjDnxHffii8yu+NU08/d+I6Jsg+y8D2l6W8gtuwSSVajeh/FOb8s51MBH HUWvwpxxR9a9KahH02L+O+Hokxx24RsSGbl+dmIit/AlNVgSAYg3UtCn+dMfV7BhwcMm /Cog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796242155; x=1796846955; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=+9y929NMX8M3989LpXcpLzNYqH5FQoBNobsmy5z8viM=; b=rnQk38aCJi6mPPt6As3eLCA3l5QYd0W74MXCLaMqXGCYnZU3TXdpeDlLAIw50kNydc /tbX/yNViOeBqqx34M0IEs6m278j/oRwd52hkRvsUxmf9qRZL3SIGXgcYnkvq81kUsMD GHS3ujfJIdvjbpmI23NoR3KX1R3EO7Y6qbKt6OWxY3PkKD/lFEIHHsCHAT2K/+elVJuj e4bAPpMprlo5Bz4pftARvN/UJE5pDZb1f0sMe9jv/ci5MwMK4rD9cWIxvitEzssui8Rp C90UdLOFc2zg5z5tp2eXScedWPsxrk3pU+/mC4D7QFTDadZIgNGhwKIYSRMFYgPyfbCn m/PA== X-Gm-Message-State: APuU4Z8elxxsz9erX/Ow4pGWxm7evXXcD6+gd5eQTCdyC+QmvWXsrM0T 8bkwSCwkcEts3KDwZqe1soeBQevjoPwYxrY2iLvpcGXdOiii+2nf6hbXrBLrG63h X-Gm-Gg: AZFdTZco6HmjOHoAssnyvqzY12MPLFHhZsj1eQd8QsSw2ELjr0NjfDHBvzGpH/kWJk0 tHznm8unrv0nvmfGfteiFIY/mV6wrHLkH0RO4bwU08UVrcc3zPM1IlCTYyrYbP8DZn8+yMsDJRl rJCxXv5wkVYheR3FqcbQsSPg1ZY5E3io1QnPSdB3srjy8IWXcG9gXHsTaJGFL0qxDiDPr2qoQCy s5dMT81palS1N90xAGLFRDRXD0RNKLvcm/bUDFHLQs2VcUm38we6LbjAUMqUPHHMPKkHQZTZSMw Kh2O+27S3zA9JoLXEOIoibhg544mKvpxGHbJuy+N6M3xsfMJRxDGXsajh2UpSMCPi3yyPRwmVst g2by4eRSNE6zZWidM87MqAcfJe2ahOsfQdLCNhO4mDAwnCo8spsNa8wz2i6omdJK8jkLL6J+TQE rTZifJ0OTHShffROrJoEq4E07HaHgEdbLnhM+yjXHB39l7MOQZcYieMjwIAuSAq3id8UPCwxNHf 2PjQW6nCC7IsnqiNpozDfdN3pX2qrtpgYxXCys+rsyOFfvQZVR/aUvpls0t7YT3zRzYBCREJcll x5vhIDqshGo0US1JsvlSgxd5W87UBK3rogpKryF1IrmyxJcTVg6nrnsQ/hmxqyvZmEMTvoSbibh +9aY22O+dYEAQ5OwB67u6TCx2ilMFYQTwwnAox5FGGu4= X-Received: by 2002:a17:902:dad0:b0:2ea:1e40:624 with SMTP id d9443c01a7336-2f03f1b80f8mr335928405ad.17.1796242155159; Wed, 02 Dec 2026 12:09:15 -0800 (PST) Received: from localhost.localdomain ([223.190.80.135]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2f03f14fc8csm204111975ad.74.2026.12.02.12.09.12 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 02 Dec 2026 12:09:14 -0800 (PST) From: Aniket Gupta To: git@vger.kernel.org Cc: Junio C Hamano , Laveesh Bansal , Patrick Steinhardt Subject: [GSoC PATCH v4] fsck: report the number of objects in the connectivity message Date: Thu, 3 Dec 2026 01:39:09 +0530 Message-ID: <20261202200909.38901-1-aniketgupta3001@gmail.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20261130123613.75255-1-aniketgupta3001@gmail.com> References: <20261020102134.42151-1-aniketgupta3001@gmail.com> <20261129100214.46634-1-aniketgupta3001@gmail.com> <20261130123613.75255-1-aniketgupta3001@gmail.com> X-Mailing-List: git@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Laveesh Bansal --- 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)