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

Re: [PATCH 8/8] worktree: simplify search for unique worktree

From
Junio C Hamano <gitster@pobox.com>
Date
Sep 10, 2020, 21:08 UTC
Message-ID
<xmqq363ppcg7.fsf@gitster.c.googlers.com>
In-Reply-To
<CAPig+cQ871p8+oQdBBY=ebDdjDWfa5NvEMroitEmk4Db8DfLvA@mail.gmail.com>
Eric Sunshine <sunshine@sunshineco.com> writes:
Show 12 quoted lines
>> Thanks for commenting. I found the original trickier than it had to be.
>> It spreads out the logic in several places and is careful to short-cut
>> the loop. My first thought was "why doesn't this just use the standard
>> form?". But I'm open to the idea that it might be a fairly personal
>> standard form... If there's any risk that someone else comes along and
>> simplifies this to use a `nr_found` variable, then maybe file this under
>> code churning?
>
> Maybe. Dunno. Even with the suggested function comment, I still find
> that the revised code has a higher cognitive load because the reader
> has to remember or figure out mentally what `found` contains by the
> `return found;` at the end of the function.

Judging from the phrase "standard form", I have a feeling that Martin thinks that the updated code is more intuitive (i.e. "we see another one while keeping the one we already found, so we know there is no unique answer"). I do not claim that would be the standard way and using a counter clamped to 2 is substandard, but I find the code more readable with the patch than the original.

Even though it helps somewhat that the counter is named "nr_found" and not "nr_match", I found it a bit awkward that the counter in the original pretends to count all the answers, yet does not really count all of them and stops at 2.

I agree with Martin that this would probably be subjective.
Thanks.
Previous: Eric SunshineNext: Martin Ågren
Message 14 of 33 in “various wt-status/worktree cleanups”
  1. 0/8 various wt-status/worktree cleanupsMartin Ågren, Sep 10, 2020
  2. 6/8 worktree: rename copy-pasted variableMartin Ågren, Sep 10, 2020
  3. Junio C HamanoSep 10, 2020
  4. Martin ÅgrenSep 12, 2020
  5. Martin ÅgrenSep 27, 2020
  6. 7/8 worktree: use skip_prefix to parse targetMartin Ågren, Sep 10, 2020
  7. 1/8 wt-status: replace sha1 mentions with oidMartin Ågren, Sep 10, 2020
  8. 2/8 wt-status: print to s->fp, not stdoutMartin Ågren, Sep 10, 2020
  9. 3/8 wt-status: introduce wt_status_state_free_buffers()Martin Ågren, Sep 10, 2020
  10. 8/8 worktree: simplify search for unique worktreeMartin Ågren, Sep 10, 2020
  11. Eric SunshineSep 10, 2020
  12. Martin ÅgrenSep 10, 2020
  13. Eric SunshineSep 10, 2020
  14. Junio C HamanoSep 10, 2020
  15. 4/8 worktree: drop useless call to strbuf_resetMartin Ågren, Sep 10, 2020
  16. Eric SunshineSep 10, 2020
  17. Martin ÅgrenSep 10, 2020
  18. Eric SunshineSep 10, 2020
  19. Martin ÅgrenSep 12, 2020
  20. 5/8 worktree: update renamed variable in commentMartin Ågren, Sep 10, 2020
  21. Taylor BlauSep 12, 2020
  22. Martin ÅgrenSep 12, 2020
  23. 0/7 various wt-status/worktree cleanupsMartin Ågren, Sep 27, 2020
  24. 1/7 wt-status: replace sha1 mentions with oidMartin Ågren, Sep 27, 2020
  25. 2/7 wt-status: print to s->fp, not stdoutMartin Ågren, Sep 27, 2020
  26. 4/7 worktree: inline `worktree_ref()` into its only callerMartin Ågren, Sep 27, 2020
  27. Eric SunshineSep 28, 2020
  28. Martin ÅgrenSep 28, 2020
  29. Eric SunshineSep 28, 2020
  30. 3/7 wt-status: introduce wt_status_state_free_buffers()Martin Ågren, Sep 27, 2020
  31. 5/7 worktree: update renamed variable in commentMartin Ågren, Sep 27, 2020
  32. 6/7 worktree: rename copy-pasted variableMartin Ågren, Sep 27, 2020
  33. 7/7 worktree: use skip_prefix to parse targetMartin Ågren, Sep 27, 2020

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.