From patchwork Mon Jan 15 10:36:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13519491 Received: from out5-smtp.messagingengine.com (out5-smtp.messagingengine.com [66.111.4.29]) (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 035CF2C68B for ; Mon, 15 Jan 2024 10:36:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none 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="c3Oaup4e"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="STtVsiyh" Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 4EEBA5C011D; Mon, 15 Jan 2024 05:36:09 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Mon, 15 Jan 2024 05:36:09 -0500 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=fm3; t=1705314969; x=1705401369; bh=+Y0V8uYcmE 3A65OAsGja2Dp1vjjNDZ+r/WDP0ilS4Rs=; b=c3Oaup4evqJOarpCOOuqS3l51r EpQIfIpj3BCpZVaYlUfRoaDjNUS7PNwpR4LA+PWsDIZwvqS/EpD6xVhijfV0NeLg C7kYBrqLayHA2vmde4XQQkiem5HsUtTE4VdluFyw6FB2hukShwMkpFdd1Tg0db5A OtyoxT36jeeWday2MCmuYPOZAg5UHhTKfr4ZZyziRLfD/FLk6Yc2IMjefFCI2iuu dlG+hig/LMaRlh8Sjt9CJh3mNcItBqvO4DB8dJLKkhPEw6olmE8WhAdfXeAr9r94 9E+/zqWoi3Af437PKI/OWCZuXYNnAc11Hnwtz6do/YGKdpJAe3ikVBy5nlqQ== 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= fm3; t=1705314969; x=1705401369; bh=+Y0V8uYcmE3A65OAsGja2Dp1vjjN DZ+r/WDP0ilS4Rs=; b=STtVsiyhX5ooU6BFfAgiOGDecuSNSj9DcO89m8YmEwV8 y+iNitsQoqRl/QKwsf3I7W/llCAo9b1CuZyl+eqV1O1GcvQMOkk3o7/NOyLmzFJU 4WDpab21Q/itreO5svyuVsVoDVnsgZoK+i+4V8rG0Ybtzz3wCTyFW/Fpd6x2QNkz gqVvhJgbAnyddjWscF6+blNcafkeGjAptsAc10stcAapFJLwXpVvc+t6aHdph8zF 3llipurFhqVQV31fvCYU64JCaaJomUkblWX04EIqr7Owlzaa13QpibII2WzjXvk5 sBGW5DbQRytG2bs5fwcect1cuBYxVHUJOOafhbLEzg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrvdejuddgudekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtudenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepfedvleefueetgeeitdekheelffekkefgffduhfduvdefffdtheekiefhkeejkeeh necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 15 Jan 2024 05:36:08 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 9e03a28b (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Mon, 15 Jan 2024 10:33:18 +0000 (UTC) Date: Mon, 15 Jan 2024 11:36:06 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Stan Hu , SZEDER =?iso-8859-1?q?G=E1bor?= , Jeff King , Johannes Schindelin , Junio C Hamano Subject: [PATCH v2 3/5] completion: improve existence check for pseudo-refs 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: Improve the existence check along the following lines: - Stop stripping the "ref :" prefix and compare to the expected value directly. This allows us to drop a now-unused variable that was previously leaking into the user's shell. - Mark the "head" variable as local so that we don't leak its value into the user's shell. - Stop manually handling the `-C $__git_repo_path` option, which the `__git ()` wrapper aleady does for us. - In simlar spirit, stop redirecting stderr, which is also handled by the wrapper already. Suggested-by: SZEDER Gábor Signed-off-by: Patrick Steinhardt --- contrib/completion/git-completion.bash | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 06a9107449..d703e3e64f 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -137,6 +137,7 @@ __git_eread () __git_pseudoref_exists () { local ref=$1 + local head __git_find_repo_path @@ -146,9 +147,8 @@ __git_pseudoref_exists () # Bash builtins since executing Git commands are expensive on some # platforms. if __git_eread "$__git_repo_path/HEAD" head; then - b="${head#ref: }" - if [ "$b" == "refs/heads/.invalid" ]; then - __git -C "$__git_repo_path" rev-parse --verify --quiet "$ref" 2>/dev/null + if [ "$head" == "ref: refs/heads/.invalid" ]; then + __git rev-parse --verify --quiet "$ref" return $? fi fi