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

Re: BUG: submodule code prints '(null)'

From
Stefan Beller <sbeller@google.com>
Date
Jun 11, 2018, 22:56 UTC
Message-ID
<CAGZ79kZk=OGPJdsDEHtgmPUrO7P2rOLSV40aJawdLs5e0=Kduw@mail.gmail.com>
In-Reply-To
<20180609110414.GA5273@duynguyen.home>
On Sat, Jun 9, 2018 at 4:04 AM Duy Nguyen <pclouds@gmail.com> wrote:
Show 24 quoted lines
>
> On Tue, Jun 05, 2018 at 05:31:41PM +0200, Duy Nguyen wrote:
> > I do not know how to reproduce this (and didn't bother to look deeply
> > into it after I found it was not a trivial fix) but one of my "git
> > fetch" showed
> >
> > warning: Submodule in commit be2db96a6c506464525f588da59cade0cedddb5e
> > at path: '(null)' collides with a submodule named the same. Skipping
> > it.
>
> The problem is default_name_or_path() can return NULL when a submodule
> is not populated. The fix could simply be printing path instead of
> name (because we are talking about path in the commit message), like
> below.
>
> But I don't really understand c68f837576 (implement fetching of moved
> submodules - 2017-10-16), the commit that made this change, and not
> sure if we should be reporting name here or path. Heiko?
>
> diff --git a/submodule.c b/submodule.c
> index 939d6870ec..61c2177755 100644
> --- a/submodule.c
> +++ b/submodule.c
> @@ -745,7 +745,7 @@ static void collect_changed_submodules_cb(struct diff_queue_struct *q,

[Not in the context of this patch, but in the code right before the context starts:]

            name = default_name_or_path(p->two->path);
            /* make sure name does not collide with existing one */
            submodule = submodule_from_name(the_repository, commit_oid, name);
            if (submodule) {

Currently I see 4 callers of default_name_or_path and the other 3 except this one have checks against NULL in place, which is good. However I think we have to guard this even more, and have to check for !name before we call submodule_from_name.

It is technically ok to call submodule_from_name with a NULL name, but it is semantically broken, see the comment in config_from that is called from submodule_from_name:

    /*
     * If any parameter except the cache is a NULL pointer just
     * return the first submodule. Can be used to check whether
     * there are any submodules parsed.
     */
    if (!treeish_name || !key) {
        ...
Show 5 quoted lines
>                                 warning("Submodule in commit %s at path: "
>                                         "'%s' collides with a submodule named "
>                                         "the same. Skipping it.",
> -                                       oid_to_hex(commit_oid), name);
> +                                       oid_to_hex(commit_oid), p->two->path);

This is correct for the error message, both in terms of not crashing as well as correctness, we really need to report a *path* here and no the name_or_path, which default_name_or_path gives.

Previous: Duy NguyenNext: Heiko Voigt
Message 4 of 12 in “BUG: submodule code prints '(null)'”
  1. Duy NguyenJun 5, 2018
  2. Kaartic SivaraamJun 6, 2018
  3. Duy NguyenJun 9, 2018
  4. Stefan BellerJun 11, 2018
  5. Heiko VoigtJun 14, 2018
  6. Duy NguyenJun 14, 2018
  7. submodule: fix NULL correctness in renamed broken submodulesStefan Beller, Jun 14, 2018
  8. t5526: test recursive submodules when fetching moved submodulesStefan Beller, Jun 14, 2018
  9. Heiko VoigtJun 14, 2018
  10. Heiko VoigtJun 14, 2018
  11. Kaartic SivaraamJun 17, 2018
  12. Stefan BellerJun 12, 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.