All of lore.kernel.org
 help / color / mirror / Atom feed
From: Heiko Voigt <hvoigt@hvoigt.net>
To: git@vger.kernel.org
Cc: sbeller@google.com, jrnieder@gmail.com, Jens.Lehmann@web.de,
	Brandon Williams <bmwill@google.com>
Subject: [RFC PATCH 2/2] submodule: simplify decision tree whether to or not to fetch
Date: Thu, 17 Aug 2017 13:00:13 +0200	[thread overview]
Message-ID: <20170817110013.GD52233@book.hvoigt.net> (raw)
In-Reply-To: <20170817105349.GC52233@book.hvoigt.net>

To make extending this logic later easier.

Signed-off-by: Heiko Voigt <hvoigt@hvoigt.net>
---
I am quite sure I replicated the same logic but a few more eyes would be
appreciated.

Cheers Heiko

 submodule.c | 55 +++++++++++++++++++++++++++----------------------------
 1 file changed, 27 insertions(+), 28 deletions(-)

diff --git a/submodule.c b/submodule.c
index 3ed78ac..a1011f4 100644
--- a/submodule.c
+++ b/submodule.c
@@ -1171,6 +1171,21 @@ int submodule_touches_in_range(struct object_id *excl_oid,
 	return ret;
 }
 
+static int get_fetch_recurse_config(const struct submodule *submodule, int command_line_option)
+{
+	if (command_line_option != RECURSE_SUBMODULES_DEFAULT)
+		return command_line_option;
+
+	if (submodule && submodule->fetch_recurse != RECURSE_SUBMODULES_NONE)
+		/* local config overrules everything except commandline */
+		return submodule->fetch_recurse;
+
+	if (gitmodules_is_unmerged)
+		return RECURSE_SUBMODULES_OFF;
+
+	return config_fetch_recurse_submodules;
+}
+
 struct submodule_parallel_fetch {
 	int count;
 	struct argv_array args;
@@ -1203,37 +1218,21 @@ static int get_next_submodule(struct child_process *cp,
 		if (!submodule)
 			submodule = submodule_from_name(&null_oid, ce->name);
 
-		default_argv = "yes";
-		if (spf->command_line_option == RECURSE_SUBMODULES_DEFAULT) {
-			if (submodule &&
-			    submodule->fetch_recurse !=
-						RECURSE_SUBMODULES_NONE) {
-				if (submodule->fetch_recurse ==
-						RECURSE_SUBMODULES_OFF)
-					continue;
-				if (submodule->fetch_recurse ==
-						RECURSE_SUBMODULES_ON_DEMAND) {
-					if (!unsorted_string_list_lookup(&changed_submodule_names,
-									 submodule->name))
-						continue;
-					default_argv = "on-demand";
-				}
-			} else {
-				if ((config_fetch_recurse_submodules == RECURSE_SUBMODULES_OFF) ||
-				    gitmodules_is_unmerged)
-					continue;
-				if (config_fetch_recurse_submodules == RECURSE_SUBMODULES_ON_DEMAND) {
-					if (!unsorted_string_list_lookup(&changed_submodule_names,
-									 submodule->name))
-						continue;
-					default_argv = "on-demand";
-				}
-			}
-		} else if (spf->command_line_option == RECURSE_SUBMODULES_ON_DEMAND) {
-			if (!unsorted_string_list_lookup(&changed_submodule_names,
+		switch (get_fetch_recurse_config(submodule, spf->command_line_option))
+		{
+		default:
+		case RECURSE_SUBMODULES_DEFAULT:
+		case RECURSE_SUBMODULES_ON_DEMAND:
+			if (!submodule || !unsorted_string_list_lookup(&changed_submodule_names,
 							 submodule->name))
 				continue;
 			default_argv = "on-demand";
+			break;
+		case RECURSE_SUBMODULES_ON:
+			default_argv = "yes";
+			break;
+		case RECURSE_SUBMODULES_OFF:
+			continue;
 		}
 
 		strbuf_addf(&submodule_path, "%s/%s", spf->work_tree, ce->name);
-- 
2.0.0.274.g6b2cd91


  reply	other threads:[~2017-08-17 11:00 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-17 10:53 [RFC PATCH 1/2] implement fetching of moved submodules Heiko Voigt
2017-08-17 11:00 ` Heiko Voigt [this message]
2017-08-17 17:24   ` [RFC PATCH 2/2] submodule: simplify decision tree whether to or not to fetch Stefan Beller
2017-08-17 17:50     ` Brandon Williams
2017-08-18 16:06       ` Heiko Voigt
2017-08-17 17:20 ` [RFC PATCH 1/2] implement fetching of moved submodules Stefan Beller
2017-08-18 16:06   ` Heiko Voigt
2017-09-15 13:18 ` [RFC PATCH v2 " Heiko Voigt
2017-09-15 13:20   ` [RFC PATCH v2 2/2] submodule: simplify decision tree whether to or not to fetch Heiko Voigt
2017-09-18 16:47     ` Brandon Williams
2017-09-18 16:49   ` [RFC PATCH v2 1/2] implement fetching of moved submodules Brandon Williams

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170817110013.GD52233@book.hvoigt.net \
    --to=hvoigt@hvoigt.net \
    --cc=Jens.Lehmann@web.de \
    --cc=bmwill@google.com \
    --cc=git@vger.kernel.org \
    --cc=jrnieder@gmail.com \
    --cc=sbeller@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.