git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Stefan Beller <sbeller@google.com>
To: Brandon Williams <bmwill@google.com>
Cc: Maxime Viargues <maxime.viargues@serato.com>,
	"git@vger.kernel.org" <git@vger.kernel.org>
Subject: Re: [PATCH 1/2] submodule.c: add has_submodules to check if we have any submodules
Date: Thu, 20 Apr 2017 15:20:48 -0700	[thread overview]
Message-ID: <CAGZ79kZeJp3nvjSJGy7P_dojjNbFtx3N11AOkGc-fdKkBOPFUg@mail.gmail.com> (raw)
In-Reply-To: <20170420220736.GH142567@google.com>

On Thu, Apr 20, 2017 at 3:07 PM, Brandon Williams <bmwill@google.com> wrote:
> On 04/11, Stefan Beller wrote:
>> +int has_submodules(unsigned what_to_check)
>> +{
>> +     if (what_to_check & SUBMODULE_CHECK_ANY_CONFIG) {
>> +             if (submodule_config_reading == SUBMODULE_CONFIG_NOT_READ)
>> +                     load_submodule_config();
>> +             if (submodule_config_reading == SUBMODULE_CONFIG_EXISTS)
>> +                     return 1;
>> +     }
>> +
>> +     if ((what_to_check & SUBMODULE_CHECK_ABSORBED_GIT_DIRS) &&
>> +         file_exists(git_path("modules")))
>> +             return 1;
>> +
>> +     if ((what_to_check & SUBMODULE_CHECK_GITMODULES_IN_WT) &&
>> +         (!is_bare_repository() && file_exists(".gitmodules")))
>> +             return 1;
>> +
>> +     if (what_to_check & SUBMODULE_CHECK_GITLINKS_IN_TREE) {
>> +             int i;
>> +
>> +             if (read_cache() < 0)
>> +                     die(_("index file corrupt"));
>> +
>> +             for (i = 0; i < active_nr; i++)
>> +                     if (S_ISGITLINK(active_cache[i]->ce_mode))
>> +                             return 1;
>> +     }
>> +
>> +     return 0;
>> +}
>
> It may be a good idea to rearrange these by order to correctness.

I arranged by estimated speed, i.e. from fastest to slowest:
* The first check just returns a value from memory in the standard case
  Though the first one may take a hit in performance for the very first time
  as it may need to load the config.
* The next two are an actual stat system call, each having a different
  'defect'. (We may have non-absorbed submodules or non-bare repos)
  -> We could have a check for in-tree as well, not sure if that is desired.

> Correctness may not be the best way to describe it, but which is the
> strongest indicator that there is a submodule or that a repo 'has a
> submodule'.

These indicators differ in strength for different scenarios IMO.
(Just after clone: check for a .gitmodules file instead of a config;
later: rather check for a config as it is fastest and actually catches
active submodules; maybe we do not care about inactive submodules)

>  That way in the future we could have a #define that is
> SUBMODULE_CHECK_ANY or ALL or something....Now that I'm thinking harder
> about that we may not want that, and just require explicitly stating
> which check you want done.
>
> Anyways good looking patch, and I like the idea of consolidating the
> checks into a single function.

Thanks,
Stefan

  reply	other threads:[~2017-04-20 22:20 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-11 19:46 [PATCH 0/2] clone: record submodule alternates when not recursing Stefan Beller
2017-04-11 19:46 ` [PATCH 1/2] submodule.c: add has_submodules to check if we have any submodules Stefan Beller
2017-04-20 22:07   ` Brandon Williams
2017-04-20 22:20     ` Stefan Beller [this message]
2017-04-20 22:25       ` Brandon Williams
2017-04-11 19:46 ` [PATCH 2/2] clone: remember references for submodules even when not recursing Stefan Beller
2017-04-20 22:12   ` Brandon Williams
2017-04-20 22:28     ` Stefan Beller
2017-04-19 19:52 ` [PATCH 0/2] clone: record submodule alternates " 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=CAGZ79kZeJp3nvjSJGy7P_dojjNbFtx3N11AOkGc-fdKkBOPFUg@mail.gmail.com \
    --to=sbeller@google.com \
    --cc=bmwill@google.com \
    --cc=git@vger.kernel.org \
    --cc=maxime.viargues@serato.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).