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

Re: [PATCH] chainlint: colorize problem annotations and test delimiters

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Sep 13, 2022, 00:30 UTC
Message-ID
<CAPig+cRTatQRS2MyOTfmz56UKqtz_x_Gk6j=rnYR-jTkM-CDdQ@mail.gmail.com>
In-Reply-To
<Yx/LpUglpjY5ZNas@coredump.intra.peff.net>
On Mon, Sep 12, 2022 at 8:15 PM Jeff King <peff@peff.net> wrote:
Show 25 quoted lines
> On Mon, Sep 12, 2022 at 11:04:48PM +0000, Eric Sunshine via GitGitGadget wrote:
> > +my @NOCOLORS = (bold => '', reset => '', blue => '', green => '', red => '');
> > +my %COLORS = ();
> > +sub get_colors {
> > +     return \%COLORS if %COLORS;
> > +     if (exists($ENV{NO_COLOR}) ||
> > +         system("tput sgr0 >/dev/null 2>&1") != 0 ||
> > +         system("tput bold >/dev/null 2>&1") != 0 ||
> > +         system("tput setaf 1 >/dev/null 2>&1") != 0) {
> > +             %COLORS = @NOCOLORS;
> > +             return \%COLORS;
> > +     }
> > +     %COLORS = (bold  => `tput bold`,
> > +                reset => `tput sgr0`,
> > +                blue  => `tput setaf 4`,
> > +                green => `tput setaf 2`,
> > +                red   => `tput setaf 1`);
> > +     chomp(%COLORS);
> > +     return \%COLORS;
> > +}
>
> This is a lot of new processes. Should be OK in the run-once-for-all-tests
> mode. It does make me wonder how much time regular test-lib.sh spends
> doing these tput checks for every script (at least it's not every
> snippet!).

This is indeed a lot of new processes, but this color interrogation is done lazily, only if a problem is detected, so it should be zero-cost in the (hopefully) normal case of a lint-clean script.

I had the exact same thought about the cost being paid by test-lib.sh making all those `tput` invocations.

Show 5 quoted lines
> It feels like we could build a color.sh snippet once and then include it
> in each script. But maybe that is dumb, since you could in theory build
> in one terminal and then run in another. Unlikely, but it shows that
> file dependencies are a mismatch. I guess a better match would be
> stuffing it into the environment before starting all of the tests.
That might be worth considering at some point.
> I ran this on my pre-fixup state where I had a half-dozen linter checks.
> It's _so_ much more readable. Thanks for working on it.
Good to hear.
Previous: Jeff KingNext: Jeff King
Message 8 of 18 in “chainlint: colorize problem annotations and test delimiters”
  1. chainlint: colorize problem annotations and test delimitersEric Sunshine via GitGitGadget, Sep 12, 2022
  2. Junio C HamanoSep 12, 2022
  3. Eric SunshineSep 13, 2022
  4. Junio C HamanoSep 13, 2022
  5. Eric SunshineSep 13, 2022
  6. Jeff KingSep 13, 2022
  7. Jeff KingSep 13, 2022
  8. Eric SunshineSep 13, 2022
  9. Jeff KingSep 13, 2022
  10. Jeff KingSep 13, 2022
  11. chainlint: colorize problem annotations and test delimitersEric Sunshine via GitGitGadget, Sep 13, 2022
  12. Jeff KingSep 13, 2022
  13. Junio C HamanoSep 13, 2022
  14. Ævar Arnfjörð BjarmasonOct 24, 2022
  15. chainlint.pl's new "deparse" output (was: [PATCH v2] [...])Ævar Arnfjörð Bjarmason, Oct 24, 2022
  16. Eric SunshineOct 25, 2022
  17. Eric SunshineOct 25, 2022
  18. Ævar Arnfjörð BjarmasonOct 25, 2022

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.