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

Re: [PATCH] write-or-die: make GIT_FLUSH a Boolean environment variable

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 2, 2024, 16:29 UTC
Message-ID
<xmqqil4bg0me.fsf@gitster.g>
In-Reply-To
<20240101082446.GA21905@tb-raspi4>
Torsten Bögershausen <tboegi@web.de> writes:
Show 18 quoted lines
>> -	char *cp;
>> +	int cp;
>>
>>  	if (f == stdout) {
>>  		if (skip_stdout_flush < 0) {
>> -			/* NEEDSWORK: make this a normal Boolean */
>> -			cp = getenv("GIT_FLUSH");
>> -			if (cp)
>> -				skip_stdout_flush = (atoi(cp) == 0);
>> +			cp = git_env_bool("GIT_FLUSH", -1);
>> +			if (cp >= 0)
>> +				skip_stdout_flush = (cp == 0);
>>  			else if ((fstat(fileno(stdout), &st) == 0) &&
>>  				 S_ISREG(st.st_mode))
>>  				skip_stdout_flush = 1;
>
> I think that the "cp" variable could be renamed,
> cp is not a "char pointer" any more.
Absolutely.  Very good point.
> However, using the logic from git_env_bool(), it can go away anyway,
> wouldn't it ?
True.

If we are doing clean-ups in this area, we may want to also stop doing "== 0" comparisons on lines the patch touches while at it.

Show 32 quoted lines
>   diff --git a/write-or-die.c b/write-or-die.c
>   index 42a2dc73cd..01b042bf12 100644
>   --- a/write-or-die.c
>   +++ b/write-or-die.c
>   @@ -13,21 +13,21 @@
>     * more. So we just ignore that case instead (and hope we get
>     * the right error code on the flush).
>     *
>   + * The flushing can be skipped like this:
>   + * GIT_FLUSH=0 git-rev-list HEAD
>   + *
>     * If the file handle is stdout, and stdout is a file, then skip the
>   - * flush entirely since it's not needed.
>   + * flush as well since it's not needed.
>     */
>    void maybe_flush_or_die(FILE *f, const char *desc)
>    {
>           static int skip_stdout_flush = -1;
>           struct stat st;
>   -       char *cp;
>
>           if (f == stdout) {
>                   if (skip_stdout_flush < 0) {
>   -                       /* NEEDSWORK: make this a normal Boolean */
>   -                       cp = getenv("GIT_FLUSH");
>   -                       if (cp)
>   -                               skip_stdout_flush = (atoi(cp) == 0);
>   +                       if (git_env_bool("GIT_FLUSH", -1) == 0)
>   +                               skip_stdout_flush = 1;
>                           else if ((fstat(fileno(stdout), &st) == 0) &&
>                                    S_ISREG(st.st_mode))
>                                   skip_stdout_flush = 1;
Previous: Torsten BögershausenNext: Chandra Pratap via GitGitGadget
Message 3 of 13 in “write-or-die: make GIT_FLUSH a Boolean environment variable”
  1. write-or-die: make GIT_FLUSH a Boolean environment variableChandra Pratap via GitGitGadget, Dec 30, 2023
  2. Torsten BögershausenJan 1, 2024
  3. Junio C HamanoJan 2, 2024
  4. write-or-die: make GIT_FLUSH a Boolean environment variableChandra Pratap via GitGitGadget, Jan 3, 2024
  5. Patrick SteinhardtJan 3, 2024
  6. Taylor BlauJan 3, 2024
  7. Torsten BögershausenJan 3, 2024
  8. Junio C HamanoJan 3, 2024
  9. Taylor BlauJan 4, 2024
  10. Junio C HamanoJan 3, 2024
  11. write-or-die: make GIT_FLUSH a Boolean environment variableChandra Pratap via GitGitGadget, Jan 4, 2024
  12. Taylor BlauJan 4, 2024
  13. Junio C HamanoJan 4, 2024

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.