From f20e7c1ea2459d9b8c12f8ed1f1546665841b643 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Wed, 2 Aug 2017 12:49:18 -0700 Subject: submodule: remove submodule.fetchjobs from submodule-config parsing The '.gitmodules' file should only contain information pertinent to configuring individual submodules (name to path mapping, URL where to obtain the submodule, etc.) while other configuration like the number of jobs to use when fetching submodules should be a part of the repository's config. Remove the 'submodule.fetchjobs' configuration option from the general submodule-config parsing and instead rely on using the 'config_from_gitmodules()' in order to maintain backwards compatibility with this config being placed in the '.gitmodules' file. Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano --- submodule.h | 1 - 1 file changed, 1 deletion(-) (limited to 'submodule.h') diff --git a/submodule.h b/submodule.h index e85b144863..c8164a3b29 100644 --- a/submodule.h +++ b/submodule.h @@ -112,7 +112,6 @@ extern int push_unpushed_submodules(struct oid_array *commits, const struct string_list *push_options, int dry_run); extern void connect_work_tree_and_git_dir(const char *work_tree, const char *git_dir); -extern int parallel_submodules(void); /* * Given a submodule path (as in the index), return the repository * path of that submodule in 'buf'. Return -1 on error or when the -- cgit 1.2.3-korg From 8fa2915971e5032e6a32f5096452db81ab8795eb Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Wed, 2 Aug 2017 12:49:19 -0700 Subject: submodule: remove fetch.recursesubmodules from submodule-config parsing Remove the 'fetch.recursesubmodules' configuration option from the general submodule-config parsing and instead rely on using 'config_from_gitmodules()' in order to maintain backwards compatibility with this config being placed in the '.gitmodules' file. Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano --- builtin/fetch.c | 8 +++++++- submodule.c | 19 ++++++------------- submodule.h | 2 +- 3 files changed, 14 insertions(+), 15 deletions(-) (limited to 'submodule.h') diff --git a/builtin/fetch.c b/builtin/fetch.c index ade092bf8d..d84c26391c 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -71,6 +71,9 @@ static int git_fetch_config(const char *k, const char *v, void *cb) if (!strcmp(k, "submodule.fetchjobs")) { max_children = parse_submodule_fetchjobs(k, v); return 0; + } else if (!strcmp(k, "fetch.recursesubmodules")) { + recurse_submodules = parse_fetch_recurse_submodules_arg(k, v); + return 0; } return git_default_config(k, v, cb); @@ -81,6 +84,9 @@ static int gitmodules_fetch_config(const char *var, const char *value, void *cb) if (!strcmp(var, "submodule.fetchjobs")) { max_children = parse_submodule_fetchjobs(var, value); return 0; + } else if (!strcmp(var, "fetch.recursesubmodules")) { + recurse_submodules = parse_fetch_recurse_submodules_arg(var, value); + return 0; } return 0; @@ -1355,7 +1361,6 @@ int cmd_fetch(int argc, const char **argv, const char *prefix) deepen = 1; if (recurse_submodules != RECURSE_SUBMODULES_OFF) { - set_config_fetch_recurse_submodules(recurse_submodules_default); gitmodules_config(); git_config(submodule_config, NULL); } @@ -1399,6 +1404,7 @@ int cmd_fetch(int argc, const char **argv, const char *prefix) result = fetch_populated_submodules(&options, submodule_prefix, recurse_submodules, + recurse_submodules_default, verbosity < 0, max_children); argv_array_clear(&options); diff --git a/submodule.c b/submodule.c index aa4fb1eaa2..1d9d2ce094 100644 --- a/submodule.c +++ b/submodule.c @@ -20,7 +20,6 @@ #include "worktree.h" #include "parse-options.h" -static int config_fetch_recurse_submodules = RECURSE_SUBMODULES_ON_DEMAND; static int config_update_recurse_submodules = RECURSE_SUBMODULES_OFF; static struct string_list changed_submodule_paths = STRING_LIST_INIT_DUP; static int initialized_fetch_ref_tips; @@ -160,10 +159,6 @@ static int git_modules_config(const char *var, const char *value, void *cb) { if (starts_with(var, "submodule.")) return parse_submodule_config_option(var, value); - else if (!strcmp(var, "fetch.recursesubmodules")) { - config_fetch_recurse_submodules = parse_fetch_recurse_submodules_arg(var, value); - return 0; - } return 0; } @@ -714,11 +709,6 @@ done: clear_commit_marks(right, ~0); } -void set_config_fetch_recurse_submodules(int value) -{ - config_fetch_recurse_submodules = value; -} - int should_update_submodules(void) { return config_update_recurse_submodules == RECURSE_SUBMODULES_ON; @@ -1164,10 +1154,11 @@ struct submodule_parallel_fetch { const char *work_tree; const char *prefix; int command_line_option; + int default_option; int quiet; int result; }; -#define SPF_INIT {0, ARGV_ARRAY_INIT, NULL, NULL, 0, 0, 0} +#define SPF_INIT {0, ARGV_ARRAY_INIT, NULL, NULL, 0, 0, 0, 0} static int get_next_submodule(struct child_process *cp, struct strbuf *err, void *data, void **task_cb) @@ -1205,10 +1196,10 @@ static int get_next_submodule(struct child_process *cp, default_argv = "on-demand"; } } else { - if ((config_fetch_recurse_submodules == RECURSE_SUBMODULES_OFF) || + if ((spf->default_option == RECURSE_SUBMODULES_OFF) || gitmodules_is_unmerged) continue; - if (config_fetch_recurse_submodules == RECURSE_SUBMODULES_ON_DEMAND) { + if (spf->default_option == RECURSE_SUBMODULES_ON_DEMAND) { if (!unsorted_string_list_lookup(&changed_submodule_paths, ce->name)) continue; default_argv = "on-demand"; @@ -1275,6 +1266,7 @@ static int fetch_finish(int retvalue, struct strbuf *err, int fetch_populated_submodules(const struct argv_array *options, const char *prefix, int command_line_option, + int default_option, int quiet, int max_parallel_jobs) { int i; @@ -1282,6 +1274,7 @@ int fetch_populated_submodules(const struct argv_array *options, spf.work_tree = get_git_work_tree(); spf.command_line_option = command_line_option; + spf.default_option = default_option; spf.quiet = quiet; spf.prefix = prefix; diff --git a/submodule.h b/submodule.h index c8164a3b29..29a1ecd19a 100644 --- a/submodule.h +++ b/submodule.h @@ -76,7 +76,6 @@ extern void show_submodule_inline_diff(FILE *f, const char *path, unsigned dirty_submodule, const char *meta, const char *del, const char *add, const char *reset, const struct diff_options *opt); -extern void set_config_fetch_recurse_submodules(int value); /* Check if we want to update any submodule.*/ extern int should_update_submodules(void); /* @@ -87,6 +86,7 @@ extern const struct submodule *submodule_from_ce(const struct cache_entry *ce); extern void check_for_new_submodule_commits(struct object_id *oid); extern int fetch_populated_submodules(const struct argv_array *options, const char *prefix, int command_line_option, + int default_option, int quiet, int max_parallel_jobs); extern unsigned is_submodule_modified(const char *path, int ignore_untracked); extern int submodule_uses_gitfile(const char *path); -- cgit 1.2.3-korg From 91b834807b98b620050fe534b6de93e223dbcbcf Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Wed, 2 Aug 2017 12:49:20 -0700 Subject: submodule: check for unstaged .gitmodules outside of config parsing Teach 'is_staging_gitmodules_ok()' to be able to determine in the '.gitmodules' file has unstaged changes based on the passed in index instead of relying on a global variable which is set during the submodule-config parsing. Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano --- builtin/mv.c | 2 +- builtin/rm.c | 2 +- submodule.c | 32 +++++++++++++++++--------------- submodule.h | 2 +- 4 files changed, 20 insertions(+), 18 deletions(-) (limited to 'submodule.h') diff --git a/builtin/mv.c b/builtin/mv.c index dcf6736b5b..94fbaaa5da 100644 --- a/builtin/mv.c +++ b/builtin/mv.c @@ -81,7 +81,7 @@ static void prepare_move_submodule(const char *src, int first, struct strbuf submodule_dotgit = STRBUF_INIT; if (!S_ISGITLINK(active_cache[first]->ce_mode)) die(_("Directory %s is in index and no submodule?"), src); - if (!is_staging_gitmodules_ok()) + if (!is_staging_gitmodules_ok(&the_index)) die(_("Please stage your changes to .gitmodules or stash them to proceed")); strbuf_addf(&submodule_dotgit, "%s/.git", src); *submodule_gitfile = read_gitfile(submodule_dotgit.buf); diff --git a/builtin/rm.c b/builtin/rm.c index 52826d1379..4057e73fa0 100644 --- a/builtin/rm.c +++ b/builtin/rm.c @@ -286,7 +286,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix) list.entry[list.nr].name = xstrdup(ce->name); list.entry[list.nr].is_submodule = S_ISGITLINK(ce->ce_mode); if (list.entry[list.nr++].is_submodule && - !is_staging_gitmodules_ok()) + !is_staging_gitmodules_ok(&the_index)) die (_("Please stage your changes to .gitmodules or stash them to proceed")); } diff --git a/submodule.c b/submodule.c index 1d9d2ce094..677b5c4015 100644 --- a/submodule.c +++ b/submodule.c @@ -37,18 +37,25 @@ static struct oid_array ref_tips_after_fetch; static int gitmodules_is_unmerged; /* - * This flag is set if the .gitmodules file had unstaged modifications on - * startup. This must be checked before allowing modifications to the - * .gitmodules file with the intention to stage them later, because when - * continuing we would stage the modifications the user didn't stage herself - * too. That might change in a future version when we learn to stage the - * changes we do ourselves without staging any previous modifications. + * Check if the .gitmodules file has unstaged modifications. This must be + * checked before allowing modifications to the .gitmodules file with the + * intention to stage them later, because when continuing we would stage the + * modifications the user didn't stage herself too. That might change in a + * future version when we learn to stage the changes we do ourselves without + * staging any previous modifications. */ -static int gitmodules_is_modified; - -int is_staging_gitmodules_ok(void) +int is_staging_gitmodules_ok(const struct index_state *istate) { - return !gitmodules_is_modified; + int pos = index_name_pos(istate, GITMODULES_FILE, strlen(GITMODULES_FILE)); + + if ((pos >= 0) && (pos < istate->cache_nr)) { + struct stat st; + if (lstat(GITMODULES_FILE, &st) == 0 && + ce_match_stat(istate->cache[pos], &st, 0) & DATA_CHANGED) + return 0; + } + + return 1; } /* @@ -231,11 +238,6 @@ void gitmodules_config(void) !memcmp(ce->name, GITMODULES_FILE, 11)) gitmodules_is_unmerged = 1; } - } else if (pos < active_nr) { - struct stat st; - if (lstat(GITMODULES_FILE, &st) == 0 && - ce_match_stat(active_cache[pos], &st, 0) & DATA_CHANGED) - gitmodules_is_modified = 1; } if (!gitmodules_is_unmerged) diff --git a/submodule.h b/submodule.h index 29a1ecd19a..b14660585f 100644 --- a/submodule.h +++ b/submodule.h @@ -33,7 +33,7 @@ struct submodule_update_strategy { }; #define SUBMODULE_UPDATE_STRATEGY_INIT {SM_UPDATE_UNSPECIFIED, NULL} -extern int is_staging_gitmodules_ok(void); +extern int is_staging_gitmodules_ok(const struct index_state *istate); extern int update_path_in_gitmodules(const char *oldpath, const char *newpath); extern int remove_path_from_gitmodules(const char *path); extern void stage_updated_gitmodules(void); -- cgit 1.2.3-korg From 34e2ba04be4f8e11d91b2508aa8ca84148fe63f1 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Wed, 2 Aug 2017 12:49:21 -0700 Subject: submodule: check for unmerged .gitmodules outside of config parsing Add 'is_gitmodules_unmerged()' function which can be used to determine in the '.gitmodules' file is unmerged based on the passed in index instead of relying on a global variable which is set during the submodule-config parsing. Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano --- submodule.c | 47 +++++++++++++++++++++++------------------------ submodule.h | 1 + 2 files changed, 24 insertions(+), 24 deletions(-) (limited to 'submodule.h') diff --git a/submodule.c b/submodule.c index 677b5c4015..3b0e70c51d 100644 --- a/submodule.c +++ b/submodule.c @@ -27,14 +27,25 @@ static struct oid_array ref_tips_before_fetch; static struct oid_array ref_tips_after_fetch; /* - * The following flag is set if the .gitmodules file is unmerged. We then - * disable recursion for all submodules where .git/config doesn't have a - * matching config entry because we can't guess what might be configured in - * .gitmodules unless the user resolves the conflict. When a command line - * option is given (which always overrides configuration) this flag will be - * ignored. + * Check if the .gitmodules file is unmerged. Parsing of the .gitmodules file + * will be disabled because we can't guess what might be configured in + * .gitmodules unless the user resolves the conflict. */ -static int gitmodules_is_unmerged; +int is_gitmodules_unmerged(const struct index_state *istate) +{ + int pos = index_name_pos(istate, GITMODULES_FILE, strlen(GITMODULES_FILE)); + if (pos < 0) { /* .gitmodules not found or isn't merged */ + pos = -1 - pos; + if (istate->cache_nr > pos) { /* there is a .gitmodules */ + const struct cache_entry *ce = istate->cache[pos]; + if (ce_namelen(ce) == strlen(GITMODULES_FILE) && + !strcmp(ce->name, GITMODULES_FILE)) + return 1; + } + } + + return 0; +} /* * Check if the .gitmodules file has unstaged modifications. This must be @@ -71,7 +82,7 @@ int update_path_in_gitmodules(const char *oldpath, const char *newpath) if (!file_exists(GITMODULES_FILE)) /* Do nothing without .gitmodules */ return -1; - if (gitmodules_is_unmerged) + if (is_gitmodules_unmerged(&the_index)) die(_("Cannot change unmerged .gitmodules, resolve merge conflicts first")); submodule = submodule_from_path(null_sha1, oldpath); @@ -105,7 +116,7 @@ int remove_path_from_gitmodules(const char *path) if (!file_exists(GITMODULES_FILE)) /* Do nothing without .gitmodules */ return -1; - if (gitmodules_is_unmerged) + if (is_gitmodules_unmerged(&the_index)) die(_("Cannot change unmerged .gitmodules, resolve merge conflicts first")); submodule = submodule_from_path(null_sha1, path); @@ -156,7 +167,7 @@ void set_diffopt_flags_from_submodule_config(struct diff_options *diffopt, if (submodule) { if (submodule->ignore) handle_ignore_submodules_arg(diffopt, submodule->ignore); - else if (gitmodules_is_unmerged) + else if (is_gitmodules_unmerged(&the_index)) DIFF_OPT_SET(diffopt, IGNORE_SUBMODULES); } } @@ -224,23 +235,12 @@ void gitmodules_config(void) const char *work_tree = get_git_work_tree(); if (work_tree) { struct strbuf gitmodules_path = STRBUF_INIT; - int pos; strbuf_addstr(&gitmodules_path, work_tree); strbuf_addstr(&gitmodules_path, "/" GITMODULES_FILE); if (read_cache() < 0) die("index file corrupt"); - pos = cache_name_pos(GITMODULES_FILE, 11); - if (pos < 0) { /* .gitmodules not found or isn't merged */ - pos = -1 - pos; - if (active_nr > pos) { /* there is a .gitmodules */ - const struct cache_entry *ce = active_cache[pos]; - if (ce_namelen(ce) == 11 && - !memcmp(ce->name, GITMODULES_FILE, 11)) - gitmodules_is_unmerged = 1; - } - } - if (!gitmodules_is_unmerged) + if (!is_gitmodules_unmerged(&the_index)) git_config_from_file(git_modules_config, gitmodules_path.buf, NULL); strbuf_release(&gitmodules_path); @@ -1198,8 +1198,7 @@ static int get_next_submodule(struct child_process *cp, default_argv = "on-demand"; } } else { - if ((spf->default_option == RECURSE_SUBMODULES_OFF) || - gitmodules_is_unmerged) + if (spf->default_option == RECURSE_SUBMODULES_OFF) continue; if (spf->default_option == RECURSE_SUBMODULES_ON_DEMAND) { if (!unsorted_string_list_lookup(&changed_submodule_paths, ce->name)) diff --git a/submodule.h b/submodule.h index b14660585f..8022faa591 100644 --- a/submodule.h +++ b/submodule.h @@ -33,6 +33,7 @@ struct submodule_update_strategy { }; #define SUBMODULE_UPDATE_STRATEGY_INIT {SM_UPDATE_UNSPECIFIED, NULL} +extern int is_gitmodules_unmerged(const struct index_state *istate); extern int is_staging_gitmodules_ok(const struct index_state *istate); extern int update_path_in_gitmodules(const char *oldpath, const char *newpath); extern int remove_path_from_gitmodules(const char *path); -- cgit 1.2.3-korg