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

Re: Conditional newline in pretty format

From
Jeff King <peff@peff.net>
Date
Mar 17, 2020, 17:18 UTC
Message-ID
<20200317171853.GA6598@coredump.intra.peff.net>
In-Reply-To
<CAHd499B+ro+d0bGA+-Y1Qnfkc1vMzXCnBfZmtZv+CscUXim=wQ@mail.gmail.com>
On Tue, Mar 17, 2020 at 10:37:13AM -0500, Robert Dailey wrote:
Show 5 quoted lines
> > It works perfectly right now except for the case where `%b` is empty.
> > In that case, I just want one newline after `%s` instead of 2. Is
> > there a way to make my second `%n` conditional on `%b` having a value?
> [...]
> Another solution I tried is `%+b`, based on this documentation:
That's what I would have suggested. And it does seem to work if you do:
  git log --format='* %s%n%+b'
but not when you add in the indentation and wrapping:
  git log --format='* %s%n%w(100,2,2)%+b'

Which is unfortunate, but I think makes sense: the wrapping sees the extra newline as part of the text to be wrapped, so it gets folded into the first line.

I think what you really want is a conditional that can cover multiple placeholders, and put the wrapped body inside that. You can do that with the for-each-ref placeholders, which have a real "%(if)...%(end)" block. But I don't think the pretty-format placeholders have an equivalent. It would be nice to unify them one day, but progress has been slow on that front.

I wonder in the meantime if it would be possible to introduce a block syntax to the pretty formats, like:

  git log --format='* %s%n%+{%w(100,2,2)%b}'

or something. I don't know the conditional code well enough to say whether that would be a trivial patch or a horribly complicated one. :)

-Peff
Previous: Robert DaileyNext: Robert Dailey
Message 3 of 5 in “Conditional newline in pretty format”
  1. Robert DaileyMar 17, 2020
  2. Robert DaileyMar 17, 2020
  3. Jeff KingMar 17, 2020
  4. Robert DaileyMar 17, 2020
  5. Jeff KingMar 17, 2020

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.