{"thread":{"id":"42460","subject":"[PATCH 1/2] submodule-config: keep shallow recommendation around","startedAt":"2016-05-26T21:59:41Z","lastAt":"2016-05-26T21:59:43Z","messageCount":3,"participants":["Stefan Beller"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"287619","messageId":"20160526215943.29526-1-sbeller@google.com","threadId":"42460","inReplyTo":null,"subject":"[PATCHv3 0/2] Submodule shallow recommendation [WAS: Submodules: have a depth field in the .gitmodules file]","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2016-05-26T21:59:41Z","receivedAt":"2016-05-26T21:59:41Z","isPatch":false,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"v3:\n* fixed documentation to consistently mention recommend-shallow\n* realigned code in the config patch\n* Thanks Remi for reviewing! diff to v2:\n\ndiff --git a/Documentation/git-submodule.txt b/Documentation/git-submodule.txt\nindex c928c0d..bf3bb37 100644\n--- a/Documentation/git-submodule.txt\n+++ b/Documentation/git-submodule.txt\n@@ -15,7 +15,7 @@ SYNOPSIS\n 'git submodule' [--quiet] init [--] [<path>...]\n 'git submodule' [--quiet] deinit [-f|--force] (--all|[--] <path>...)\n 'git submodule' [--quiet] update [--init] [--remote] [-N|--no-fetch]\n-\t      [--[no-]recommended-depth] [-f|--force] [--rebase|--merge]\n+\t      [--[no-]recommend-shallow] [-f|--force] [--rebase|--merge]\n \t      [--reference <repository>] [--depth <depth>] [--recursive]\n \t      [--jobs <n>] [--] [<path>...]\n 'git submodule' [--quiet] summary [--cached|--files] [(-n|--summary-limit) <n>]\n@@ -385,10 +385,11 @@ for linkgit:git-clone[1]'s `--reference` and `--shared` options carefully.\n \tclone with a history truncated to the specified number of revisions.\n \tSee linkgit:git-clone[1]\n \n---[no-]recommended-depth::\n+--[no-]recommend-shallow::\n \tThis option is only valid for the update command.\n \tThe initial clone of a submodule will use the recommended\n-\t`submodule.<name>.depth` as provided by the .gitmodules file.\n+\t`submodule.<name>.shallow` as provided by the .gitmodules file\n+\tby default. To ignore the suggestions use `--no-recommend-shallow`.\n \n -j <n>::\n --jobs <n>::\ndiff --git a/submodule-config.c b/submodule-config.c\nindex e11b35d..db1847f 100644\n--- a/submodule-config.c\n+++ b/submodule-config.c\n@@ -355,8 +355,7 @@ static int parse_config(const char *var, const char *value, void *data)\n \t\t\t &submodule->update_strategy) < 0)\n \t\t\t\tdie(_(\"invalid value for %s\"), var);\n \t} else if (!strcmp(item.buf, \"shallow\")) {\n-\t\tif (!me->overwrite &&\n-\t\t\t submodule->recommend_shallow != -1)\n+\t\tif (!me->overwrite && submodule->recommend_shallow != -1)\n \t\t\twarn_multiple_config(me->commit_sha1, submodule->name,\n \t\t\t\t\t     \"shallow\");\n \t\telse {\n\n\nv2:\n* Instead of storing the depth, we keep a boolean `shallow` field in the\n  `.gitmodules` file.\n* slightly renamed options (--recommend-shallow instead of --recommended-depth)\n* one more test\n* I dropped [PATCH 1/3] submodule update: make use of the existing fetch_in_submodule function\n  as Junio picked it up separately as sb/submodule-misc-cleanups\n\nv1:\nSometimes the history of a submodule is not considered important by\nthe projects upstream. To make it easier for downstream users, allow\na field 'submodule.<name>.depth' in .gitmodules, which can be used\nto indicate the recommended depth.\n\nThanks,\nStefan\n\n\nStefan Beller (2):\n  submodule-config: keep shallow recommendation around\n  submodule update: learn `--[no-]recommend-shallow` option\n\n Documentation/git-submodule.txt | 11 +++++++--\n builtin/submodule--helper.c     |  7 +++++-\n git-submodule.sh                |  9 ++++++-\n submodule-config.c              |  9 +++++++\n submodule-config.h              |  1 +\n t/t5614-clone-submodules.sh     | 52 +++++++++++++++++++++++++++++++++++++++++\n 6 files changed, 85 insertions(+), 4 deletions(-)\n\n-- \n2.9.0.rc0.2.g145fc64\n\nbase-commit: 3a0f269e7c82aa3a87323cb7ae04ac5f129f036b\n"},{"id":"287617","messageId":"20160526215943.29526-2-sbeller@google.com","threadId":"42460","inReplyTo":"20160526215943.29526-1-sbeller@google.com","subject":"[PATCH 1/2] submodule-config: keep shallow recommendation around","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2016-05-26T21:59:42Z","receivedAt":"2016-05-26T21:59:42Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"The shallow field will be used in a later patch by `submodule update`.\nTo differentiate between the actual depth (which may be different),\nwe name it `recommend_shallow` as the field in the .gitmodules file\nis only a recommendation by the project.\n\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n submodule-config.c | 9 +++++++++\n submodule-config.h | 1 +\n 2 files changed, 10 insertions(+)\n\ndiff --git a/submodule-config.c b/submodule-config.c\nindex debab29..db1847f 100644\n--- a/submodule-config.c\n+++ b/submodule-config.c\n@@ -199,6 +199,7 @@ static struct submodule *lookup_or_create_by_name(struct submodule_cache *cache,\n \tsubmodule->update_strategy.command = NULL;\n \tsubmodule->fetch_recurse = RECURSE_SUBMODULES_NONE;\n \tsubmodule->ignore = NULL;\n+\tsubmodule->recommend_shallow = -1;\n \n \thashcpy(submodule->gitmodules_sha1, gitmodules_sha1);\n \n@@ -353,6 +354,14 @@ static int parse_config(const char *var, const char *value, void *data)\n \t\telse if (parse_submodule_update_strategy(value,\n \t\t\t &submodule->update_strategy) < 0)\n \t\t\t\tdie(_(\"invalid value for %s\"), var);\n+\t} else if (!strcmp(item.buf, \"shallow\")) {\n+\t\tif (!me->overwrite && submodule->recommend_shallow != -1)\n+\t\t\twarn_multiple_config(me->commit_sha1, submodule->name,\n+\t\t\t\t\t     \"shallow\");\n+\t\telse {\n+\t\t\tsubmodule->recommend_shallow =\n+\t\t\t\tgit_config_bool(var, value);\n+\t\t}\n \t}\n \n \tstrbuf_release(&name);\ndiff --git a/submodule-config.h b/submodule-config.h\nindex e4857f5..b1fdcc0 100644\n--- a/submodule-config.h\n+++ b/submodule-config.h\n@@ -18,6 +18,7 @@ struct submodule {\n \tstruct submodule_update_strategy update_strategy;\n \t/* the sha1 blob id of the responsible .gitmodules file */\n \tunsigned char gitmodules_sha1[20];\n+\tint recommend_shallow;\n };\n \n int parse_fetch_recurse_submodules_arg(const char *opt, const char *arg);\n-- \n2.9.0.rc0.2.g145fc64\n"},{"id":"287618","messageId":"20160526215943.29526-3-sbeller@google.com","threadId":"42460","inReplyTo":"20160526215943.29526-1-sbeller@google.com","subject":"[PATCH 2/2] submodule update: learn `--[no-]recommend-shallow` option","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2016-05-26T21:59:43Z","receivedAt":"2016-05-26T21:59:43Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Sometimes the history of a submodule is not considered important by\nthe projects upstream. To make it easier for downstream users, allow\na boolean field 'submodule.<name>.shallow' in .gitmodules, which can\nbe used to recommend whether upstream considers the history important.\n\nThis field is honored in the initial clone by default, it can be\nignored by giving the `--no-recommend-shallow` option.\n\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n Documentation/git-submodule.txt | 11 +++++++--\n builtin/submodule--helper.c     |  7 +++++-\n git-submodule.sh                |  9 ++++++-\n t/t5614-clone-submodules.sh     | 52 +++++++++++++++++++++++++++++++++++++++++\n 4 files changed, 75 insertions(+), 4 deletions(-)\n\ndiff --git a/Documentation/git-submodule.txt b/Documentation/git-submodule.txt\nindex 9226c43..bf3bb37 100644\n--- a/Documentation/git-submodule.txt\n+++ b/Documentation/git-submodule.txt\n@@ -15,8 +15,9 @@ SYNOPSIS\n 'git submodule' [--quiet] init [--] [<path>...]\n 'git submodule' [--quiet] deinit [-f|--force] (--all|[--] <path>...)\n 'git submodule' [--quiet] update [--init] [--remote] [-N|--no-fetch]\n-\t      [-f|--force] [--rebase|--merge] [--reference <repository>]\n-\t      [--depth <depth>] [--recursive] [--jobs <n>] [--] [<path>...]\n+\t      [--[no-]recommend-shallow] [-f|--force] [--rebase|--merge]\n+\t      [--reference <repository>] [--depth <depth>] [--recursive]\n+\t      [--jobs <n>] [--] [<path>...]\n 'git submodule' [--quiet] summary [--cached|--files] [(-n|--summary-limit) <n>]\n \t      [commit] [--] [<path>...]\n 'git submodule' [--quiet] foreach [--recursive] <command>\n@@ -384,6 +385,12 @@ for linkgit:git-clone[1]'s `--reference` and `--shared` options carefully.\n \tclone with a history truncated to the specified number of revisions.\n \tSee linkgit:git-clone[1]\n \n+--[no-]recommend-shallow::\n+\tThis option is only valid for the update command.\n+\tThe initial clone of a submodule will use the recommended\n+\t`submodule.<name>.shallow` as provided by the .gitmodules file\n+\tby default. To ignore the suggestions use `--no-recommend-shallow`.\n+\n -j <n>::\n --jobs <n>::\n \tThis option is only valid for the update command.\ndiff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c\nindex 8da263f..ca33408 100644\n--- a/builtin/submodule--helper.c\n+++ b/builtin/submodule--helper.c\n@@ -581,6 +581,7 @@ struct submodule_update_clone {\n \n \t/* configuration parameters which are passed on to the children */\n \tint quiet;\n+\tint recommend_shallow;\n \tconst char *reference;\n \tconst char *depth;\n \tconst char *recursive_prefix;\n@@ -593,7 +594,7 @@ struct submodule_update_clone {\n \tunsigned quickstop : 1;\n };\n #define SUBMODULE_UPDATE_CLONE_INIT {0, MODULE_LIST_INIT, 0, \\\n-\tSUBMODULE_UPDATE_STRATEGY_INIT, 0, NULL, NULL, NULL, NULL, \\\n+\tSUBMODULE_UPDATE_STRATEGY_INIT, 0, -1, NULL, NULL, NULL, NULL, \\\n \tSTRING_LIST_INIT_DUP, 0}\n \n \n@@ -698,6 +699,8 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,\n \t\targv_array_push(&child->args, \"--quiet\");\n \tif (suc->prefix)\n \t\targv_array_pushl(&child->args, \"--prefix\", suc->prefix, NULL);\n+\tif (suc->recommend_shallow && sub->recommend_shallow == 1)\n+\t\targv_array_push(&child->args, \"--depth=1\");\n \targv_array_pushl(&child->args, \"--path\", sub->path, NULL);\n \targv_array_pushl(&child->args, \"--name\", sub->name, NULL);\n \targv_array_pushl(&child->args, \"--url\", url, NULL);\n@@ -780,6 +783,8 @@ static int update_clone(int argc, const char **argv, const char *prefix)\n \t\t\t      \"specified number of revisions\")),\n \t\tOPT_INTEGER('j', \"jobs\", &max_jobs,\n \t\t\t    N_(\"parallel jobs\")),\n+\t\tOPT_BOOL(0, \"recommend-shallow\", &suc.recommend_shallow,\n+\t\t\t    N_(\"whether the initial clone should follow the shallow recommendation\")),\n \t\tOPT__QUIET(&suc.quiet, N_(\"don't print cloning progress\")),\n \t\tOPT_END()\n \t};\ndiff --git a/git-submodule.sh b/git-submodule.sh\nindex 5a4dec0..42e0e9f 100755\n--- a/git-submodule.sh\n+++ b/git-submodule.sh\n@@ -9,7 +9,7 @@ USAGE=\"[--quiet] add [-b <branch>] [-f|--force] [--name <name>] [--reference <re\n    or: $dashless [--quiet] status [--cached] [--recursive] [--] [<path>...]\n    or: $dashless [--quiet] init [--] [<path>...]\n    or: $dashless [--quiet] deinit [-f|--force] (--all| [--] <path>...)\n-   or: $dashless [--quiet] update [--init] [--remote] [-N|--no-fetch] [-f|--force] [--checkout|--merge|--rebase] [--reference <repository>] [--recursive] [--] [<path>...]\n+   or: $dashless [--quiet] update [--init] [--remote] [-N|--no-fetch] [-f|--force] [--checkout|--merge|--rebase] [--[no-]recommend-shallow] [--reference <repository>] [--recursive] [--] [<path>...]\n    or: $dashless [--quiet] summary [--cached|--files] [--summary-limit <n>] [commit] [--] [<path>...]\n    or: $dashless [--quiet] foreach [--recursive] <command>\n    or: $dashless [--quiet] sync [--recursive] [--] [<path>...]\"\n@@ -559,6 +559,12 @@ cmd_update()\n \t\t--checkout)\n \t\t\tupdate=\"checkout\"\n \t\t\t;;\n+\t\t--recommend-shallow)\n+\t\t\trecommend_shallow=\"--recommend-shallow\"\n+\t\t\t;;\n+\t\t--no-recommend-shallow)\n+\t\t\trecommend_shallow=\"--no-recommend-shallow\"\n+\t\t\t;;\n \t\t--depth)\n \t\t\tcase \"$2\" in '') usage ;; esac\n \t\t\tdepth=\"--depth=$2\"\n@@ -601,6 +607,7 @@ cmd_update()\n \t\t${update:+--update \"$update\"} \\\n \t\t${reference:+--reference \"$reference\"} \\\n \t\t${depth:+--depth \"$depth\"} \\\n+\t\t${recommend_shallow:+\"$recommend_shallow\"} \\\n \t\t${jobs:+$jobs} \\\n \t\t\"$@\" || echo \"#unmatched\"\n \t} | {\ndiff --git a/t/t5614-clone-submodules.sh b/t/t5614-clone-submodules.sh\nindex 62044c5..32d83e2 100755\n--- a/t/t5614-clone-submodules.sh\n+++ b/t/t5614-clone-submodules.sh\n@@ -82,4 +82,56 @@ test_expect_success 'non shallow clone with shallow submodule' '\n \t)\n '\n \n+test_expect_success 'clone follows shallow recommendation' '\n+\ttest_when_finished \"rm -rf super_clone\" &&\n+\tgit config -f .gitmodules submodule.sub.shallow true &&\n+\tgit add .gitmodules &&\n+\tgit commit -m \"recommed shallow for sub\" &&\n+\tgit clone --recurse-submodules --no-local \"file://$pwd/.\" super_clone &&\n+\t(\n+\t\tcd super_clone &&\n+\t\tgit log --oneline >lines &&\n+\t\ttest_line_count = 4 lines\n+\t) &&\n+\t(\n+\t\tcd super_clone/sub &&\n+\t\tgit log --oneline >lines &&\n+\t\ttest_line_count = 1 lines\n+\t)\n+'\n+\n+test_expect_success 'get unshallow recommended shallow submodule' '\n+\ttest_when_finished \"rm -rf super_clone\" &&\n+\tgit clone --no-local \"file://$pwd/.\" super_clone &&\n+\t(\n+\t\tcd super_clone &&\n+\t\tgit submodule update --init --no-recommend-shallow &&\n+\t\tgit log --oneline >lines &&\n+\t\ttest_line_count = 4 lines\n+\t) &&\n+\t(\n+\t\tcd super_clone/sub &&\n+\t\tgit log --oneline >lines &&\n+\t\ttest_line_count = 3 lines\n+\t)\n+'\n+\n+test_expect_success 'clone follows non shallow recommendation' '\n+\ttest_when_finished \"rm -rf super_clone\" &&\n+\tgit config -f .gitmodules submodule.sub.shallow false &&\n+\tgit add .gitmodules &&\n+\tgit commit -m \"recommed non shallow for sub\" &&\n+\tgit clone --recurse-submodules --no-local \"file://$pwd/.\" super_clone &&\n+\t(\n+\t\tcd super_clone &&\n+\t\tgit log --oneline >lines &&\n+\t\ttest_line_count = 5 lines\n+\t) &&\n+\t(\n+\t\tcd super_clone/sub &&\n+\t\tgit log --oneline >lines &&\n+\t\ttest_line_count = 3 lines\n+\t)\n+'\n+\n test_done\n-- \n2.9.0.rc0.2.g145fc64\n"}]}