threads / patch / 49399

patchfetch: Ensure that fetch.recurseSubmodules overrides submodule.recurse.

Subject: [PATCH] fetch: Ensure that fetch.recurseSubmodules overrides submodule.recurse.

## tl;dr

2 messages between Sep 21, 2018 and Sep 21, 2018. Diffs are folded; open one to read it.

replies: 1people: 2as markdown or json

Marc Branchaud· Sep 21, 2018, 18:51 UTC · lore
Also document this fact.
Signed-off-by: Marc Branchaud <marcnarc@xiplink.com>
---

I ran into this bug when I had both fetch.recurseSubmodules=on-demand and submodule.recurse=true, and submodule.recurse was set *after* fetch.recurseSubmodules in my config.

The fix ensures that fetch.recurseSubmodules always overrides submodule.recurse. If neither is set then fetch still behaves as if fetch.recurseSubmodules=on-demand (the documented default).

I'm not sure if this is the most elegant implementation, but it gets the job done.

		M.
 Documentation/config.txt | 6 ++++--
 builtin/fetch.c          | 5 ++++-
 2 files changed, 8 insertions(+), 3 deletions(-)
Show changes to 2 files +8 −3

Documentation/config.txt, builtin/fetch.c

diff --git a/Documentation/config.txt b/Documentation/config.txt
index eb66a11975..67b0adc1d4 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -1514,7 +1514,8 @@ fetch.recurseSubmodules::
 	recurse at all when set to false. When set to 'on-demand' (the default
 	value), fetch and pull will only recurse into a populated submodule
 	when its superproject retrieves a commit that updates the submodule's
-	reference.
+	reference.  This option overrides the more general submodule.recurse
+	option, for the `fetch` command.
 
 fetch.fsckObjects::
 	If it is set to true, git-fetch-pack will check all fetched
@@ -3465,7 +3466,8 @@ submodule.active::
 submodule.recurse::
 	Specifies if commands recurse into submodules by default. This
 	applies to all commands that have a `--recurse-submodules` option,
-	except `clone`.
+	except `clone`.  Also, the `fetch` command's behaviour can be specified
+	independently with the fetch.recurseSubmodules option.
 	Defaults to false.
 
 submodule.fetchJobs::
diff --git a/builtin/fetch.c b/builtin/fetch.c
index 61bec5d213..08b8bf2741 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -60,6 +60,7 @@ static struct transport *gsecondary;
 static const char *submodule_prefix = "";
 static int recurse_submodules = RECURSE_SUBMODULES_DEFAULT;
 static int recurse_submodules_default = RECURSE_SUBMODULES_ON_DEMAND;
+static int recurse_submodules_set_explicitly = 0;
 static int shown_url = 0;
 static struct refspec refmap = REFSPEC_INIT_FETCH;
 static struct list_objects_filter_options filter_options;
@@ -78,7 +79,8 @@ static int git_fetch_config(const char *k, const char *v, void *cb)
 		return 0;
 	}
 
-	if (!strcmp(k, "submodule.recurse")) {
+	if (!strcmp(k, "submodule.recurse") &&
+	    !recurse_submodules_set_explicitly) {
 		int r = git_config_bool(k, v) ?
 			RECURSE_SUBMODULES_ON : RECURSE_SUBMODULES_OFF;
 		recurse_submodules = r;
@@ -88,6 +90,7 @@ static int git_fetch_config(const char *k, const char *v, void *cb)
 		max_children = parse_submodule_fetchjobs(k, v);
 		return 0;
 	} else if (!strcmp(k, "fetch.recursesubmodules")) {
+		recurse_submodules_set_explicitly = 1;
 		recurse_submodules = parse_fetch_recurse_submodules_arg(k, v);
 		return 0;
 	}
-- 
2.19.0.1.g5109f9487a
Stefan Beller· Sep 21, 2018, 19:22 UTC · re: Marc Branchaud · lore

Re: [PATCH] fetch: Ensure that fetch.recurseSubmodules overrides submodule.recurse.

On Fri, Sep 21, 2018 at 12:00 PM Marc Branchaud <marcnarc@xiplink.com> wrote:
Show 13 quoted lines
>
> Also document this fact.
>
> Signed-off-by: Marc Branchaud <marcnarc@xiplink.com>
> ---
>
> I ran into this bug when I had both fetch.recurseSubmodules=on-demand and
> submodule.recurse=true, and submodule.recurse was set *after*
> fetch.recurseSubmodules in my config.
>
> The fix ensures that fetch.recurseSubmodules always overrides
> submodule.recurse.  If neither is set then fetch still behaves as if
> fetch.recurseSubmodules=on-demand (the documented default).

At least the second paragraph is valuable information in the commit message, so maybe add it there? I am not sure if the first paragraph is a good part for the commit message, but maybe helps for writing a test?

Show 12 quoted lines
> +       reference.  This option overrides the more general submodule.recurse
> +       option, for the `fetch` command.
>
>  fetch.fsckObjects::
>         If it is set to true, git-fetch-pack will check all fetched
> @@ -3465,7 +3466,8 @@ submodule.active::
>  submodule.recurse::
>         Specifies if commands recurse into submodules by default. This
>         applies to all commands that have a `--recurse-submodules` option,
> -       except `clone`.
> +       except `clone`.  Also, the `fetch` command's behaviour can be specified
> +       independently with the fetch.recurseSubmodules option.
There is also push.recurseSubmodules, which should behave similarly?

The series that introduced submodule.recurse ends with 58f4203e7db (builtin/fetch.c: respect 'submodule.recurse' option, 2017-05-31) (sb/submodule-blanket-recursive) seems to have overlooked this only for fetch/push, as the other commands (checkout, read-tree, reset, grep) do not have their own specific setting to recurse.

Show 5 quoted lines
> @@ -88,6 +90,7 @@ static int git_fetch_config(const char *k, const char *v, void *cb)
>                 max_children = parse_submodule_fetchjobs(k, v);
>                 return 0;
>         } else if (!strcmp(k, "fetch.recursesubmodules")) {
> +               recurse_submodules_set_explicitly = 1;

the command line option also overried explicitely, but that is ensured via the program flow (parse_config happens after git_config to overlay options, which itself was pre-seeded with fetch_config_from_gitmodules).

I briefly wondered if this overlaying approach would be better (i.e. first do git_config with more generic option, and then again with the more detailed option) as it would save one global variable, but the downsides are terrible (way more work to do, more code and such), so I think having a global makes sense and gets the job done.

Ideally instead of a global we'd have this flag stored in the repository struct, as eventually in the long run, fetch_populated_submodules could happen in-process instead of spawning fetch processes for each submodule (and their nested submodules which may be configured differently). But for now the global will do.

Thanks! Stefan

← back to recent threads