From patchwork Wed Jun 12 08:03:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13694596 Received: from fout4-smtp.messagingengine.com (fout4-smtp.messagingengine.com [103.168.172.147]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ECB6D16DEDE for ; Wed, 12 Jun 2024 08:03:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.147 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718179409; cv=none; b=nNJi1obuWnbGmjsb31CbmLL/Ggl26AhcdF/iB8W2VHlZh0WUiZo8Ed4X4kvLARTDvyzYjPFfFV+1Ht+A4koqvTC9KsIsCvfrTkUMiDCD54+uG4HE/ZKeLQGNZQ0yEni/dujs166xFS1/BZd96278K6KxvDU9NO5Gevf62QcDRMc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718179409; c=relaxed/simple; bh=5zGctpDrL1iI4VjGKVQmkbZP4uiCd4O9sDeT1iTCHjs=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=QbUTUQ0u4BJuwBUtAshebWQJpFdk3lnbos8qoFa2reVQPQpfvc30MTv2HiEohcw0zxZZKz91yt3PU5iJ49q1brm4LCSOew5B6oU4RZj12ZpPbGy5PW4IWmgmIlh7aaQ6oUfxPLqCvG8DAK4CsrcoDOFEks7BHqGUSXvIGc/+040= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=fDOsyC5I; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=YAxZ98hV; arc=none smtp.client-ip=103.168.172.147 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="fDOsyC5I"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="YAxZ98hV" Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfout.nyi.internal (Postfix) with ESMTP id E73181380153; Wed, 12 Jun 2024 04:03:26 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Wed, 12 Jun 2024 04:03:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1718179406; x=1718265806; bh=xbhjltAIUf HnDJig1OhBBkMn/eJoo/s90NMTvY6fyBA=; b=fDOsyC5Ida0Ss/1NyZLIn/Q81k vt4oizo+s/SdBhzrN4VHGVvec0btqKq00yz/9y3fCku8nCrUp9VbdKm+qfPzp7ky ltKhCXN/Yq32D/f80ZBzuizOdGNbaR99LLF6bXoFrs1UfnQS1R1cJedVzMOFw7s8 sUijk1GVsoUwOzWFDczaKJAEI1ttU1iRcQgAqSrl2Zxo/scZ1XsT8KACabpqj94s o1zDh9+nXHM+V4AW7GMi0A2S6VENMMpbufo5pSAum6SAf+KKN0SLzYnOOovGBxj3 bKzhAmZQKdBinj28QDk09J2iai8WKW6QUzQ/wL141uF5JmqIOQBVYO3m/Nvg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1718179406; x=1718265806; bh=xbhjltAIUfHnDJig1OhBBkMn/eJo o/s90NMTvY6fyBA=; b=YAxZ98hVrFhlcrWkO+gP3cYySpnVbEvl4z0VFdXcc603 6PmOqJPCiiy9QdCCQwJF2Fanv8jVLGLCU7I5WiM1QXe2KLzgXNH3FivJmu8N/inW VEMBDWGJkKOrAJRwuCAg7AuxRg3cznos89CeZmYJApQ5n1FKJjAZGGzRwyomeCHh Dnz46JnfiWDflFAaBRbpZUQepaJxjL11+DlqL2wI+Jf8P1jTO5Walym8s+Y8BEWQ 1e14Yi3a13LO+Lnl8VndrDishsIBTIRYpimIbjEkuXL4v4gDo4glayp5vSf3HGOA opuWWuyd5PRZgKMK3HEQd+346EigenfAWZPK520VLA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrfedufedguddvgecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecunecujfgurhepfffhvfevuffkfhggtggujgesgh dtreertddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhs sehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepueektdevtdffveeljeetgfehheeige ekleduvdeffeeghefgledttdehjeelffetnecuvehluhhsthgvrhfuihiivgeptdenucfr rghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 12 Jun 2024 04:03:25 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 8a4a2fd2 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 12 Jun 2024 08:03:14 +0000 (UTC) Date: Wed, 12 Jun 2024 10:03:23 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Kyle Lippincott , Junio C Hamano Subject: [PATCH v2 1/3] config: fix segfault when parsing "core.abbrev" without repo Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: The "core.abbrev" config allows the user to specify the minimum length when abbreviating object hashes. Next to the values "auto" and "no", this config also accepts a concrete length that needs to be bigger or equal to the minimum length and smaller or equal to the hash algorithm's hex length. While the former condition is trivial, the latter depends on the object format used by the current repository. It is thus a variable upper boundary that may either be 40 (SHA-1) or 64 (SHA-256). This has two major downsides. First, the user that specifies this config must be aware of the object hashes that its repository use. If they want to configure the value globally, then they cannot pick any value in the range `[41, 64]` if they have any repository that uses SHA-1. If they did, Git would error out when parsing the config. Second, and more importantly, parsing "core.abbrev" crashes when outside of a Git repository because we dereference `the_hash_algo` to figure out its hex length. Starting with c8aed5e8da (repository: stop setting SHA1 as the default object hash, 2024-05-07) though, we stopped initializing `the_hash_algo` outside of Git repositories. Fix both of these issues by not making it an error anymore when the given length exceeds the hash length. Instead, leave the abbreviated length intact. `repo_find_unique_abbrev_r()` handles this just fine except for a performance penalty which we will fix in a subsequent commit. Reported-by: Kyle Lippincott Signed-off-by: Patrick Steinhardt --- config.c | 4 ++-- t/t4202-log.sh | 12 ++++++++++++ t/t5601-clone.sh | 7 +++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/config.c b/config.c index abce05b774..0416b0f2b6 100644 --- a/config.c +++ b/config.c @@ -1460,10 +1460,10 @@ static int git_default_core_config(const char *var, const char *value, if (!strcasecmp(value, "auto")) default_abbrev = -1; else if (!git_parse_maybe_bool_text(value)) - default_abbrev = the_hash_algo->hexsz; + default_abbrev = GIT_MAX_HEXSZ; else { int abbrev = git_config_int(var, value, ctx->kvi); - if (abbrev < minimum_abbrev || abbrev > the_hash_algo->hexsz) + if (abbrev < minimum_abbrev) return error(_("abbrev length out of range: %d"), abbrev); default_abbrev = abbrev; } diff --git a/t/t4202-log.sh b/t/t4202-log.sh index 86c695eb0a..e97826458c 100755 --- a/t/t4202-log.sh +++ b/t/t4202-log.sh @@ -1237,6 +1237,18 @@ test_expect_success 'log.abbrevCommit configuration' ' test_cmp expect.whatchanged.full actual ' +test_expect_success '--abbrev-commit with core.abbrev=false' ' + git log --no-abbrev >expect && + git -c core.abbrev=false log --abbrev-commit >actual && + test_cmp expect actual +' + +test_expect_success '--abbrev-commit with core.abbrev=9000' ' + git log --no-abbrev >expect && + git -c core.abbrev=9000 log --abbrev-commit >actual && + test_cmp expect actual +' + test_expect_success 'show added path under "--follow -M"' ' # This tests for a regression introduced in v1.7.2-rc0~103^2~2 test_create_repo regression && diff --git a/t/t5601-clone.sh b/t/t5601-clone.sh index cc0b953f14..5d7ea147f1 100755 --- a/t/t5601-clone.sh +++ b/t/t5601-clone.sh @@ -46,6 +46,13 @@ test_expect_success 'output from clone' ' test $(grep Clon output | wc -l) = 1 ' +test_expect_success 'output from clone with core.abbrev does not crash' ' + rm -fr dst && + echo "Cloning into ${SQ}dst${SQ}..." >expect && + git -c core.abbrev=12 clone -n "file://$(pwd)/src" dst >actual 2>&1 && + test_cmp expect actual +' + test_expect_success 'clone does not keep pack' ' rm -fr dst && From patchwork Wed Jun 12 08:03:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13694597 Received: from fout4-smtp.messagingengine.com (fout4-smtp.messagingengine.com [103.168.172.147]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 01FF74C63 for ; Wed, 12 Jun 2024 08:03:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.147 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718179417; cv=none; b=MHh9tURMA7PYXVt0jhKNj1sXz5jrVVt8g1MSu++VhSid3SFN/9ToMHXgBmT9EBLYFVB9GoVd99R9NTx9ONbseWiTV7/xYiZWx43iPNSNZkikKZBzppircIM7b2heB4DqkhdBOge1uNpbaWTbpcEc6vEK+tDRJx7+1dfaBfK0KsA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718179417; c=relaxed/simple; bh=s040zfoMXTy6c4VuGPjHQsbxYV8k0DuUEjrNYuz4xdo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=EtNqTJkAKMq4svzxf6aISbk/OQ6Q1ox+Q0+WH1R2MMFUh9JUU5de0lFr0rGp2oCQMJyC0pEIcJGo4HsZXbit/sBIBAtSeT3e0bWTFCHFkOiHNktES/roISnxfHk7unMyzFefS/2fRAPONkSraX9yYLvyyme8RJj0LmK39tCYaEw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=GXSo93mc; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=HWv0vHCO; arc=none smtp.client-ip=103.168.172.147 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="GXSo93mc"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="HWv0vHCO" Received: from compute7.internal (compute7.nyi.internal [10.202.2.48]) by mailfout.nyi.internal (Postfix) with ESMTP id 2BA5013800FC; Wed, 12 Jun 2024 04:03:35 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute7.internal (MEProxy); Wed, 12 Jun 2024 04:03:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1718179415; x=1718265815; bh=DjoEtAMor0 ldAWdXpi0x++sFQCNnX1sMW2hAUhcUpuw=; b=GXSo93mcTKn/C+d571cwzr1s5D dZeN8mw+TLu73GuLXMjE32I4aQbAZYzaSBO7bUMon3HqHTB9xzp4wC2Bau4+w50Y Yf9whIM1n08stD23t8JNJ9ThwG3N3PvDQj4P+sewuwzRQWGQLBkxCHUo4vLlwri3 +yjTKEWg5ChzDMdcD3jTuG73P+wZuOAthka1qHVPHC+8o+vjnKQyUxd0PEYx0UMK DDLp3Hj7Ga8Bic5t0pkSZq/Tqw2OCJyPSXvT40TchBrA5Toow8xBt9Pc1s66ZeEr fVq6X/Ise56a9+lwHvZwAAlE64KDceGB52nee4VdQm+NFumq6usoFw7yR7SQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1718179415; x=1718265815; bh=DjoEtAMor0ldAWdXpi0x++sFQCNn X1sMW2hAUhcUpuw=; b=HWv0vHCOpGvAz8PkcUllgZbYbbRg52W8MvWSNd8YF593 8/vepd8x715AUj5wVDYBRtK5bKtk3KPFUC7UCEJLBEjW+DJJ50v38YLeIbnk2pBX 53SvJ+/u7tR0GSoY5rOaMm5knSi6CgR9NHbTuchpiym63YQTyKmoqotky50f6NEN FDdsD5aLD+7sp5XDK02R5uLT5MbGQQm0yacA8vVg46Hl0B0HAVrJGkrEp4PeMhuU qRH7WBKn3AJmy+iBh0OJEh727BrNQsdOOYTtyTkl4LzhhwHwOHIyqSIHDH5tBrS3 FIAqaxfPt61F6NlS6xbV7EDPmZPZBWGDsdHFpSkAJw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrfedufedguddvgecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecunecujfgurhepfffhvfevuffkfhggtggujgesgh dtreertddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhs sehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepueektdevtdffveeljeetgfehheeige ekleduvdeffeeghefgledttdehjeelffetnecuvehluhhsthgvrhfuihiivgeptdenucfr rghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 12 Jun 2024 04:03:34 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 441d1ec9 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 12 Jun 2024 08:03:23 +0000 (UTC) Date: Wed, 12 Jun 2024 10:03:31 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Kyle Lippincott , Junio C Hamano Subject: [PATCH v2 2/3] parse-options-cb: stop clamping "--abbrev=" to hash length Message-ID: <92860256a61f14b60d6172d396f3ba5fd7be557c.1718178996.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: The `OPT__ABBREV()` option allows the user to specify the length that object hashes shall be abbreviated to. This length needs to be in the range of `(MIN_ABBREV, the_hash_algo->hexsz)`, which is why we clamp the value as required. While this makes sense in the case of `MIN_ABBREV`, it is unnecessary for the upper boundary as the value is eventually passed down to `repo_find_unnique_abbrev_r()`, which handles values larger than the current hash length just fine. In the preceding commit, we have changed parsing of the "core.abbrev" config to stop clamping to the upper boundary. Let's do the same here so that the code becomes simpler, we are consistent with how we treat the "core.abbrev" config and so that we stop depending on `the_repository`. Signed-off-by: Patrick Steinhardt --- parse-options-cb.c | 2 -- t/t4202-log.sh | 12 ++++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/parse-options-cb.c b/parse-options-cb.c index d99d688d3c..b2aa62a9dc 100644 --- a/parse-options-cb.c +++ b/parse-options-cb.c @@ -30,8 +30,6 @@ int parse_opt_abbrev_cb(const struct option *opt, const char *arg, int unset) opt->long_name); if (v && v < MINIMUM_ABBREV) v = MINIMUM_ABBREV; - else if (startup_info->have_repository && v > the_hash_algo->hexsz) - v = the_hash_algo->hexsz; } *(int *)(opt->value) = v; return 0; diff --git a/t/t4202-log.sh b/t/t4202-log.sh index e97826458c..51f7beb59f 100755 --- a/t/t4202-log.sh +++ b/t/t4202-log.sh @@ -1243,12 +1243,24 @@ test_expect_success '--abbrev-commit with core.abbrev=false' ' test_cmp expect actual ' +test_expect_success '--abbrev-commit with --no-abbrev' ' + git log --no-abbrev >expect && + git log --abbrev-commit --no-abbrev >actual && + test_cmp expect actual +' + test_expect_success '--abbrev-commit with core.abbrev=9000' ' git log --no-abbrev >expect && git -c core.abbrev=9000 log --abbrev-commit >actual && test_cmp expect actual ' +test_expect_success '--abbrev-commit with --abbrev=9000' ' + git log --no-abbrev >expect && + git log --abbrev-commit --abbrev=9000 >actual && + test_cmp expect actual +' + test_expect_success 'show added path under "--follow -M"' ' # This tests for a regression introduced in v1.7.2-rc0~103^2~2 test_create_repo regression && From patchwork Wed Jun 12 08:03:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13694598 Received: from fout4-smtp.messagingengine.com (fout4-smtp.messagingengine.com [103.168.172.147]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0789016D9B0 for ; Wed, 12 Jun 2024 08:03:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.147 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718179422; cv=none; b=qt635rxFAHTh+cv4UdRwrFMTlCNjSHDc1hKftFUz3XfHNU1CvdiuOPNHEywXfzChM/PZfet4U3B9yZpAGDi1DK/wvMY4XL7tIM/avxyTwhwPhtvWaIIlycA3BenRJzwkWJcEWqMm1/TnHM5A6t3srj2q/JXhcvcOIOsqDFodN0E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718179422; c=relaxed/simple; bh=Ys644v6hgwqRUjsDfxjHDW3z0uuwXuTjGRNrXI2uTIA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=DX3FpjGnVBnmCBX3qbYXy1yvuhwqD3dFuc+/gikxr4DJkPuNsBiPGrD8/e+FPXAF5tG5/C05QFLzVX2i5FcMVj8JsbgPTVR4+RGSYzh9u/0eyuIYHIDtKrUMzcX/zi9KJ2l8yoXXtBSYsEunAMbqVDZWPH2prs47ScZYh06ocaQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=LdLCUOoM; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=MpNxkekO; arc=none smtp.client-ip=103.168.172.147 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="LdLCUOoM"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="MpNxkekO" Received: from compute7.internal (compute7.nyi.internal [10.202.2.48]) by mailfout.nyi.internal (Postfix) with ESMTP id 5BCE413800FC; Wed, 12 Jun 2024 04:03:40 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute7.internal (MEProxy); Wed, 12 Jun 2024 04:03:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1718179420; x=1718265820; bh=KNWaneA2gC NzKmNZFUlaFCk2pozweAFT2BdSugPa01o=; b=LdLCUOoMAZVyGioiD7bl7WRUbA Dn+twiWbH+HtHK8sREWLUy2FFl255KMOjoRs2pcXUtOEVTAl0ZTbUkUOFOUmyRju Tj+CMaZv7BG+BI+iha8yF+1vfb89Tz0xUn8A+w1JoAr/LZ7ueX3EqL9naGW2kK7u yCsx/ElLiwP7b+WnodoQYqNkQL83sHgOrI7HqIyq0gxxNYL2sS4O/5IlIMUY1rBy tuAbSeoJrimEOZe2zvLFA4OyNTdtHGqddI/L8yuL8kl8F5BKEwcADs22upNGNK6s ccviD/2163f+lM124TLFY57v+dLqdmefEBp2qLAoIF1n1VgwOt0XUq/C8jLA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1718179420; x=1718265820; bh=KNWaneA2gCNzKmNZFUlaFCk2pozw eAFT2BdSugPa01o=; b=MpNxkekOrkwOIiJzhNXBSqonwOfn4+6pjkjO/HDHafy8 +alwkqq1W+jIRI37S8jq1kS2DbR35m18KiRmz80tT0nfgp7ABGgulgOhR7V7FZRV hZY3VOb8KwKJn099mLR1EACUjllJgRsBsexgYvzLhVLfW/fUKWyl//NYeWVmyxit G4LlQasKVk2v+XYURN3JIDndBJR9IVU72OaY5LcYgLB/Ee96mDfJhWfE7F7PPfys lGpLT1RgKk2J44uTTQ5dNxCOFWtje90YIL2eyosXeZCDzmKuLG528ZUUEQO5fDF4 2mOrcj1FmFiFGvoaESLPyJHyc04GbgKAStZNrDhv5Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrfedufedguddvgecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecunecujfgurhepfffhvfevuffkfhggtggujgesgh dtreertddtjeenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhs sehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepteeuvefhhfdufedvgeeiueeileegtd fhgeeftdeuveejjedtgfejhedujeeutddunecuvehluhhsthgvrhfuihiivgeptdenucfr rghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 12 Jun 2024 04:03:39 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 7993d7e3 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 12 Jun 2024 08:03:27 +0000 (UTC) Date: Wed, 12 Jun 2024 10:03:36 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Kyle Lippincott , Junio C Hamano Subject: [PATCH v2 3/3] object-name: don't try to abbreviate to lengths greater than hexsz Message-ID: <0ccb8d8efa4010c4a7ba00ca1abe7f3e923843ed.1718178996.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: When given a length that equals the current hash algorithm's hex size, then `repo_find_unique_abbrev_r()` exits early without trying to find an abbreviation. This is only sensible because there is nothing to abbreviate in the first place, so searching through objects to find a unique prefix would be a waste of compute. What we don't handle though is the case where the user passes a length greater than the hash length. This is fine in practice as we still compute the correct result. But at the very least, this is a waste of resources as we try to abbreviate a value that cannot be abbreviated, which causes us to hit the object database. Start to explicitly handle values larger than hexsz to avoid this performance penalty, which leads to a measureable speedup. The following benchmark has been executed in linux.git: Benchmark 1: git -c core.abbrev=9000 log --abbrev-commit (revision = HEAD~) Time (mean ± σ): 12.812 s ± 0.040 s [User: 12.225 s, System: 0.554 s] Range (min … max): 12.723 s … 12.857 s 10 runs Benchmark 2: git -c core.abbrev=9000 log --abbrev-commit (revision = HEAD) Time (mean ± σ): 11.095 s ± 0.029 s [User: 10.546 s, System: 0.521 s] Range (min … max): 11.037 s … 11.122 s 10 runs Summary git -c core.abbrev=9000 log --abbrev-commit HEAD (revision = HEAD) ran 1.15 ± 0.00 times faster than git -c core.abbrev=9000 log --abbrev-commit HEAD (revision = HEAD~) Signed-off-by: Patrick Steinhardt --- object-name.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/object-name.c b/object-name.c index 523af6f64f..1be2ad1a16 100644 --- a/object-name.c +++ b/object-name.c @@ -837,7 +837,7 @@ int repo_find_unique_abbrev_r(struct repository *r, char *hex, } oid_to_hex_r(hex, oid); - if (len == hexsz || !len) + if (len >= hexsz || !len) return hexsz; mad.repo = r;