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

Re: [PATCH 1/2] submodule.c: add has_submodules to check if we have any submodules

From
BWBrandon Williams <bmwill@google.com>
Date
Apr 20, 2017, 22:25 UTC
Message-ID
<20170420222510.GL142567@google.com>
In-Reply-To
<CAGZ79kZeJp3nvjSJGy7P_dojjNbFtx3N11AOkGc-fdKkBOPFUg@mail.gmail.com>
On 04/20, Stefan Beller wrote:
Show 42 quoted lines
> 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.
Fair enough, I'm fine with the ordering then.
Show 9 quoted lines
> 
> > 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)

This is why I went back on my thinking :) I realized that it really depends on the scenario you are in.

Show 11 quoted lines
> 
> >  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
-- 
Brandon Williams
Previous: Stefan BellerNext: Stefan Beller
Message 5 of 9 in “clone: record submodule alternates when not recursing”
  1. 0/2 clone: record submodule alternates when not recursingStefan Beller, Apr 11, 2017
  2. 1/2 submodule.c: add has_submodules to check if we have any submodulesStefan Beller, Apr 11, 2017
  3. Brandon WilliamsApr 20, 2017
  4. Stefan BellerApr 20, 2017
  5. Brandon WilliamsApr 20, 2017
  6. 2/2 clone: remember references for submodules even when not recursingStefan Beller, Apr 11, 2017
  7. Brandon WilliamsApr 20, 2017
  8. Stefan BellerApr 20, 2017
  9. Stefan BellerApr 19, 2017

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.