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

Re: [PATCH] for-each-repo: do nothing on empty config

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 6, 2021, 08:05 UTC
Message-ID
<xmqqa6tmtrr1.fsf@gitster.c.googlers.com>
In-Reply-To
<db7bf751-7541-59b9-a3a0-ec07e28eb9de@gmail.com>
Derrick Stolee <stolee@gmail.com> writes:
Show 15 quoted lines
>> Probably not worth a re-roll, but the above has higher cognitive load than:
>> 
>>     if (!value)
>>         return 0;
>>
>> which indicates clearly that the command succeeded, whereas `return
>> result` makes the reader scan all the code above the conditional to
>> figure out what values `result` could possibly hold.
>
> True. Looking at this again, it might be better to just update the
> loop to be
>
> 	for (i = 0; values && i < values->nr; i++) {
>
> which would run the loop zero times when there are zero results.

It is misleading, though. It forces readers to first assume that the loop body may update "values" from non-NULL to NULL in some condition and hunt for such a code in vain.

If some clean-up starts to become needed after the loop, the "if the value array is empty, immediately return 0" may have to be rewritten to "if empty, jump to the clean-up part after the loop", but until then, what Eric gave us would be the easiest to read, I would think.

> To me, "nonexistent" or "does not exist" doesn't adequately describe
> this (hypothetical) situation.
>
> Perhaps "fail-subcommand" might be better?

I wonder if "false" or "exit 1" would fit the bill. In any case, a comment may help, perhaps?

	test_expect_success 'do nothing and succeed on empty/missing config' '
		# if this runs even once, "false" ensures a failure
		git for-each-repo --config=bogus.config -- false
	'
Previous: Eric SunshineNext: Derrick Stolee
Message 9 of 15 in “for-each-repo: do nothing on empty config”
  1. for-each-repo: do nothing on empty configDerrick Stolee via GitGitGadget, Jan 5, 2021
  2. Eric SunshineJan 5, 2021
  3. Derrick StoleeJan 6, 2021
  4. Eric SunshineJan 6, 2021
  5. Derrick StoleeJan 6, 2021
  6. Eric SunshineJan 6, 2021
  7. Junio C HamanoJan 6, 2021
  8. Eric SunshineJan 7, 2021
  9. Junio C HamanoJan 6, 2021
  10. Derrick StoleeJan 6, 2021
  11. Junio C HamanoJan 6, 2021
  12. Junio C HamanoJan 6, 2021
  13. Derrick StoleeJan 7, 2021
  14. for-each-repo: do nothing on empty configDerrick Stolee via GitGitGadget, Jan 6, 2021
  15. for-each-repo: do nothing on empty configDerrick Stolee via GitGitGadget, Jan 8, 2021

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.