Re: [RFC PATCH 1/3] usage: extract `prefix_suffix_lines()` from `advise()`
- From
Jeff King <peff@peff.net>
- Date
- May 29, 2018, 21:33 UTC
- Message-ID
- <20180529213317.GE7964@sigill.intra.peff.net>
- In-Reply-To
- <CACsJy8CZQLxU5TPx=M0NV_xTR_9qyjbOWnVcdX9-Tz+BCb24VA@mail.gmail.com>
On Mon, May 28, 2018 at 08:40:16PM +0200, Duy Nguyen wrote:
Show 23 quoted lines
> On Fri, May 25, 2018 at 11:00 PM, Martin Ågren <martin.agren@gmail.com> wrote: > > advice.c contains a useful code snippet which takes a multi-line string > > and prints the lines, prefixing and suffixing each line with two > > constant strings. This was originally added in 23cb5bf3b3 (i18n of > > multi-line advice messages, 2011-12-22) to produce such output: > > > > hint: some multi-line advice > > hint: prefixed with "hint: " > > > > The prefix is actually colored after 960786e761 (push: colorize errors, > > 2018-04-21) and each line has a suffix for resetting the color. > > > > The next commit will teach the same "prefix all the lines"-trick to the > > code that produces, e.g., "warning: "-messages. In preparation for that, > > extract the code for printing the individual lines and expose it through > > git-compat-util.h. > > > > Signed-off-by: Martin Ågren <martin.agren@gmail.com> > > --- > > I'm open for suggestions on the naming of `prefix_suffix_lines()`... > > I think the important verb, print (to FILE*), is somehow missing. This > current name would be great if it produces another str(buf).
It can't use a strbuf, since we want vreportf() to avoid calling any allocation functions.
-Peff