Submodule shallow recommendation [WAS: Submodules: have a depth field in the .gitmodules file]
v3 cover Submodule shallow recommendation [WAS: Submodules: have a depth field in the .gitmodules file]
v3:
* fixed documentation to consistently mention recommend-shallow
* realigned code in the config patch
* Thanks Remi for reviewing! diff to v2:
Documentation/git-submodule.txt +4 -3
@@ -15,7 +15,7 @@ SYNOPSIS 'git submodule' [--quiet] init [--] [<path>...] 'git submodule' [--quiet] deinit [-f|--force] (--all|[--] <path>...) 'git submodule' [--quiet] update [--init] [--remote] [-N|--no-fetch] - [--[no-]recommended-depth] [-f|--force] [--rebase|--merge] + [--[no-]recommend-shallow] [-f|--force] [--rebase|--merge] [--reference <repository>] [--depth <depth>] [--recursive] [--jobs <n>] [--] [<path>...] 'git submodule' [--quiet] summary [--cached|--files] [(-n|--summary-limit) <n>]
@@ -385,10 +385,11 @@ for linkgit:git-clone[1]'s `--reference` and `--shared` options carefully. clone with a history truncated to the specified number of revisions. See linkgit:git-clone[1] ---[no-]recommended-depth:: +--[no-]recommend-shallow:: This option is only valid for the update command. The initial clone of a submodule will use the recommended - `submodule.<name>.depth` as provided by the .gitmodules file. + `submodule.<name>.shallow` as provided by the .gitmodules file + by default. To ignore the suggestions use `--no-recommend-shallow`. -j <n>:: --jobs <n>::
submodule-config.c +1 -2
@@ -355,8 +355,7 @@ static int parse_config(const char *var, const char *value, void *data) &submodule->update_strategy) < 0)die (_ ("invalid value for %s" ), var); }else if (!strcmp (item.buf,"shallow" )) { -if (!me->overwrite && - submodule->recommend_shallow !=-1 ) +if (!me->overwrite && submodule->recommend_shallow !=-1 )warn_multiple_config (me->commit_sha1, submodule->name,"shallow" );else {
v2:
* Instead of storing the depth, we keep a boolean shallow field in the .gitmodules file.
* slightly renamed options (--recommend-shallow instead of --recommended-depth)
* one more test
* I dropped [PATCH 1/3] submodule update: make use of the existing fetch_in_submodule function as Junio picked it up separately as sb/submodule-misc-cleanups
v1:
Sometimes the history of a submodule is not considered important by the projects upstream. To make it easier for downstream users, allow a field 'submodule.<name>.depth' in .gitmodules, which can be used to indicate the recommended depth.
Thanks,
Stefan
Stefan Beller (2):
submodule-config: keep shallow recommendation around submodule update: learn --[no-]recommend-shallow option
Documentation/git-submodule.txt | 11 +++++++-- builtin/submodule--helper.c | 7 +++++- git-submodule.sh | 9 ++++++- submodule-config.c | 9 +++++++ submodule-config.h | 1 + t/t5614-clone-submodules.sh | 52 +++++++++++++++++++++++++++++++++++++++++ 6 files changed, 85 insertions(+), 4 deletions(-)
Signature · 3 lines
2.9.0.rc0.2.g145fc64 base-commit: 3a0f269e7c82aa3a87323cb7ae04ac5f129f036b
PATCH v3 1/2 submodule-config: keep shallow recommendation around
The shallow field will be used in a later patch by submodule update. To differentiate between the actual depth (which may be different), we name it recommend_shallow as the field in the .gitmodules file is only a recommendation by the project.
--- submodule-config.c | 9 +++++++++ submodule-config.h | 1 + 2 files changed, 10 insertions(+)
submodule-config.c +9 -0
@@ -199,6 +199,7 @@ static struct submodule *lookup_or_create_by_name(struct submodule_cache *cache, submodule->update_strategy.command =NULL ; submodule->fetch_recurse =RECURSE_SUBMODULES_NONE ; submodule->ignore =NULL ; + submodule->recommend_shallow =-1 ;hashcpy (submodule->gitmodules_sha1, gitmodules_sha1);
@@ -353,6 +354,14 @@ static int parse_config(const char *var, const char *value, void *data)else if (parse_submodule_update_strategy (value, &submodule->update_strategy) <0 )die (_ ("invalid value for %s" ), var); + }else if (!strcmp (item.buf,"shallow" )) { +if (!me->overwrite && submodule->recommend_shallow !=-1 ) +warn_multiple_config (me->commit_sha1, submodule->name, +"shallow" ); +else { + submodule->recommend_shallow = +git_config_bool (var, value); + } }strbuf_release (&name);
submodule-config.h +1 -0
@@ -18,6 +18,7 @@ struct submodule {struct submodule_update_strategy update_strategy;/* the sha1 blob id of the responsible .gitmodules file */ unsigned char gitmodules_sha1[20 ]; +int recommend_shallow; };int parse_fetch_recurse_submodules_arg (const char *opt,const char *arg);
Signature · 1 line
2.9.0.rc0.2.g145fc64
PATCH v3 2/2 submodule update: learn `--[no-]recommend-shallow` option
In reply to Stefan BellerSometimes the history of a submodule is not considered important by the projects upstream. To make it easier for downstream users, allow a boolean field 'submodule.<name>.shallow' in .gitmodules, which can be used to recommend whether upstream considers the history important.
This field is honored in the initial clone by default, it can be ignored by giving the --no-recommend-shallow option.
--- Documentation/git-submodule.txt | 11 +++++++-- builtin/submodule--helper.c | 7 +++++- git-submodule.sh | 9 ++++++- t/t5614-clone-submodules.sh | 52 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 75 insertions(+), 4 deletions(-)
Documentation/git-submodule.txt +9 -2
@@ -15,8 +15,9 @@ SYNOPSIS 'git submodule' [--quiet] init [--] [<path>...] 'git submodule' [--quiet] deinit [-f|--force] (--all|[--] <path>...) 'git submodule' [--quiet] update [--init] [--remote] [-N|--no-fetch] - [-f|--force] [--rebase|--merge] [--reference <repository>] - [--depth <depth>] [--recursive] [--jobs <n>] [--] [<path>...] + [--[no-]recommend-shallow] [-f|--force] [--rebase|--merge] + [--reference <repository>] [--depth <depth>] [--recursive] + [--jobs <n>] [--] [<path>...] 'git submodule' [--quiet] summary [--cached|--files] [(-n|--summary-limit) <n>] [commit] [--] [<path>...] 'git submodule' [--quiet] foreach [--recursive] <command>
@@ -384,6 +385,12 @@ for linkgit:git-clone[1]'s `--reference` and `--shared` options carefully. clone with a history truncated to the specified number of revisions. See linkgit:git-clone[1] +--[no-]recommend-shallow:: + This option is only valid for the update command. + The initial clone of a submodule will use the recommended + `submodule.<name>.shallow` as provided by the .gitmodules file + by default. To ignore the suggestions use `--no-recommend-shallow`. + -j <n>:: --jobs <n>:: This option is only valid for the update command.
builtin/submodule--helper.c +6 -1
@@ -581,6 +581,7 @@ struct submodule_update_clone {/* configuration parameters which are passed on to the children */ int quiet; +int recommend_shallow;const char *reference;const char *depth;const char *recursive_prefix;
@@ -593,7 +594,7 @@ struct submodule_update_clone { unsigned quickstop : 1; };#define SUBMODULE_UPDATE_CLONE_INIT {0, MODULE_LIST_INIT, 0, \ - SUBMODULE_UPDATE_STRATEGY_INIT, 0, NULL, NULL, NULL, NULL, \ + SUBMODULE_UPDATE_STRATEGY_INIT, 0, -1, NULL, NULL, NULL, NULL, \ STRING_LIST_INIT_DUP, 0}
@@ -698,6 +699,8 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,argv_array_push (&child->args,"--quiet" );if (suc->prefix)argv_array_pushl (&child->args,"--prefix" , suc->prefix,NULL ); +if (suc->recommend_shallow && sub->recommend_shallow ==1 ) +argv_array_push (&child->args,"--depth=1" );argv_array_pushl (&child->args,"--path" , sub->path,NULL );argv_array_pushl (&child->args,"--name" , sub->name,NULL );argv_array_pushl (&child->args,"--url" , url,NULL );
@@ -780,6 +783,8 @@ static int update_clone(int argc, const char **argv, const char *prefix) "specified number of revisions")),OPT_INTEGER ('j' ,"jobs" , &max_jobs,N_ ("parallel jobs" )), +OPT_BOOL (0 ,"recommend-shallow" , &suc.recommend_shallow, +N_ ("whether the initial clone should follow the shallow recommendation" )),OPT__QUIET (&suc.quiet,N_ ("don't print cloning progress" )), OPT_END() };
git-submodule.sh +8 -1
@@ -9,7 +9,7 @@ USAGE="[--quiet] add [-b <branch>] [-f|--force] [--name <name>] [--reference <re or: $dashless [--quiet] status [--cached] [--recursive] [--] [<path>...] or: $dashless [--quiet] init [--] [<path>...] or: $dashless [--quiet] deinit [-f|--force] (--all| [--] <path>...) - or: $dashless [--quiet] update [--init] [--remote] [-N|--no-fetch] [-f|--force] [--checkout|--merge|--rebase] [--reference <repository>] [--recursive] [--] [<path>...] + or: $dashless [--quiet] update [--init] [--remote] [-N|--no-fetch] [-f|--force] [--checkout|--merge|--rebase] [--[no-]recommend-shallow] [--reference <repository>] [--recursive] [--] [<path>...] or: $dashless [--quiet] summary [--cached|--files] [--summary-limit <n>] [commit] [--] [<path>...] or: $dashless [--quiet] foreach [--recursive] <command> or: $dashless [--quiet] sync [--recursive] [--] [<path>...]"
@@ -559,6 +559,12 @@ cmd_update() --checkout) update="checkout" ;; + --recommend-shallow) + recommend_shallow="--recommend-shallow" + ;; + --no-recommend-shallow) + recommend_shallow="--no-recommend-shallow" + ;; --depth) case "$2" in '') usage ;; esac depth="--depth=$2"
@@ -601,6 +607,7 @@ cmd_update() ${update:+--update "$update"} \ ${reference:+--reference "$reference"} \ ${depth:+--depth "$depth"} \ + ${recommend_shallow:+"$recommend_shallow"} \ ${jobs:+$jobs} \ "$@" || echo "#unmatched" } | {
t/t5614-clone-submodules.sh +52 -0
56 lines not on this page · raw message
Signature · 1 line
2.9.0.rc0.2.g145fc64