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

Re: [PATCH 3/3] Revert "bash prompt: avoid command substitution when finalizing gitstring"

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 22, 2013, 00:22 UTC
Message-ID
<xmqq7gfesheu.fsf@gitster.dls.corp.google.com>
In-Reply-To
<CA+sFfMc0BPo8pSLngi=bAWxYNT8xKFEOo77z3a12q+-Sq4qiiA@mail.gmail.com>
Brandon Casey <drafnel@gmail.com> writes:
Show 33 quoted lines
> On Wed, Aug 21, 2013 at 2:47 PM, Junio C Hamano <gitster@pobox.com> wrote:
>> Brandon Casey <bcasey@nvidia.com> writes:
>>
>>> From: Brandon Casey <drafnel@gmail.com>
>>>
>>> This reverts commit 69a8141a5d81925b7e08cb228535e9ea4a7a02e3.
>>>
>>> Old Bash (3.0) which is distributed with RHEL 4.X and other ancient
>>> platforms that are still in wide use, does not have a printf that
>>> supports -v.  Let's revert this patch and go back to using printf
>>> in the traditional way.
>>>
>>> Signed-off-by: Brandon Casey <drafnel@gmail.com>
>>> ---
>>
>> Is this something you can detect at load-time once, store the result
>> in a private variable and then switch on it at runtime, something
>> along the lines of...
>>
>>
>>         # on load...
>>         printf -v __git_printf_supports_v -- "%s" yes >/dev/null 2>&1
>>
>>         ...
>>
>>         if test "${__git_printf_supports_v}" = yes
>>         then
>>                 printf -v gitstring -- "$printf_format" "$gitstring"
>>         else
>>                 gitstring=$(printf -- "$printf_format" "$gitstring")
>>         fi
>
> Yes, that appears to work.

A real patch needs to be a bit more careful, though. The variable needs to be cleared before all of the above, and the testing would want to consider that the variable may not be set (i.e. use "${var-}" when checking).

Thanks.
Show 23 quoted lines
> -Brandon
>
>
>>>  contrib/completion/git-prompt.sh | 6 +-----
>>>  1 file changed, 1 insertion(+), 5 deletions(-)
>>>
>>> diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh
>>> index a81ef5a..7698ec4 100644
>>> --- a/contrib/completion/git-prompt.sh
>>> +++ b/contrib/completion/git-prompt.sh
>>> @@ -433,11 +433,7 @@ __git_ps1 ()
>>>       local gitstring="$c${b##refs/heads/}${f:+$z$f}$r$p"
>>>
>>>       if [ $pcmode = yes ]; then
>>> -             if [[ -n ${ZSH_VERSION-} ]]; then
>>> -                     gitstring=$(printf -- "$printf_format" "$gitstring")
>>> -             else
>>> -                     printf -v gitstring -- "$printf_format" "$gitstring"
>>> -             fi
>>> +             gitstring=$(printf -- "$printf_format" "$gitstring")
>>>               PS1="$ps1pc_start$gitstring$ps1pc_end"
>>>       else
>>>               printf -- "$printf_format" "$gitstring"
Previous: Brandon CaseyNext: Brandon Casey
Message 6 of 10 in “git-completion.bash: use correct Bash/Zsh array length syntax”
  1. 1/3 git-completion.bash: use correct Bash/Zsh array length syntaxBrandon Casey, Aug 21, 2013
  2. 2/3 t9902-completion.sh: old Bash still does not support array+=('') notationBrandon Casey, Aug 21, 2013
  3. 3/3 Revert "bash prompt: avoid command substitution when finalizing gitstring"Brandon Casey, Aug 21, 2013
  4. Junio C HamanoAug 21, 2013
  5. Brandon CaseyAug 21, 2013
  6. Junio C HamanoAug 22, 2013
  7. Brandon CaseyAug 22, 2013
  8. contrib/git-prompt.sh: handle missing 'printf -v' more gracefullyBrandon Casey, Aug 22, 2013
  9. contrib/git-prompt.sh: handle missing 'printf -v' more gracefullyBrandon Casey, Aug 22, 2013
  10. Junio C HamanoAug 22, 2013

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.