{"thread":{"id":"44647","subject":"[PATCH 1/2] submodule--helper: set alternateLocation for cloned submodules","startedAt":"2016-12-07T22:50:21Z","lastAt":"2016-12-08T00:02:46Z","messageCount":3,"participants":["vi0oss@gmail.com","Stefan Beller"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"307189","messageId":"20161207224948.7957-1-vi0oss@gmail.com","threadId":"44647","inReplyTo":null,"subject":"[PATCH 1/2] submodule--helper: set alternateLocation for cloned submodules","fromName":"","fromEmail":"vi0oss@gmail.com","sentAt":"2016-12-07T22:49:47Z","receivedAt":"2016-12-07T22:50:21Z","isPatch":true,"sender":{"key":"vi0oss@gmail.com","avatar":"https://avatars.githubusercontent.com/u/173219?v=4"},"body":"From: \"Vitaly \\\"_Vi\\\" Shukela\" <vi0oss@gmail.com>\n\nIn 31224cbdc7 (clone: recursive and reference option triggers\nsubmodule alternates, 2016-08-17) a mechanism was added to\nhave submodules referenced.  It did not address _nested_\nsubmodules, however.\n\nThis patch makes all not just the root repository, but also\nall submodules (recursively) have submodule.alternateLocation\nand submodule.alternateErrorStrategy configured, making Git\nsearch for possible alternates for nested submodules as well.\n\nAs submodule's alternate target does not end in .git/objects\n(rather .git/modules/qqqqqq/objects), this alternate target\npath restriction for in add_possible_reference_from_superproject\nrelates from \"*.git/objects\" to just */objects\".\n\nNew tests have been added to t7408-submodule-reference.\n\nSigned-off-by: Vitaly _Vi Shukela <vi0oss@gmail.com>\n---\n\nNotes:\n    Resolved issues pointed by Stefan Beller except of\n    the one about loosened path check, which he aggreed\n    to be relaxed for this case.\n\n builtin/submodule--helper.c    | 21 ++++++++++--\n t/t7408-submodule-reference.sh | 72 ++++++++++++++++++++++++++++++++++++++++++\n 2 files changed, 91 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c\nindex 4beeda5..7b7633d 100644\n--- a/builtin/submodule--helper.c\n+++ b/builtin/submodule--helper.c\n@@ -498,9 +498,9 @@ static int add_possible_reference_from_superproject(\n \n \t/*\n \t * If the alternate object store is another repository, try the\n-\t * standard layout with .git/modules/<name>/objects\n+\t * standard layout with .git/(modules/<name>)+/objects\n \t */\n-\tif (ends_with(alt->path, \".git/objects\")) {\n+\tif (ends_with(alt->path, \"/objects\")) {\n \t\tchar *sm_alternate;\n \t\tstruct strbuf sb = STRBUF_INIT;\n \t\tstruct strbuf err = STRBUF_INIT;\n@@ -583,6 +583,7 @@ static int module_clone(int argc, const char **argv, const char *prefix)\n \tstruct strbuf rel_path = STRBUF_INIT;\n \tstruct strbuf sb = STRBUF_INIT;\n \tstruct string_list reference = STRING_LIST_INIT_NODUP;\n+\tchar *sm_alternate = NULL, *error_strategy = NULL;\n \n \tstruct option module_clone_options[] = {\n \t\tOPT_STRING(0, \"prefix\", &prefix,\n@@ -672,6 +673,22 @@ static int module_clone(int argc, const char **argv, const char *prefix)\n \t\tdie(_(\"could not get submodule directory for '%s'\"), path);\n \tgit_config_set_in_file(p, \"core.worktree\",\n \t\t\t       relative_path(path, sm_gitdir, &rel_path));\n+\n+\t/* setup alternateLocation and alternateErrorStrategy in the cloned submodule if needed */\n+\tgit_config_get_string(\"submodule.alternateLocation\", &sm_alternate);\n+\tif (sm_alternate) {\n+\t\tgit_config_set_in_file(p, \"submodule.alternateLocation\",\n+\t\t\t\t\t   sm_alternate);\n+\t}\n+\tgit_config_get_string(\"submodule.alternateErrorStrategy\", &error_strategy);\n+\tif (error_strategy) {\n+\t\tgit_config_set_in_file(p, \"submodule.alternateErrorStrategy\",\n+\t\t\t\t\t   error_strategy);\n+\t}\n+\n+\t\tfree(sm_alternate);\n+\t\tfree(error_strategy);\n+\n \tstrbuf_release(&sb);\n \tstrbuf_release(&rel_path);\n \tfree(sm_gitdir);\ndiff --git a/t/t7408-submodule-reference.sh b/t/t7408-submodule-reference.sh\nindex 1c1e289..ef7771b 100755\n--- a/t/t7408-submodule-reference.sh\n+++ b/t/t7408-submodule-reference.sh\n@@ -125,4 +125,76 @@ test_expect_success 'ignoring missing submodule alternates passes clone and subm\n \t)\n '\n \n+test_expect_success 'preparing second superproject with a nested submodule' '\n+\ttest_create_repo supersuper &&\n+\t(\n+\t\tcd supersuper &&\n+\t\techo \"I am super super.\" >file &&\n+\t\tgit add file &&\n+\t\tgit commit -m B-super-super-initial\n+\t\tgit submodule add \"file://$base_dir/super\" subwithsub &&\n+\t\tgit commit -m B-super-super-added &&\n+\t\tgit submodule update --init --recursive &&\n+\t\tgit repack -ad\n+\t)\n+'\n+\n+# At this point there are three root-level positories: A, B, super and super2\n+\n+test_expect_success 'nested submodule alternate in works and is actually used' '\n+\ttest_when_finished \"rm -rf supersuper-clone\" &&\n+\tgit clone --recursive --reference supersuper supersuper supersuper-clone &&\n+\t(\n+\t\tcd supersuper-clone &&\n+\t\t# test superproject has alternates setup correctly\n+\t\ttest_alternate_is_used .git/objects/info/alternates . &&\n+\t\t# immediate submodule has alternate:\n+\t\ttest_alternate_is_used .git/modules/subwithsub/objects/info/alternates subwithsub\n+\t\t# nested submodule also has alternate:\n+\t\ttest_alternate_is_used .git/modules/subwithsub/modules/sub/objects/info/alternates subwithsub/sub\n+\t)\n+'\n+\n+test_expect_success 'missing nested submodule alternate fails clone and submodule update' '\n+\ttest_when_finished \"rm -rf supersuper-clone supersuper2\" &&\n+\tgit clone supersuper supersuper2 &&\n+\t(\n+\t\tcd supersuper2 &&\n+\t\tgit submodule update --init\n+\t) &&\n+\ttest_must_fail git clone --recursive --reference supersuper2 supersuper2 supersuper-clone &&\n+\t(\n+\t\tcd supersuper-clone &&\n+\t\t# test superproject has alternates setup correctly\n+\t\ttest_alternate_is_used .git/objects/info/alternates . &&\n+\t\t# update of the submodule fails\n+\t\ttest_must_fail git submodule update --init --recursive &&\n+\t\t# immediate submodule has alternate:\n+\t\ttest_alternate_is_used .git/modules/subwithsub/objects/info/alternates subwithsub\n+\t\t# but nested submodule has no alternate:\n+\t\ttest_must_fail test_alternate_is_used .git/modules/subwithsub/modules/sub/objects/info/alternates subwithsub/sub\n+\t)\n+'\n+\n+test_expect_success 'missing nested submodule alternate in --reference-if-able mode' '\n+\ttest_when_finished \"rm -rf supersuper-clone supersuper2\" &&\n+\tgit clone supersuper supersuper2 &&\n+\t(\n+\t\tcd supersuper2 &&\n+\t\tgit submodule update --init\n+\t) &&\n+\tgit clone --recursive --reference-if-able supersuper2 supersuper2 supersuper-clone &&\n+\t(\n+\t\tcd supersuper-clone &&\n+\t\t# test superproject has alternates setup correctly\n+\t\ttest_alternate_is_used .git/objects/info/alternates . &&\n+\t\t# update of the submodule fails\n+\t\ttest_must_fail git submodule update --init --recursive &&\n+\t\t# immediate submodule has alternate:\n+\t\ttest_alternate_is_used .git/modules/subwithsub/objects/info/alternates subwithsub\n+\t\t# but nested submodule has no alternate:\n+\t\ttest_must_fail test_alternate_is_used .git/modules/subwithsub/modules/sub/objects/info/alternates subwithsub/sub\n+\t)\n+'\n+\n test_done\n-- \n2.10.2\n\n"},{"id":"307190","messageId":"20161207224948.7957-2-vi0oss@gmail.com","threadId":"44647","inReplyTo":"20161207224948.7957-1-vi0oss@gmail.com","subject":"[PATCH 2/2] mailmap: Update my e-mail address","fromName":"","fromEmail":"vi0oss@gmail.com","sentAt":"2016-12-07T22:49:48Z","receivedAt":"2016-12-07T22:50:33Z","isPatch":true,"sender":{"key":"vi0oss@gmail.com","avatar":"https://avatars.githubusercontent.com/u/173219?v=4"},"body":"From: \"Vitaly \\\"_Vi\\\" Shukela\" <vi0oss@gmail.com>\n\nSigned-off-by: Vitaly \"_Vi\" Shukela <vi0oss@gmail.com>\n---\n .mailmap | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/.mailmap b/.mailmap\nindex 9cc33e9..b7ae81a 100644\n--- a/.mailmap\n+++ b/.mailmap\n@@ -246,7 +246,7 @@ Uwe Kleine-König <u.kleine-koenig@pengutronix.de> <ukleinek@informatik.uni-frei\n Uwe Kleine-König <u.kleine-koenig@pengutronix.de> <uzeisberger@io.fsforth.de>\n Uwe Kleine-König <u.kleine-koenig@pengutronix.de> <zeisberg@informatik.uni-freiburg.de>\n Ville Skyttä <ville.skytta@iki.fi> <scop@xemacs.org>\n-Vitaly \"_Vi\" Shukela <public_vi@tut.by>\n+Vitaly \"_Vi\" Shukela <vi0oss@gmail.com> <public_vi@tut.by>\n W. Trevor King <wking@tremily.us> <wking@drexel.edu>\n William Pursell <bill.pursell@gmail.com>\n YONETANI Tomokazu <y0n3t4n1@gmail.com> <qhwt+git@les.ath.cx>\n-- \n2.10.2\n\n"},{"id":"307201","messageId":"CAGZ79kaSVcf1zk4P1hWsU=aJG7G99qohhavBftmPxnrkjW+nfQ@mail.gmail.com","threadId":"44647","inReplyTo":"20161207224948.7957-1-vi0oss@gmail.com","subject":"Re: [PATCH 1/2] submodule--helper: set alternateLocation for cloned submodules","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2016-12-08T00:02:41Z","receivedAt":"2016-12-08T00:02:46Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"On Wed, Dec 7, 2016 at 2:49 PM,  <vi0oss@gmail.com> wrote:\n> Notes:\n>     Resolved issues pointed by Stefan Beller except of\n>     the one about loosened path check, which he aggreed\n>     to be relaxed for this case.\n\nI am sorry to have given an incomplete review at the first time. :/\nMore below.\n\n> +       /* setup alternateLocation and alternateErrorStrategy in the cloned submodule if needed */\n> +       git_config_get_string(\"submodule.alternateLocation\", &sm_alternate);\n> +       if (sm_alternate) {\n> +               git_config_set_in_file(p, \"submodule.alternateLocation\",\n> +                                          sm_alternate);\n> +       }\n\nFor a single command, we usually omit the braces for\nan if clause, i.e.\n\n    if (foo)\n        bar(...);\n\n    /* code goes on */\n\n\n> +       git_config_get_string(\"submodule.alternateErrorStrategy\", &error_strategy);\n> +       if (error_strategy) {\n> +               git_config_set_in_file(p, \"submodule.alternateErrorStrategy\",\n> +                                          error_strategy);\n> +       }\n> +\n> +               free(sm_alternate);\n> +               free(error_strategy);\n> +\n\nThe indentation seems a bit off for the free here?\n(The main nit that motivated me writing the email)\n\n\n>         strbuf_release(&sb);\n>         strbuf_release(&rel_path);\n>         free(sm_gitdir);\n> diff --git a/t/t7408-submodule-reference.sh b/t/t7408-submodule-reference.sh\n> index 1c1e289..ef7771b 100755\n> --- a/t/t7408-submodule-reference.sh\n> +++ b/t/t7408-submodule-reference.sh\n> @@ -125,4 +125,76 @@ test_expect_success 'ignoring missing submodule alternates passes clone and subm\n>         )\n>  '\n>\n> +test_expect_success 'preparing second superproject with a nested submodule' '\n> +       test_create_repo supersuper &&\n> +       (\n> +               cd supersuper &&\n> +               echo \"I am super super.\" >file &&\n> +               git add file &&\n> +               git commit -m B-super-super-initial\n> +               git submodule add \"file://$base_dir/super\" subwithsub &&\n> +               git commit -m B-super-super-added &&\n> +               git submodule update --init --recursive &&\n> +               git repack -ad\n> +       )\n> +'\n> +\n> +# At this point there are three root-level positories: A, B, super and super2\n> +\n> +test_expect_success 'nested submodule alternate in works and is actually used' '\n> +       test_when_finished \"rm -rf supersuper-clone\" &&\n> +       git clone --recursive --reference supersuper supersuper supersuper-clone &&\n> +       (\n> +               cd supersuper-clone &&\n> +               # test superproject has alternates setup correctly\n> +               test_alternate_is_used .git/objects/info/alternates . &&\n> +               # immediate submodule has alternate:\n> +               test_alternate_is_used .git/modules/subwithsub/objects/info/alternates subwithsub\n> +               # nested submodule also has alternate:\n> +               test_alternate_is_used .git/modules/subwithsub/modules/sub/objects/info/alternates subwithsub/sub\n> +       )\n> +'\n> +\n> +test_expect_success 'missing nested submodule alternate fails clone and submodule update' '\n> +       test_when_finished \"rm -rf supersuper-clone supersuper2\" &&\n> +       git clone supersuper supersuper2 &&\n> +       (\n> +               cd supersuper2 &&\n> +               git submodule update --init\n> +       ) &&\n> +       test_must_fail git clone --recursive --reference supersuper2 supersuper2 supersuper-clone &&\n> +       (\n> +               cd supersuper-clone &&\n> +               # test superproject has alternates setup correctly\n> +               test_alternate_is_used .git/objects/info/alternates . &&\n> +               # update of the submodule fails\n> +               test_must_fail git submodule update --init --recursive &&\n> +               # immediate submodule has alternate:\n> +               test_alternate_is_used .git/modules/subwithsub/objects/info/alternates subwithsub\n> +               # but nested submodule has no alternate:\n> +               test_must_fail test_alternate_is_used .git/modules/subwithsub/modules/sub/objects/info/alternates subwithsub/sub\n> +       )\n> +'\n> +\n> +test_expect_success 'missing nested submodule alternate in --reference-if-able mode' '\n> +       test_when_finished \"rm -rf supersuper-clone supersuper2\" &&\n> +       git clone supersuper supersuper2 &&\n> +       (\n> +               cd supersuper2 &&\n> +               git submodule update --init\n> +       ) &&\n> +       git clone --recursive --reference-if-able supersuper2 supersuper2 supersuper-clone &&\n> +       (\n> +               cd supersuper-clone &&\n> +               # test superproject has alternates setup correctly\n> +               test_alternate_is_used .git/objects/info/alternates . &&\n> +               # update of the submodule fails\n> +               test_must_fail git submodule update --init --recursive &&\n> +               # immediate submodule has alternate:\n> +               test_alternate_is_used .git/modules/subwithsub/objects/info/alternates subwithsub\n> +               # but nested submodule has no alternate:\n> +               test_must_fail test_alternate_is_used .git/modules/subwithsub/modules/sub/objects/info/alternates subwithsub/sub\n> +       )\n\nBoth the first and the last part are the same in the last two tests,\nthe only difference is the line with git clone --reference ...\nMaybe we can use a function somehow to make this a bit more\nobvious?\n\nOtherwise the tests look good to me.\n\nThanks,\nStefan\n"}]}