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

Re: [PATCH 2/2] Highlight keywords in remote sideband output.

From
Han-Wen Nienhuys <hanwen@google.com>
Date
Aug 2, 2018, 11:43 UTC
Message-ID
<CAFQ2z_OZjGykJ6xUwXB69MSChJpPQzc0xBPDw82oA6+tOs00qQ@mail.gmail.com>
In-Reply-To
<CAPig+cSbibJ7i8LwJqPe06xJObnq6dJdMUnJoC1uAg4zUQq3KA@mail.gmail.com>
On Tue, Jul 31, 2018 at 10:21 PM Eric Sunshine <sunshine@sunshineco.com> wrote:
Show 6 quoted lines
>
> On Tue, Jul 31, 2018 at 1:37 PM Han-Wen Nienhuys <hanwen@google.com> wrote:
> > Highlight keywords in remote sideband output.
>
> Prefix with the module you're touching, don't capitalize, and drop the
> period. Perhaps:
Done.
Show 10 quoted lines
>     sideband: highlight keywords in remote sideband output
>
> > The highlighting is done on the client-side. Supported keywords are
> > "error", "warning", "hint" and "success".
> >
> > The colorization is controlled with the config setting "color.remote".
>
> What's the motivation for this change? The commit message should say
> something about that and give an explanation of why this is done
> client-side rather than server-side.
Added
> > Co-authored-by: Duy Nguyen <pclouds@gmail.com>
>
> Helped-by: is more typical.
Done.
Show 10 quoted lines
> > Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
> > ---
> > diff --git a/Documentation/config.txt b/Documentation/config.txt
> > @@ -1229,6 +1229,15 @@ color.push::
> > +color.remote::
> > +       A boolean to enable/disable colored remote output. If unset,
> > +       then the value of `color.ui` is used (`auto` by default).
>
> If this is "boolean", what does "auto" mean? Perhaps update the
> description to better match other color-related options.

All other doc entries say "boolean" here too. I'm happy to fix phrasing of this file in a follow-on change, but let's keep it like this for consistency.

Show 13 quoted lines
> > diff --git a/sideband.c b/sideband.c
> > @@ -1,6 +1,97 @@
> > +void maybe_colorize_sideband(struct strbuf *dest, const char *src, int n)
> > +{
> > +       int i;
> > +
> > +       load_sideband_colors();
> > +       if (!want_color_stderr(sideband_use_color)) {
> > +               strbuf_add(dest, src, n);
> > +               return;
> > +       }
>
> Can load_sideband_colors() be moved below the !want_color_stderr() conditional?
Reorganized this a bit.
Show 13 quoted lines
> > +
> > +       while (isspace(*src)) {
> > +               strbuf_addch(dest, *src);
> > +               src++;
> > +               n--;
> > +       }
> > +
> > +       for (i = 0; i < ARRAY_SIZE(keywords); i++) {
> > +               struct kwtable* p = keywords + i;
> > +               int len = strlen(p->keyword);
>
> Would it make sense to precompute each keyword length so you don't
> have to recompute them repeatedly, or is that premature optimization?

That is premature optimization. The next line does a strncasecmp on the same data so the cost (loading the keywords into CPU cache) is the same, while precomputing the length makes the code more error prone.

Show 7 quoted lines
> > +               if (!strncasecmp(p->keyword, src, len) && !isalnum(src[len])) {
>
> So, the strncasecmp() is checking if one of the recognized keywords is
> at the 'src' position, and the !isalnum() ensures that you won't pick
> up something of which the keyword is merely a prefix. For instance,
> you won't mistakenly highlight "successful". It also works correctly
> when 'len' happens to reference the end-of-string NUL. Okay.
added comment.
Show 13 quoted lines
> > +                       strbuf_addstr(dest, p->color);
> > +                       strbuf_add(dest, src, len);
> > +                       strbuf_addstr(dest, GIT_COLOR_RESET);
> > +                       n -= len;
> > +                       src += len;
> > +                       break;
> > +               }
>
> So, despite the explanation in the commit message, this function isn't
> _generally_ highlighting keywords in the sideband. Instead, it is
> highlighting a keyword only if it finds it at the start of string
> (ignoring whitespace). Perhaps the commit message could be more clear
> about that.
updated message.
> A natural follow-on question is whether strings are fed to this
> function one line at a time or if the incoming string may have
> embedded newlines (in which case, you might need to find a prefix
> following a newline, as well?).
added comment.
--
Google Germany GmbH, Erika-Mann-Strasse 33, 80636 Munich
Registergericht und -nummer: Hamburg, HRB 86891
Sitz der Gesellschaft: Hamburg
Geschäftsführer: Paul Manicle, Halimah DeLaine Prado
Previous: Stefan Beller
Message 15 of 15 in “Highlight keywords in remote sideband output.”
  1. 0/2 Highlight keywords in remote sideband output.Han-Wen Nienhuys, Jul 31, 2018
  2. 1/2 Document git config getter return value.Han-Wen Nienhuys, Jul 31, 2018
  3. Eric SunshineAug 1, 2018
  4. 2/2 Highlight keywords in remote sideband output.Han-Wen Nienhuys, Jul 31, 2018
  5. Junio C HamanoJul 31, 2018
  6. Eric SunshineJul 31, 2018
  7. Junio C HamanoAug 1, 2018
  8. Han-Wen NienhuysAug 1, 2018
  9. Junio C HamanoAug 1, 2018
  10. Han-Wen NienhuysAug 2, 2018
  11. Eric SunshineAug 2, 2018
  12. Han-Wen NienhuysAug 2, 2018
  13. Eric SunshineAug 2, 2018
  14. Stefan BellerAug 2, 2018
  15. Han-Wen NienhuysAug 2, 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.