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

Re: [PATCH 5/5] submodule: fixup nested submodules after moving the submodule

From
Stefan Beller <sbeller@google.com>
Date
Mar 28, 2018, 00:42 UTC
Message-ID
<CAGZ79kaQYjepND8EdgB73meBsShOc5aBporiK2Bo40fqcar0gg@mail.gmail.com>
In-Reply-To
<20180327170714.81b37f84cb4c544d76f34701@google.com>
On Tue, Mar 27, 2018 at 5:07 PM, Jonathan Tan <jonathantanmy@google.com> wrote:
> s/submoduled/submodules
> s/superprojects/superproject's/
> s/and //
>
> s/force/forcing/
All wording fixed.
Show 13 quoted lines
>> +     sub_path = sub_worktree + strlen(super_worktree) + 1;
>> +
>> +     if (repo_submodule_init(&subrepo, superproject, sub_path))
>> +             return;
>> +
>> +     repo_read_index(&subrepo);
>
> From the name of this function and its usage in
> connect_work_tree_and_git_dir(), I expected this function to just
> iterate through all the files in its workdir (which it is doing in the
> "for" loop below) and connect any nested submodules. Why does it need
> access to its superproject? (I would think that repo_init() would be
> sufficient here instead of repo_submodule_init().)
Testing validates your thinking (for now).

If we ever want to have good error reporting (see bmwills hint to check for index corruption), we may want to have all the repos constructed as submodules from the_repository, as then the error messages might be better (e.g. in the future we could display the "submodule nesting stack").

I'll remove the superproject argument for now.
Show 15 quoted lines
>> +
>> +             strbuf_reset(&sub_wt);
>> +             strbuf_addf(&sub_wt, "%s/%s/.git", sub_worktree, sub->path);
>> +
>> +             strbuf_reset(&sub_gd);
>> +             strbuf_addf(&sub_gd, "%s/modules/%s", sub_gitdir, sub->name);
>> +
>> +             strbuf_setlen(&sub_wt, sub_wt.len - strlen("/.git"));
>> +
>> +             if (is_submodule_active(&subrepo, ce->name)) {
>> +                     connect_work_tree_and_git_dir(sub_wt.buf, sub_gd.buf, 0);
>> +                     connect_wt_gitdir_in_nested(sub_wt.buf, sub_gd.buf, &subrepo);
>
> The modifications of sub_wt and sub_gd should probably go here, since
> they are not used unless this "if" block is executed.

Thanks! I also cut out the setlen call by giving the correct format string. (The code presented here is not very old, I just fired it off as soon as the test passed)

Show 13 quoted lines
>
>> +void connect_work_tree_and_git_dir(const char *work_tree_,
>> +                                const char *git_dir_,
>> +                                int recurse_into_nested)
>
> How is this function expected to be used? From what I see:
>  - if recurse_into_nested is 0, this works regardless of whether the
>    work_tree_ and git_dir_ is directly or indirectly a submodule of
>    the_repository
>  - if recurse_into_nested is 1, work_tree_ and git_dir_ must be directly
>    a submodule of the_repository (since it is referenced directly)
>
> This seems confusing - is this expected?

In the next revision of the series connect_wt_gitdir_in_nested will no longer have a third argument for the repo, as we use repo_init.

That eases the handling a bit here.
Previous: Jonathan TanNext: Stefan Beller
Message 15 of 36 in “Moving submodules with nested submodules”
  1. 0/5 Moving submodules with nested submodulesStefan Beller, Mar 27, 2018
  2. 1/5 submodule.h: drop declaration of connect_work_tree_and_git_dirStefan Beller, Mar 27, 2018
  3. 3/5 submodule-config: add repository argument to submodule_from_{name, path}Stefan Beller, Mar 27, 2018
  4. Jonathan TanMar 27, 2018
  5. Stefan BellerMar 27, 2018
  6. 2/5 submodule-config: allow submodule_free to handle arbitrary repositoriesStefan Beller, Mar 27, 2018
  7. Brandon WilliamsMar 27, 2018
  8. grep: remove "repo" arg from non-supporting funcsJonathan Tan, Mar 27, 2018
  9. Stefan BellerMar 27, 2018
  10. Jonathan TanMar 28, 2018
  11. Stefan BellerMar 28, 2018
  12. 5/5 submodule: fixup nested submodules after moving the submoduleStefan Beller, Mar 27, 2018
  13. Brandon WilliamsMar 27, 2018
  14. Jonathan TanMar 28, 2018
  15. Stefan BellerMar 28, 2018
  16. 0/6 Moving submodules with nested submodulesStefan Beller, Mar 28, 2018
  17. 1/6 submodule.h: drop declaration of connect_work_tree_and_git_dirStefan Beller, Mar 28, 2018
  18. 2/6 submodule-config: allow submodule_free to handle arbitrary repositoriesStefan Beller, Mar 28, 2018
  19. 4/6 submodule-config: remove submodule_from_cacheStefan Beller, Mar 28, 2018
  20. 5/6 submodule: fixup nested submodules after moving the submoduleStefan Beller, Mar 28, 2018
  21. Brandon WilliamsMar 28, 2018
  22. Stefan BellerMar 28, 2018
  23. Jonathan TanMar 28, 2018
  24. 3/6 submodule-config: add repository argument to submodule_from_{name, path}Stefan Beller, Mar 28, 2018
  25. 6/6 grep: remove "repo" arg from non-supporting funcsStefan Beller, Mar 28, 2018
  26. Jonathan TanMar 28, 2018
  27. 0/6 Moving submodules with nested submodulesStefan Beller, Mar 28, 2018
  28. 1/6 submodule.h: drop declaration of connect_work_tree_and_git_dirStefan Beller, Mar 28, 2018
  29. 2/6 grep: remove "repo" arg from non-supporting funcsStefan Beller, Mar 28, 2018
  30. 3/6 submodule-config: allow submodule_free to handle arbitrary repositoriesStefan Beller, Mar 28, 2018
  31. 6/6 submodule: fixup nested submodules after moving the submoduleStefan Beller, Mar 28, 2018
  32. 4/6 submodule-config: add repository argument to submodule_from_{name, path}Stefan Beller, Mar 28, 2018
  33. 5/6 submodule-config: remove submodule_from_cacheStefan Beller, Mar 28, 2018
  34. Jonathan TanMar 28, 2018
  35. 4/5 submodule-config: remove submodule_from_cacheStefan Beller, Mar 27, 2018
  36. Jonathan TanMar 27, 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.