diff options
author | Junio C Hamano <gitster@pobox.com> | 2017-03-30 14:07:14 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2017-03-30 14:07:14 -0700 |
commit | a93dcb0a56a38289632a85d906e49150b1e34100 (patch) | |
tree | 64b79bdee36dcc8326c08e0aca55f1d8b423ebff /submodule.c | |
parent | 7a09a61e66e34d936c2cc628170031a754ce6e5f (diff) | |
parent | 1b614c07d2428927358cc7317622913d1dbd59c9 (diff) | |
download | git-a93dcb0a56a38289632a85d906e49150b1e34100.tar.gz |
Merge branch 'bw/submodule-is-active'
"what URL do we want to update this submodule?" and "are we
interested in this submodule?" are split into two distinct
concepts, and then the way used to express the latter got extended,
paving a way to make it easier to manage a project with many
submodules and make it possible to later extend use of multiple
worktrees for a project with submodules.
* bw/submodule-is-active:
submodule add: respect submodule.active and submodule.<name>.active
submodule--helper init: set submodule.<name>.active
clone: teach --recurse-submodules to optionally take a pathspec
submodule init: initialize active submodules
submodule: decouple url and submodule interest
submodule--helper clone: check for configured submodules using helper
submodule sync: use submodule--helper is-active
submodule sync: skip work for inactive submodules
submodule status: use submodule--helper is-active
submodule--helper: add is-active subcommand
Diffstat (limited to 'submodule.c')
-rw-r--r-- | submodule.c | 50 |
1 files changed, 42 insertions, 8 deletions
diff --git a/submodule.c b/submodule.c index 040f4c2287..c52d6634c5 100644 --- a/submodule.c +++ b/submodule.c @@ -213,25 +213,59 @@ void gitmodules_config_sha1(const unsigned char *commit_sha1) } /* + * NEEDSWORK: With the addition of different configuration options to determine + * if a submodule is of interests, the validity of this function's name comes + * into question. Once the dust has settled and more concrete terminology is + * decided upon, come up with a more proper name for this function. One + * potential candidate could be 'is_submodule_active()'. + * * Determine if a submodule has been initialized at a given 'path' */ int is_submodule_initialized(const char *path) { int ret = 0; - const struct submodule *module = NULL; + char *key = NULL; + char *value = NULL; + const struct string_list *sl; + const struct submodule *module = submodule_from_path(null_sha1, path); - module = submodule_from_path(null_sha1, path); + /* early return if there isn't a path->module mapping */ + if (!module) + return 0; - if (module) { - char *key = xstrfmt("submodule.%s.url", module->name); - char *value = NULL; + /* submodule.<name>.active is set */ + key = xstrfmt("submodule.%s.active", module->name); + if (!git_config_get_bool(key, &ret)) { + free(key); + return ret; + } + free(key); - ret = !git_config_get_string(key, &value); + /* submodule.active is set */ + sl = git_config_get_value_multi("submodule.active"); + if (sl) { + struct pathspec ps; + struct argv_array args = ARGV_ARRAY_INIT; + const struct string_list_item *item; - free(value); - free(key); + for_each_string_list_item(item, sl) { + argv_array_push(&args, item->string); + } + + parse_pathspec(&ps, 0, 0, NULL, args.argv); + ret = match_pathspec(&ps, path, strlen(path), 0, NULL, 1); + + argv_array_clear(&args); + clear_pathspec(&ps); + return ret; } + /* fallback to checking if the URL is set */ + key = xstrfmt("submodule.%s.url", module->name); + ret = !git_config_get_string(key, &value); + + free(value); + free(key); return ret; } |