From: Jeff King <peff@peff.net>
To: Robert Dailey <rcdailey.lists@gmail.com>
Cc: Git <git@vger.kernel.org>
Subject: Re: Conditional newline in pretty format
Date: Tue, 17 Mar 2020 13:18:53 -0400 [thread overview]
Message-ID: <20200317171853.GA6598@coredump.intra.peff.net> (raw)
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:
> > 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
next prev parent reply other threads:[~2020-03-17 17:18 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-17 15:28 Conditional newline in pretty format Robert Dailey
2020-03-17 15:37 ` Robert Dailey
2020-03-17 17:18 ` Jeff King [this message]
2020-03-17 17:27 ` Robert Dailey
2020-03-17 17:55 ` Jeff King
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200317171853.GA6598@coredump.intra.peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
--cc=rcdailey.lists@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).