From patchwork Fri Nov 24 11:37:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13467577 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="o/HPigsx"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="xq32Y5Kc" Received: from wout2-smtp.messagingengine.com (wout2-smtp.messagingengine.com [64.147.123.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0036ECE for ; Fri, 24 Nov 2023 03:37:13 -0800 (PST) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.west.internal (Postfix) with ESMTP id 72A053200A3C for ; Fri, 24 Nov 2023 06:37:11 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Fri, 24 Nov 2023 06:37:11 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :message-id:mime-version:reply-to:sender:subject:subject:to:to; s=fm1; t=1700825830; x=1700912230; bh=0IZTtCCzTYk3/Muf6lT1bmVnO TWZMXH+TxUJTTnKPto=; b=o/HPigsxNOb6UAeyuH8cQna6MQM8UkxNUQiUm7tw7 /iR+fS939K1gSkAUaDtenI9t5QKOeYzNtK+ufxSU1U7BCasrp5rYi6ccJAtStFlA uBQgySMQrRpAB1qI+CNyhcbSrYjRQoLAnST30uOAsY5P9M6Ryd7mVwqEYGozJzO7 j80SyNUPGPUTqctWVcyHM6RgpcCiVkhkYFLgk4am8gzHYYWslCD2cJ6ONFsAsq9V K1IOZMbMMz/mFOhMHI45hFp9SRMfaoH+q/M8hgJ9UMX99hQfcgMn7P5WcBL+RURP utFPoS2JqW6ky3EVsNmf06eDrExJDp0Ni3B9n6rNDv13A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:message-id :mime-version:reply-to:sender:subject:subject:to:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t= 1700825830; x=1700912230; bh=0IZTtCCzTYk3/Muf6lT1bmVnOTWZMXH+TxU JTTnKPto=; b=xq32Y5Kc8RfJy5JJ+9iwujO5gfIJ1+TGUAwdF/Z+MuNWtFzKaYa G/RBsT5yL9V+OFNALmsnr9e8yYuUREXAR6VoN8i5xSrGNyAlIeUgIv4BdW8EfegH +KDfMJmV2FepxbPvYIN2ywX9G5bpzOt8V44/ZzTF/eoB4Dlxz1KICD7j37do90bR d/5lWNUuTJgNC0kHPV0hbi5S3/UcXAqIxsbRewDAX9tanIAgrk9URZQSRYYowlP8 FRya/Mlo4Hb2YwT8F31yC5GXQZHylTfc7/HMMnLfB3eGxV3qf+qobS81Ujw9Kolu TgsH/216SOblZ1Sur1khKih4r33cXBFs4AA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrudehhedgvdelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuffkgggtugesghdtreertd dtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhs rdhimheqnecuggftrfgrthhtvghrnhepjeeifedvueelfffgjeduffdvgefhiefgjefgvd dvfeduvefffeevfffhgfekieffnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghm pehmrghilhhfrhhomhepphhssehpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Fri, 24 Nov 2023 06:37:10 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 1a7ff13f (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Fri, 24 Nov 2023 11:36:09 +0000 (UTC) Date: Fri, 24 Nov 2023 12:37:06 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH] git-prompt: stop manually parsing HEAD Message-ID: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline We're manually parsing the HEAD reference in git-prompt to figure out whether it is a symbolic or direct reference. This makes it intimately tied to the on-disk format we use to store references and will stop working once we gain additional reference backends in the Git project. Refactor the code to always use git-symbolic-ref(1) to read HEAD, which is both simpler and compatible with alternate reference backends. Signed-off-by: Patrick Steinhardt --- contrib/completion/git-prompt.sh | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh index 2c030050ae..05de540e13 100644 --- a/contrib/completion/git-prompt.sh +++ b/contrib/completion/git-prompt.sh @@ -474,17 +474,10 @@ __git_ps1 () if [ -n "$b" ]; then : - elif [ -h "$g/HEAD" ]; then - # symlink symbolic ref - b="$(git symbolic-ref HEAD 2>/dev/null)" else - local head="" - if ! __git_eread "$g/HEAD" head; then - return $exit - fi - # is it a symbolic ref? - b="${head#ref: }" - if [ "$head" = "$b" ]; then + b="$(git symbolic-ref HEAD 2>/dev/null)" + + if test -z "$b"; then detached=yes b="$( case "${GIT_PS1_DESCRIBE_STYLE-}" in @@ -498,9 +491,14 @@ __git_ps1 () git describe HEAD ;; (* | default) git describe --tags --exact-match HEAD ;; - esac 2>/dev/null)" || + esac 2>/dev/null)" + + if test -z "$b"; then + test -z "$short_sha" && return $exit + + b="$short_sha..." + fi - b="$short_sha..." b="($b)" fi fi