git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Stefan Beller <sbeller@google.com>
Cc: sunshine@sunshineco.com, git@vger.kernel.org, jrnieder@gmail.com,
	johannes.schindelin@gmail.com, Jens.Lehmann@web.de,
	peff@peff.net
Subject: Re: [PATCHv4 1/3] submodule: implement `list` as a builtin helper
Date: Wed, 02 Sep 2015 00:20:56 -0700	[thread overview]
Message-ID: <xmqqk2s9p9rb.fsf@gitster.mtv.corp.google.com> (raw)
In-Reply-To: <xmqqtwrdrk1k.fsf@gitster.mtv.corp.google.com> (Junio C. Hamano's message of "Tue, 01 Sep 2015 12:55:51 -0700")

Junio C Hamano <gitster@pobox.com> writes:

> Stefan Beller <sbeller@google.com> writes:
>
>> +static int module_list_compute(int argc, const char **argv,
>> +				const char *prefix,
>> +				struct pathspec *pathspec)
>> +{
>> ...
>> +	for (i = 0; i < active_nr; i++) {
>> +		const struct cache_entry *ce = active_cache[i];
>> +
>> +		if (!match_pathspec(pathspec, ce->name, ce_namelen(ce),
>> +				    max_prefix_len, ps_matched,
>> +				    S_ISGITLINK(ce->ce_mode) | S_ISDIR(ce->ce_mode)))
>> +			continue;

Another minor thing I noticed here is that ce->ce_mode would never
be S_ISDIR().

It is not immediately clear if it is necessary to pass is_dir=true
upon S_ISGITLINK(ce->ce_mode) to match_pathspec(), but I think that
is probably a right thing to do.  The only difference this makes, I
think, is when a pathspec ends with a slash.  E.g. when you have a
submodule at path ce->ce_name == "dir" and the caller says "dir/".
Then DO_MATCH_DIRECTORY logic would say "dir/" does match "dir".

So taken together with the remainder of the loop, perhaps

        for (i = 0; i < active_nr; i++) {
                ce = active_cache[i];

                if (!S_ISGITLINK(ce->ce_mode) ||
                    !match_pathspec(..., is_dir=1))
                        continue;

                ALLOC_GROW(ce_entries, ce_nr + 1, ce_alloc);
                ce_entries[ce_nr++] = ce;
                while (...)
                        skip the entries with the same name;
        }

would be what we want.  Pathspec matching is much more expensive
than ce_mode check, and after passing that check, you know the last
parameter to the match_pathspec() at that point, so the above
structure would also make sense from performance point of view, I
think.  And of course, the structure makes it clear that we only
care about GITLINK entries and nothing else in this loop, so it is
good from readability point of view, too.

  reply	other threads:[~2015-09-02  7:21 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-01 18:24 [PATCHv4 0/3] submodule--helper: Have some refactoring only patches first Stefan Beller
2015-09-01 18:24 ` [PATCHv4 1/3] submodule: implement `list` as a builtin helper Stefan Beller
2015-09-01 19:55   ` Junio C Hamano
2015-09-02  7:20     ` Junio C Hamano [this message]
2015-09-01 23:17   ` Eric Sunshine
2015-09-01 18:24 ` [PATCHv4 2/3] submodule: implement `name` " Stefan Beller
2015-09-01 19:01   ` Eric Sunshine
2015-09-01 18:24 ` [PATCHv4 3/3] submodule: implement `clone` " Stefan Beller
2015-09-01 18:52   ` Eric Sunshine
2015-09-01 19:05     ` Jeff King
2015-09-01 19:15       ` Eric Sunshine
2015-09-01 19:13     ` Junio C Hamano
     [not found] <1441148863-9139-1-git-send-email-sbeller@google.com>
2015-09-01 23:07 ` [PATCHv4 1/3] submodule: implement `list` " Stefan Beller
2015-09-01 23:08   ` Stefan Beller

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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=xmqqk2s9p9rb.fsf@gitster.mtv.corp.google.com \
    --to=gitster@pobox.com \
    --cc=Jens.Lehmann@web.de \
    --cc=git@vger.kernel.org \
    --cc=johannes.schindelin@gmail.com \
    --cc=jrnieder@gmail.com \
    --cc=peff@peff.net \
    --cc=sbeller@google.com \
    --cc=sunshine@sunshineco.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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).