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

Re: [PATCH 3/7] submodule: is_submodule_active to differentiate between new and old mode

From
Stefan Beller <sbeller@google.com>
Date
Aug 20, 2018, 19:50 UTC
Message-ID
<CAGZ79kb-_7PTqe_9i4=FQQE7EmQsKN8+iB4snLetPD+r2UgpBQ@mail.gmail.com>
In-Reply-To
<xmqq600afc1e.fsf@gitster-ct.c.googlers.com>
On Thu, Aug 16, 2018 at 10:37 AM Junio C Hamano <gitster@pobox.com> wrote:
Show 80 quoted lines
>
> Stefan Beller <sbeller@google.com> writes:
>
> > The change a086f921a72 (submodule: decouple url and submodule interest,
> > 2017-03-17) enables us to do more than originally thought.
> > As the url setting was used both to actually set the url where to
> > obtain the submodule from, as well as used as a boolean flag later
> > to see if it was active, we would need to keep the url around.
> >
> > Now that submodules can be activated using the submodule.[<name>.]active
> > setting, we could remove the url if the submodule is activated via that
> > setting.
>
> ... as the cloned submodule repository has $GIT_DIR/config which
> knows its own origin, we do not need to record URL in superproject's
> $GIT_DIR/config.  Back before we started using a directory under
> $GIT_DIR/modules/ as a more permanent location to store submodule,
> and point at it by a gitdir file in $path/.git to allow removal of a
> submodule from the working tree of the superproject without having
> to reclone when resurrecting the same submodule, it may have been
> useful to keep custom URL somewhere in the superproject, but that no
> longer is the case.
>
> > In preparation to do so, pave the way by providing an easy way to see
> > if a submodule is considered active via the new .active setting or via
> > the old .url setting.
>
> Makes sense.
>
> >
> > Signed-off-by: Stefan Beller <sbeller@google.com>
> > ---
> >  submodule.c | 5 +----
> >  submodule.h | 6 ++++++
> >  2 files changed, 7 insertions(+), 4 deletions(-)
> >
> > diff --git a/submodule.c b/submodule.c
> > index 6e14547e9e0..d56350ed094 100644
> > --- a/submodule.c
> > +++ b/submodule.c
> > @@ -221,9 +221,6 @@ int option_parse_recurse_submodules_worktree_updater(const struct option *opt,
> >       return 0;
> >  }
> >
> > -/*
> > - * Determine if a submodule has been initialized at a given 'path'
> > - */
> >  int is_submodule_active(struct repository *repo, const char *path)
> >  {
> >       int ret = 0;
> > @@ -267,7 +264,7 @@ int is_submodule_active(struct repository *repo, const char *path)
> >
> >       /* fallback to checking if the URL is set */
> >       key = xstrfmt("submodule.%s.url", module->name);
> > -     ret = !repo_config_get_string(repo, key, &value);
> > +     ret = !repo_config_get_string(repo, key, &value) ? 2 : 0;
> >
> >       free(value);
> >       free(key);
> > diff --git a/submodule.h b/submodule.h
> > index 4644683e6cb..bfc070e4629 100644
> > --- a/submodule.h
> > +++ b/submodule.h
> > @@ -45,6 +45,12 @@ extern int git_default_submodule_config(const char *var, const char *value, void
> >  struct option;
> >  int option_parse_recurse_submodules_worktree_updater(const struct option *opt,
> >                                                    const char *arg, int unset);
> > +/*
> > + * Determine if a submodule has been initialized at a given 'path'.
> > + * Returns 1 if it is considered active via the submodule.[<name>.]active
> > + * setting, or return 2 if it is active via the older submodule.url setting.
> > + */
> > +#define SUBMODULE_ACTIVE_VIA_URL 2
> >  extern int is_submodule_active(struct repository *repo, const char *path);
> >  /*
> >   * Determine if a submodule has been populated at a given 'path' by checking if
>
> This change assumes that all the existing return sites in the
> is_submodule_active() function signals true with 1 (or at least some
> value that is different from 2).
Yes.
Show 5 quoted lines
> So I think this patch is insufficient, and needs to at least change
> the "submodule.active" codepath to return !!ret; otherwise, a caller
> that now expects 0 (not active), 1 (active but can lose URL) and 2
> (active and the presence of URL makes it so) will be confused when
> one of the MATCHED_* constants from dir.h comes back.
Yes.
I'll resend when appropriately.

Thanks, Stefan

Previous: Junio C HamanoNext: Junio C Hamano
Message 7 of 14 in “Unset the submodule URL in the superproject when no longer needed”
  1. 0/7 Unset the submodule URL in the superproject when no longer neededStefan Beller, Aug 16, 2018
  2. 1/7 t7410: update to new styleStefan Beller, Aug 16, 2018
  3. Junio C HamanoAug 16, 2018
  4. 2/7 builtin/submodule--helper: remove stray new lineStefan Beller, Aug 16, 2018
  5. 3/7 submodule: is_submodule_active to differentiate between new and old modeStefan Beller, Aug 16, 2018
  6. Junio C HamanoAug 16, 2018
  7. Stefan BellerAug 20, 2018
  8. Junio C HamanoAug 21, 2018
  9. 4/7 submodule sync: omit setting submodule URL in config if possibleStefan Beller, Aug 16, 2018
  10. 5/7 submodule--helper: factor out allocation of callback cookieStefan Beller, Aug 16, 2018
  11. 6/7 submodule--helper, update_clone: store index to update_clone instead of ceStefan Beller, Aug 16, 2018
  12. 7/7 builtin/submodule--helper: unset submodule url if possibleStefan Beller, Aug 16, 2018
  13. Junio C HamanoAug 16, 2018
  14. Stefan BellerAug 16, 2018

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.