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

Re: [RFC PATCH] git-prompt: make colourization consistent

From
Joakim Petersen <joak-pet@online.no>
Date
Jun 1, 2022, 18:32 UTC
Message-ID
<47ba2296-10f3-4590-dbf5-38d92ed3e29e@online.no>
In-Reply-To
<xmqq7d60tfyd.fsf@gitster.g>
On 01/06/2022 20:07, Junio C Hamano wrote:
Show 29 quoted lines
> Hmph, am I correct to understand that the general flow of __git_ps1 is
> 
>   (1) various pieces of information like $h, $w, $i, $s, $r, $b, $p,
>       etc.  are declared "local" and values computed for them,
>       either inside __git_ps1() itself, or by various helper
>       functions it calls;
> 
>   (2) When GIT_PS1_SHOWCOLORHINTS is in effect, we may call the
>       __git_ps1_colorize_gitstring helper (which is touched by the
>       above hunk), that modifies these variables with color codes.
>       Upon entry to this helper function, these variables prepared in
>       (1) have no color effects.  Upon leaving, they do.
> 
>   (3) Finally, the PS1 is asseembled by concatenating these
>       variables, whose text was prepared in (1) and then prefixed by
>       color codes in (2), one of the earliest steps begins like so:
> 
>       local f="$h$w$i$s$u"
>       local gitstring="$c$b${f:+$z$f}${sparse}$r$p"
> 
> In the final step of formulation, $p immediately follows $r in the
> resulting $PS1, and the existing code at the end of the (2) prefixes
> $c_clear before $r, and $r before such prefixing is free of coloring,
> so it is curious how this patch makes difference (other than emitting
> $c_clear one more time).  Unless there is a use of $p that does not
> immediately follow $r, that is.
> 
> Thanks.
> 

Your understanding is correct for the flow before the change I referenced (0ec7c23cdc6 (git-prompt: make upstream state indicator location consistent, 2022-02-27)), however, that commit changed the definition of $f and $gitstring to

	local f="$h$w$i$s$u$p"
	local gitstring="$c$b${f:+$z$f}${sparse}$r${upstream}"

This makes it so $p is no longer immediately preceded by $r, but rather $u, which, like all the preceding variables, except $h, will be colourized if enabled.

Previous: Junio C HamanoNext: Junio C Hamano
Message 5 of 43 in “git-prompt: make colourization consistent”
  1. git-prompt: make colourization consistentJoakim Petersen, Jun 1, 2022
  2. Ævar Arnfjörð BjarmasonJun 1, 2022
  3. Joakim PetersenJun 1, 2022
  4. Junio C HamanoJun 1, 2022
  5. Joakim PetersenJun 1, 2022
  6. Junio C HamanoJun 1, 2022
  7. git-prompt: make colourization consistentJoakim Petersen, Jun 2, 2022
  8. joak-pet@online.noJun 2, 2022
  9. Junio C HamanoJun 2, 2022
  10. Joakim PetersenJun 3, 2022
  11. git-prompt: make colourization consistentJoakim Petersen, Jun 3, 2022
  12. Junio C HamanoJun 3, 2022
  13. Joakim PetersenJun 3, 2022
  14. Joakim PetersenJun 3, 2022
  15. Justin DonnellyJun 3, 2022
  16. Junio C HamanoJun 3, 2022
  17. Joakim PetersenJun 4, 2022
  18. Junio C HamanoJun 6, 2022
  19. Junio C HamanoJun 3, 2022
  20. git-prompt: make colourization consistentJoakim Petersen, Jun 4, 2022
  21. Justin DonnellyJun 4, 2022
  22. Joakim PetersenJun 4, 2022
  23. git-prompt: make colourization consistentJoakim Petersen, Jun 4, 2022
  24. Bagas SanjayaJun 6, 2022
  25. Junio C HamanoJun 7, 2022
  26. Joakim PetersenJun 9, 2022
  27. Junio C HamanoJun 6, 2022
  28. Joakim PetersenJun 6, 2022
  29. Junio C HamanoJun 6, 2022
  30. Joakim PetersenJun 7, 2022
  31. git-prompt: make colourization consistentJoakim Petersen, Jun 6, 2022
  32. git-prompt: make colourization consistentJoakim Petersen, Jun 7, 2022
  33. Junio C HamanoJun 7, 2022
  34. Joakim PetersenJun 9, 2022
  35. SZEDER GáborJun 9, 2022
  36. Joakim PetersenJun 9, 2022
  37. Junio C HamanoJun 9, 2022
  38. SZEDER GáborJun 11, 2022
  39. git-prompt: make colouring consistentJoakim Petersen, Jun 9, 2022
  40. git-prompt: fix expansion of branch colour codesJoakim Petersen, Jun 9, 2022
  41. Junio C HamanoJun 10, 2022
  42. Joakim PetersenJun 10, 2022
  43. git-prompt: fix expansion of branch colour codesJoakim Petersen, Jun 10, 2022

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.