In later patches we introduce the --recurse-submodule flag for commands that modify the working directory, e.g. git-checkout. It is potentially expensive to check if a submodule needs an update, because a common theme to interact with submodules is to spawn a child process for each interaction. So let's introduce a function that checks if a submodule needs to be checked for an update before attempting the update. Signed-off-by: Stefan Beller <sbeller@xxxxxxxxxx> --- submodule.c | 27 +++++++++++++++++++++++++++ submodule.h | 13 +++++++++++++ 2 files changed, 40 insertions(+) diff --git a/submodule.c b/submodule.c index 591f4a694e..2a37e03420 100644 --- a/submodule.c +++ b/submodule.c @@ -548,6 +548,33 @@ void set_config_update_recurse_submodules(int value) config_update_recurse_submodules = value; } +int touch_submodules_in_worktree(void) +{ + /* + * Update can't be "none", "merge" or "rebase", + * treat any value as OFF, except an explicit ON. + */ + return config_update_recurse_submodules == RECURSE_SUBMODULES_ON; +} + +int is_active_submodule_with_strategy(const struct cache_entry *ce, + enum submodule_update_type strategy) +{ + const struct submodule *sub; + + if (!S_ISGITLINK(ce->ce_mode)) + return 0; + + if (!touch_submodules_in_worktree()) + return 0; + + sub = submodule_from_path(null_sha1, ce->name); + if (!sub) + return 0; + + return sub->update_strategy.type == strategy; +} + static int has_remote(const char *refname, const struct object_id *oid, int flags, void *cb_data) { diff --git a/submodule.h b/submodule.h index b4e60c08d2..46d9f0f293 100644 --- a/submodule.h +++ b/submodule.h @@ -65,6 +65,19 @@ extern void show_submodule_inline_diff(FILE *f, const char *path, const struct diff_options *opt); extern void set_config_fetch_recurse_submodules(int value); extern void set_config_update_recurse_submodules(int value); + +/* + * Traditionally Git ignored changes made for submodules. + * This function checks if we are interested in the given submodule + * for any kind of operation. + */ +extern int touch_submodules_in_worktree(void); +/* + * Check if the given ce entry is a submodule with the given update + * strategy configured. + */ +extern int is_active_submodule_with_strategy(const struct cache_entry *ce, + enum submodule_update_type strategy); extern void check_for_new_submodule_commits(unsigned char new_sha1[20]); extern int fetch_populated_submodules(const struct argv_array *options, const char *prefix, int command_line_option, -- 2.12.0.rc1.16.ge4278d41a0.dirty