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

Re: [PATCH 1/2] gpg-interface: refactor 'enum sign_mode' parsing

From
Junio C Hamano <gitster@pobox.com>
Date
Sep 11, 2025, 16:29 UTC
Message-ID
<xmqqcy7xosu8.fsf@gitster.g>
In-Reply-To
<aMJm57VmWb3h167z@pks.im>
Patrick Steinhardt <ps@pks.im> writes:
Show 14 quoted lines
>> +	if (!parse_sign_mode(arg, val))
>> +		return 0;
>> +
>> +	return error("Unknown %s mode: %s", opt->long_name, arg);
>
> Would it make sense to maybe reverse the error handling and say
> something like:
>
>     if (parse_sign_mode(arg, val) < 0)
>         return error("Unknown %s mode: %s", opt->long_name, arg);
>
>     return 0;
>
> That reads a bit more natural to me at least.

I also thought that the original had a "Huh?" factor, but my reaction was more like "wouldn't it be easier to see if these are both sides of if/else?", i.e.

	if (parse_sign_mode(...))
		return error(...);
	else
		return 0;

which made me think that the differences were mostly subjective and refrained from commenting.

But after I see your version, I tend to agree that it is easier to see the flow if the most-straightforward success case ran through to the end, while exceptional cases (i.e. an error return, or the initial "unset" case) did early returns. I have to add, however, that I feel that this is mostly subjective and falls into "once it is in the tree, it's not really worth the patch noise to go and fix it up" category. If we will have v2 of this series, I do prefer to see it written more in your way, though.

Thanks.
Previous: Patrick SteinhardtNext: Christian Couder
Message 5 of 21 in “fast-import: start controlling how commit signatures are handled”
  1. 0/2 fast-import: start controlling how commit signatures are handledChristian Couder, Sep 10, 2025
  2. 1/2 gpg-interface: refactor 'enum sign_mode' parsingChristian Couder, Sep 10, 2025
  3. Junio C HamanoSep 10, 2025
  4. Patrick SteinhardtSep 11, 2025
  5. Junio C HamanoSep 11, 2025
  6. Christian CouderSep 12, 2025
  7. Christian CouderSep 12, 2025
  8. 2/2 fast-import: add '--signed-commits=<mode>' optionChristian Couder, Sep 10, 2025
  9. Junio C HamanoSep 10, 2025
  10. Christian CouderSep 12, 2025
  11. Junio C HamanoSep 12, 2025
  12. Christian CouderSep 15, 2025
  13. Junio C HamanoSep 15, 2025
  14. Christian CouderSep 17, 2025
  15. Junio C HamanoSep 10, 2025
  16. Christian CouderSep 12, 2025
  17. Junio C HamanoSep 12, 2025
  18. Patrick SteinhardtSep 11, 2025
  19. Junio C HamanoSep 11, 2025
  20. Christian CouderSep 12, 2025
  21. Christian CouderSep 12, 2025

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.