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

Re: [PATCH 1/1] Makefile: fix the "built from commit" code

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Jun 28, 2018, 16:23 UTC
Message-ID
<nycvar.QRO.7.76.6.1806281809060.73@tvgsbejvaqbjf.bet>
In-Reply-To
<20180628132314.GA14026@sigill.intra.peff.net>
Hi Peff,
On Thu, 28 Jun 2018, Jeff King wrote:
Show 14 quoted lines
> On Wed, Jun 27, 2018 at 09:35:23PM +0200, Johannes Schindelin via GitGitGadget wrote:
> 
> > To prevent erroneous commits from being reported (e.g. when unpacking
> > Git's source code from a .tar.gz file into a subdirectory of a different
> > Git project, as e.g. git_osx_installer does), we painstakingly set
> > GIT_CEILING_DIRECTORIES when trying to determine the current commit.
> > 
> > Except that we got the quoting wrong, and that variable therefore does
> > not have the desired effect.
> > 
> > Let's fix that quoting, and while at it, also suppress the unhelpful
> > message
> 
> I had to stare at the code for a bit to figure out what was wrong:
Do you want me to update the commit message?
Show 13 quoted lines
> > -	'-DGIT_BUILT_FROM_COMMIT="$(shell GIT_CEILING_DIRECTORIES=\"$(CURDIR)/..\" \
> > -		git rev-parse -q --verify HEAD || :)"'
> > +	'-DGIT_BUILT_FROM_COMMIT="$(shell \
> > +		GIT_CEILING_DIRECTORIES="$(CURDIR)/.." \
> > +		git rev-parse -q --verify HEAD 2>/dev/null)"'
> 
> The issue is that the $(shell) is resolved before the output is stuffed
> into the command-line with -DGIT_BUILT_FROM_COMMIT, and therefore is
> _not_ inside quotes. And thus backslashing the quotes is wrong, as the
> quote gets literally inserted into the CEILING_DIRECTORIES variable.
> 
> I thought at first we could not need the quotes in the post-image
> either, because shell variable assignments do not do word-splitting.
Show 6 quoted lines
> I.e.:
> 
>   FOO='with spaces'
>   BAR=$FOO sh -c 'echo $BAR'
> 
> works just fine.
	$ x="two  spaces"
	$ echo $x
	two spaces
Maybe we should quote a little bit more religiously.
Show 8 quoted lines
> But $(CURDIR) here is not a shell variable, but rather a Makefile
> variable, so it's expanded before we hit the shell. So we need the
> quotes. And unfortunately it also breaks if $(CURDIR) contains exotic
> metacharacters. If we cared we could use single quotes and $(CURDIR_SQ),
> but I suspect it would be far from the first thing to break in such a
> case.
> 
> Which is a long-winded way of saying the patch looks correct to me.
Thanks ;-)

Ciao, Dscho

Previous: Jeff KingNext: Junio C Hamano
Message 4 of 12 in “Makefile: fix the "built from commit" code”
  1. 0/1 Makefile: fix the "built from commit" codeJohannes Schindelin via GitGitGadget, Jun 28, 2018
  2. 1/1 Makefile: fix the "built from commit" codeJohannes Schindelin via GitGitGadget, Jun 27, 2018
  3. Jeff KingJun 28, 2018
  4. Johannes SchindelinJun 28, 2018
  5. Junio C HamanoJun 28, 2018
  6. Jeff KingJun 28, 2018
  7. Johannes SchindelinJun 29, 2018
  8. Jeff KingJun 28, 2018
  9. Johannes SchindelinJun 28, 2018
  10. brian m. carlsonJun 28, 2018
  11. 0/1 Fix "built from commit" logicJohannes Schindelin via GitGitGadget, Jun 29, 2018
  12. 1/1 Makefile: fix the "built from commit" codeJohannes Schindelin via GitGitGadget, Jun 27, 2018

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.