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

Re: [PATCH] git-prompt.sh: shorter equal upstream branch name

From
RHRichard Hansen <rhansen@bbn.com>
Date
Oct 1, 2014, 03:54 UTC
Message-ID
<542B7AF8.6080501@bbn.com>
In-Reply-To
<xmqq7g0krb2p.fsf@gitster.dls.corp.google.com>
On 2014-09-30 18:35, Junio C Hamano wrote:
Show 8 quoted lines
> Richard Hansen <rhansen@bbn.com> writes:
>>   * While this syntax works in both Bash and Zsh (assuming no
>>     pattern-special characters), my preference is to stick to POSIX[1]
>>     when possible.
> 
> Nah.  The existing script is full of bash-isms like local you
> suggested to add (and other constructs like shell arrays and [[ ]]
> tests, I suspect),
True.
> and there is no hope to "fix" them to stick to
> the bare-minimum POSIX,

I don't think it'd be hard to convert it to pure POSIX if there was a desire to do so. The biggest challenge would be 'local', which would require subshells or uniquified prefixed global variables. Both of those are likely to make the code a bit grotesque.

> and there is no need to do so (isn't this
> bash-prompt script after all?)

It would be unwise to go to great lengths to avoid Bashisms, but I think it would be smart to use POSIX syntax when it is easy to do so. Rarely is it hard or awkward to use POSIX syntax ('local' and arrays are two major exceptions), so Bashisms like the ${//} expansion in this patch are usually unnecessary divergences from a ubiquitous standard. POSIX is a stable foundation, and it's easy to get POSIX shell code to run consistently on all POSIX-like shells.

One of these days I'll try converting git-prompt.sh to POSIX -- I'm curious to see how bad it would be.

-Richard
Previous: Junio C HamanoNext: Junio C Hamano
Message 4 of 9 in “git-prompt.sh: shorter equal upstream branch name”
  1. git-prompt.sh: shorter equal upstream branch nameJulien Carsique, Sep 30, 2014
  2. Richard HansenSep 30, 2014
  3. Junio C HamanoSep 30, 2014
  4. Richard HansenOct 1, 2014
  5. Junio C HamanoOct 1, 2014
  6. Julien CarsiqueOct 7, 2014
  7. Richard HansenOct 7, 2014
  8. Junio C HamanoOct 7, 2014
  9. Junio C HamanoSep 30, 2014

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.