git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] completion: fix prompt with unset SHOWCONFLICTSTATE in nounset mode

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 1, 2024, 17:26 UTC
Message-ID
<xmqqh6gl9eq5.fsf@gitster.g>
In-Reply-To
<CABr9L5A_zz6ZvBWUoX_Px6Upyiur3+SPp8U91uw3OXO0mXZgeg@mail.gmail.com>
Ville Skyttä <ville.skytta@iki.fi> writes:
Show 12 quoted lines
> 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
Previous: Ville SkyttäNext: Ville Skyttä
Message 4 of 6 in “completion: fix prompt with unset SHOWCONFLICTSTATE in nounset mode”
  1. completion: fix prompt with unset SHOWCONFLICTSTATE in nounset modeVille Skyttä, Apr 1, 2024
  2. Junio C HamanoApr 1, 2024
  3. Ville SkyttäApr 1, 2024
  4. Junio C HamanoApr 1, 2024
  5. Ville SkyttäApr 1, 2024
  6. Junio C HamanoApr 1, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.