git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 3/7] submodule: is_submodule_active to differentiate between new and old mode

From
Stefan Beller <sbeller@google.com>
Date
Aug 16, 2018, 02:30 UTC
Message-ID
<20180816023100.161626-4-sbeller@google.com>
In-Reply-To
<20180816023100.161626-1-sbeller@google.com>

The change a086f921a72 (submodule: decouple url and submodule interest, 2017-03-17) enables us to do more than originally thought. As the url setting was used both to actually set the url where to obtain the submodule from, as well as used as a boolean flag later to see if it was active, we would need to keep the url around.

Now that submodules can be activated using the submodule.[<name>.]active setting, we could remove the url if the submodule is activated via that setting.

In preparation to do so, pave the way by providing an easy way to see if a submodule is considered active via the new .active setting or via the old .url setting.

Signed-off-by: Stefan Beller <sbeller@google.com>
---
 submodule.c | 5 +----
 submodule.h | 6 ++++++
 2 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/submodule.c b/submodule.c
index 6e14547e9e0..d56350ed094 100644
--- a/submodule.c
+++ b/submodule.c
@@ -221,9 +221,6 @@ int option_parse_recurse_submodules_worktree_updater(const struct option *opt,
 	return 0;
 }
 
-/*
- * Determine if a submodule has been initialized at a given 'path'
- */
 int is_submodule_active(struct repository *repo, const char *path)
 {
 	int ret = 0;
@@ -267,7 +264,7 @@ int is_submodule_active(struct repository *repo, const char *path)
 
 	/* fallback to checking if the URL is set */
 	key = xstrfmt("submodule.%s.url", module->name);
-	ret = !repo_config_get_string(repo, key, &value);
+	ret = !repo_config_get_string(repo, key, &value) ? 2 : 0;
 
 	free(value);
 	free(key);
diff --git a/submodule.h b/submodule.h
index 4644683e6cb..bfc070e4629 100644
--- a/submodule.h
+++ b/submodule.h
@@ -45,6 +45,12 @@ extern int git_default_submodule_config(const char *var, const char *value, void
 struct option;
 int option_parse_recurse_submodules_worktree_updater(const struct option *opt,
 						     const char *arg, int unset);
+/*
+ * Determine if a submodule has been initialized at a given 'path'.
+ * Returns 1 if it is considered active via the submodule.[<name>.]active
+ * setting, or return 2 if it is active via the older submodule.url setting.
+ */
+#define SUBMODULE_ACTIVE_VIA_URL 2
 extern int is_submodule_active(struct repository *repo, const char *path);
 /*
  * Determine if a submodule has been populated at a given 'path' by checking if
-- 
2.18.0.265.g16de1b435c9.dirty
Previous: Stefan BellerNext: Junio C Hamano
Message 5 of 14 in “Unset the submodule URL in the superproject when no longer needed”
  1. 0/7 Unset the submodule URL in the superproject when no longer neededStefan Beller, Aug 16, 2018
  2. 1/7 t7410: update to new styleStefan Beller, Aug 16, 2018
  3. Junio C HamanoAug 16, 2018
  4. 2/7 builtin/submodule--helper: remove stray new lineStefan Beller, Aug 16, 2018
  5. 3/7 submodule: is_submodule_active to differentiate between new and old modeStefan Beller, Aug 16, 2018
  6. Junio C HamanoAug 16, 2018
  7. Stefan BellerAug 20, 2018
  8. Junio C HamanoAug 21, 2018
  9. 4/7 submodule sync: omit setting submodule URL in config if possibleStefan Beller, Aug 16, 2018
  10. 5/7 submodule--helper: factor out allocation of callback cookieStefan Beller, Aug 16, 2018
  11. 6/7 submodule--helper, update_clone: store index to update_clone instead of ceStefan Beller, Aug 16, 2018
  12. 7/7 builtin/submodule--helper: unset submodule url if possibleStefan Beller, Aug 16, 2018
  13. Junio C HamanoAug 16, 2018
  14. Stefan BellerAug 16, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.