Re: [PATCH] submodule--helper: set alternateLocation for cloned submodules
- From
Stefan Beller <sbeller@google.com>
- Date
- Dec 7, 2016, 20:09 UTC
- Message-ID
- <CAGZ79kY3LR2KA69b4iDJb164EhJLb3JuVSRRcN0-4-kp-eryog@mail.gmail.com>
- In-Reply-To
- <20161207184248.6130-1-vi0oss@gmail.com>
On Wed, Dec 7, 2016 at 10:42 AM, <vi0oss@gmail.com> wrote:
> From: Vitaly _Vi Shukela <vi0oss@gmail.com>
Thanks for contributing to Git! (/me looks up if you have sent patches already as you seem to know how to do that. :) unrelated side note: Maybe you want to send a patch for the .mailmap file mapping your two email addresses together, c.f. "git log -- .mailmap")
> > Git v2.11 introduced "git clone --recursive --referece ...", > but it didn't put the alternates for _nested_ submodules.
This message is targeted at people familiar with gits code base, so we can be more specific. e.g.
In 31224cbdc7 (clone: recursive and reference option triggers
submodule alternates, 2016-08-17) a mechanism was added to
have submodules referenced. It did not address _nested_
submodules, however.Show 5 quoted lines
> > This patch makes all not just the root repository, but also > all submodules (recursively) have submodule.alternateLocation > and submodule.alternateErrorStrategy configured, making Git > search for possible alternates for nested submodules as well.
Sounds great!
Show 5 quoted lines
> > As submodule's alternate target does not end in .git/objects > (rather .git/modules/qqqqqq/objects), this alternate target > path restriction for in add_possible_reference_from_superproject > relates from "*.git/objects" to just */objects".
I wonder if this check is too weak and we actually have to check for either .git/objects or modules/<name/possibly/having/slashes>/objects. When writing the referenced commit I assumed we'd need a stronger check to be safer and not add some random location as a possible alternate.
> > New tests have been added to t7408-submodule-reference.
Thanks!
Show 30 quoted lines
>
> Signed-off-by: Vitaly _Vi Shukela <vi0oss@gmail.com>
> ---
> builtin/submodule--helper.c | 24 ++++++++++++--
> t/t7408-submodule-reference.sh | 73 ++++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 95 insertions(+), 2 deletions(-)
>
> diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
> index 4beeda5..93dae62 100644
> --- a/builtin/submodule--helper.c
> +++ b/builtin/submodule--helper.c
> @@ -498,9 +498,9 @@ static int add_possible_reference_from_superproject(
>
> /*
> * If the alternate object store is another repository, try the
> - * standard layout with .git/modules/<name>/objects
> + * standard layout with .git/(modules/<name>)+/objects
> */
> - if (ends_with(alt->path, ".git/objects")) {
> + if (ends_with(alt->path, "/objects")) {
> char *sm_alternate;
> struct strbuf sb = STRBUF_INIT;
> struct strbuf err = STRBUF_INIT;
> @@ -672,6 +672,26 @@ static int module_clone(int argc, const char **argv, const char *prefix)
> die(_("could not get submodule directory for '%s'"), path);
> git_config_set_in_file(p, "core.worktree",
> relative_path(path, sm_gitdir, &rel_path));
> +
> + /* setup alternateLocation and alternateErrorStrategy in the cloned submodule if needed */
> + {Usually we do not use braces to further nest code, please remove this nesting.
Show 33 quoted lines
> + char *sm_alternate = NULL, *error_strategy = NULL;
> +
> + git_config_get_string("submodule.alternateLocation", &sm_alternate);
> + if (sm_alternate) {
> + git_config_set_in_file(p, "submodule.alternateLocation",
> + sm_alternate);
> + }
> + git_config_get_string("submodule.alternateErrorStrategy", &error_strategy);
> + if (error_strategy) {
> + git_config_set_in_file(p, "submodule.alternateErrorStrategy",
> + error_strategy);
> + }
> +
> + free(sm_alternate);
> + free(error_strategy);
> + }
> +
> strbuf_release(&sb);
> strbuf_release(&rel_path);
> free(sm_gitdir);
> diff --git a/t/t7408-submodule-reference.sh b/t/t7408-submodule-reference.sh
> index 1c1e289..7b64725 100755
> --- a/t/t7408-submodule-reference.sh
> +++ b/t/t7408-submodule-reference.sh
> @@ -125,4 +125,77 @@ test_expect_success 'ignoring missing submodule alternates passes clone and subm
> )
> '
>
> +test_expect_success 'preparing second superproject with a nested submodule' '
> + test_create_repo supersuper &&
> + (
> + cd supersuper &&
> + echo I am super super. >file &&Usually we quote strings containing white space, e.g. echo "I am ..." >actual
Show 8 quoted lines
> + git add file && > + git commit -m B-super-super-initial > + git submodule add "file://$base_dir/super" subwithsub && > + git commit -m B-super-super-added && > + git submodule update --init --recursive && > + git repack -ad > + ) && > + echo not cleaning supersuper
This echo is left in for debugging purposes?