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

Re: [PATCH 1/3] diff-merges: cleanup func_by_opt()

From
Junio C Hamano <gitster@pobox.com>
Date
Sep 16, 2022, 16:14 UTC
Message-ID
<xmqqy1uji9dz.fsf@gitster.g>
In-Reply-To
<87wna3jwx8.fsf@osv.gnss.ru>
Sergey Organov <sorganov@gmail.com> writes:
Show 14 quoted lines
> Junio C Hamano <gitster@pobox.com> writes:
>
>> Sergey Organov <sorganov@gmail.com> writes:
>>
>>> Get rid of unneeded "else" statements in func_by_opt().
>>
>> While it is true that loss of "else" will not change what the code
>> means, this change feels subjective and I'd say it falls into "once
>> committed, it is not worth the patch noise to go in and change"
>> category, not a "clean-up we should do".
>
> I agree the "else" vs "no else" is subjective, but the problem in fact
> is that the first "if", unlike the rest of them, already had no "else",
> making the code inconsistent.

This is a static helper function about a single "optarg" string that wanted to say "switch(optarg) { case "off": ... }" but couldn't in C, and I happen to view if strcmp else if strcmp ... sequence on the same string a poor-man's substitute for such a construct. So my take of it is to call the second "if" not being "else if" a problem, not the rest of it. If we add a new condition on a different input, making it "if (x) ...; switch(optarg) { ... }" that talks about something other than optarg, then writing it all with "if" without "else if" would make it harder to see the pattern, but I do not care too deeply either way, because this is unlikely to gain any logic more involved than "switch(optarg) { ... }".

> So the fix should either be adding one
> "else" to the first "if", or remove all of the "else". I chose the
> latter, to end up with less noisy code.

Yup, see above for the reason why I would choose else-if cascade if I had to but I do not care too deeply either way in this particular case ;-)

Previous: Sergey OrganovNext: Sergey Organov
Message 5 of 13 in “diff-merges: minor cleanups”
  1. 0/3 diff-merges: minor cleanupsSergey Organov, Sep 14, 2022
  2. 1/3 diff-merges: cleanup func_by_opt()Sergey Organov, Sep 14, 2022
  3. Junio C HamanoSep 15, 2022
  4. Sergey OrganovSep 16, 2022
  5. Junio C HamanoSep 16, 2022
  6. Sergey OrganovSep 16, 2022
  7. 2/3 diff-merges: cleanup set_diff_merges()Sergey Organov, Sep 14, 2022
  8. Junio C HamanoSep 15, 2022
  9. Sergey OrganovSep 16, 2022
  10. 3/3 diff-merges: clarify log.diffMerges documentationSergey Organov, Sep 14, 2022
  11. Junio C HamanoSep 15, 2022
  12. Sergey OrganovSep 16, 2022
  13. Junio C HamanoSep 16, 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.