git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "Ville Skyttä" <ville.skytta@iki.fi>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] completion: fix prompt with unset SHOWCONFLICTSTATE in nounset mode
Date: Mon, 01 Apr 2024 10:26:10 -0700	[thread overview]
Message-ID: <xmqqh6gl9eq5.fsf@gitster.g> (raw)
In-Reply-To: <CABr9L5A_zz6ZvBWUoX_Px6Upyiur3+SPp8U91uw3OXO0mXZgeg@mail.gmail.com> ("Ville Skyttä"'s message of "Mon, 1 Apr 2024 17:07:01 +0000")

Ville Skyttä <ville.skytta@iki.fi> writes:

> I initially actually changed those very lines too when working on the
> fix for the issue I faced with GIT_PS1_SHOWCONFLICTSTATE. However,
> both occurrences are within __git_ps1_show_upstream, and the only call
> site for that function is protected by a check on the variable that
> does take possible unset state into account; the function will in the
> file's current form never be called with it unset. Additionally, the
> first occurrence is immediately following a line that sets the
> variable, so that one is "doubly protected".
>
> Therefore, I decided to undo those changes and not include them here.
> I guess it's a matter of taste whether one finds it desirable to
> protect those accesses nevertheless, but it's not strictly necessary.

I am glad you took a look into it already.  I wonder if we can
somehow keep this "institutional knowledge" to help the next person
by saving them from wasting time wondering about the reason why it
is safe (iow, what you have found out and described above).  Perhaps
a patch like this?  I dunno.

Anyway, thanks again for digging!

 contrib/completion/git-prompt.sh | 4 ++++
 1 file changed, 4 insertions(+)

diff --git i/contrib/completion/git-prompt.sh w/contrib/completion/git-prompt.sh
index 3826f52dec..b05e4cb049 100644
--- i/contrib/completion/git-prompt.sh
+++ w/contrib/completion/git-prompt.sh
@@ -113,6 +113,10 @@ printf -v __git_printf_supports_v -- '%s' yes >/dev/null 2>&1
 
 # stores the divergence from upstream in $p
 # used by GIT_PS1_SHOWUPSTREAM
+#
+# Note: ${GIT_PS1_SHOWUPSTREAM} is used without the nounset 
+# protection ${GIT_PS1_SHOWUPSTREAM-}, as the only caller calls
+# only after making sure it is already set.
 __git_ps1_show_upstream ()
 {
 	local key value


  reply	other threads:[~2024-04-01 17:26 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-01 11:30 [PATCH] completion: fix prompt with unset SHOWCONFLICTSTATE in nounset mode Ville Skyttä
2024-04-01 15:31 ` Junio C Hamano
2024-04-01 17:07   ` Ville Skyttä
2024-04-01 17:26     ` Junio C Hamano [this message]
2024-04-01 19:10       ` Ville Skyttä
2024-04-01 19:38         ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqh6gl9eq5.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=ville.skytta@iki.fi \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).