git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eric Sunshine <sunshine@sunshineco.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: Mike Rappazzo <rappazzo@gmail.com>,
	David Turner <dturner@twopensource.com>,
	Git List <git@vger.kernel.org>
Subject: Re: [PATCH v7 1/3] worktree: add top-level worktree.c
Date: Wed, 16 Sep 2015 16:42:15 -0400	[thread overview]
Message-ID: <CAPig+cQ9QpGUZCaZXG3avChVdpXGoKXbKAc9vYUCFWMSUE-B4g@mail.gmail.com> (raw)
In-Reply-To: <xmqqwpvsx5ie.fsf@gitster.mtv.corp.google.com>

On Mon, Sep 14, 2015 at 1:41 PM, Junio C Hamano <gitster@pobox.com> wrote:
> Mike Rappazzo <rappazzo@gmail.com> writes:
>> On Sat, Sep 12, 2015 at 10:39 PM, Eric Sunshine <sunshine@sunshineco.com> wrote:
>>>> +struct worktree_list *get_worktree_list()
>>>
>>> Can we be more concise and call this get_worktrees()?
>>
>> I prefer 'get_worktree_list' because I also added the 'get_worktree'
>> function, and I wanted to differentiate
>> the function names.
>
> I'd say that plural can be differentiating enough; it probably is a
> matter of taste.  How often do external callers want to call
> get_worktree() and not get_worktrees()?

The shorter name, get_worktrees(), also has the minor benefit of
concision, similar to the way we use short variable names (i, j, n, p,
s) to help reveal and (often) make code structure obvious at a glance;
whereas long, noisy, wordy names tend to obscure code structure.

The "_list" suffix doesn't add any value over the shorter pluralizing
"s"; in fact, it may be (very, very slightly) detrimental in implying
too strongly that the return value must be a linked list.

>>>> +struct worktree {
>>>> +       char *path;
>>>> +       char *git_dir;
>>>> +       char *head_ref;
>>>> +       unsigned char head_sha1[20];
>>>> +       int is_detached;
>>>> +       int is_bare;
>>>> +};
>>>> +
>>>> +struct worktree_list {
>>>> +       struct worktree *worktree;
>>>> +       struct worktree_list *next;
>>>> +};
>>>
>>> I don't care too strongly, but an alternate approach (which I probably
>>> would have taken) would be to have get_worktrees() simply return an
>>> array of 'struct worktree' objects, hence no need for the additional
>>> 'struct worktree_list'.
>
> I do not think we are using this to hold thousands of worktree
> objects in core.  Adding "struct worktree *next" pointer to the
> worktree object itself would probably be sufficient for the need of
> codepaths that want to enumerate and iterate over them and that
> would be another way to lose the extra structure.

I was more concerned with the inherent (and, in this case,
unnecessary) complexity of a linked list. Being able to drop the extra
'worktree_list' structure was just an added benefit of moving to the
simpler array approach.

  reply	other threads:[~2015-09-16 20:42 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-04 21:39 [PATCH v7 0/3] worktree: worktree.c functions and list builtin command Michael Rappazzo
2015-09-04 21:39 ` [PATCH v7 1/3] worktree: add top-level worktree.c Michael Rappazzo
2015-09-10 20:04   ` Junio C Hamano
2015-09-11 10:33     ` Mike Rappazzo
2015-09-13  2:39   ` Eric Sunshine
2015-09-13  6:27     ` Eric Sunshine
2015-09-14 12:20     ` Mike Rappazzo
2015-09-14 17:41       ` Junio C Hamano
2015-09-16 20:42         ` Eric Sunshine [this message]
2015-09-16 20:32       ` Eric Sunshine
2015-09-16 20:49         ` Mike Rappazzo
2015-09-22  1:05           ` Eric Sunshine
2015-09-22  1:17             ` Junio C Hamano
2015-09-04 21:39 ` [PATCH v7 2/3] worktree: move/refactor find_shared_symref from branch.c Michael Rappazzo
2015-09-11 16:16   ` Junio C Hamano
2015-09-11 21:43     ` Mike Rappazzo
2015-09-11 21:52       ` Junio C Hamano
2015-09-11 23:10         ` Eric Sunshine
2015-09-12  2:33           ` Mike Rappazzo
2015-09-13  3:19   ` Eric Sunshine
2015-09-14 17:44     ` Mike Rappazzo
2015-09-16 21:09       ` Eric Sunshine
2015-09-16 21:36         ` Mike Rappazzo
2015-09-22  1:07           ` Eric Sunshine
2015-09-04 21:39 ` [PATCH v7 3/3] worktree: add 'list' command Michael Rappazzo
2015-09-11 22:02   ` Junio C Hamano
2015-09-13  4:25   ` Eric Sunshine

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAPig+cQ9QpGUZCaZXG3avChVdpXGoKXbKAc9vYUCFWMSUE-B4g@mail.gmail.com \
    --to=sunshine@sunshineco.com \
    --cc=dturner@twopensource.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=rappazzo@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).