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

[PATCH] submodule: fix NULL correctness in renamed broken submodules

From
Stefan Beller <sbeller@google.com>
Date
Jun 14, 2018, 17:31 UTC
Message-ID
<20180614173107.201885-1-sbeller@google.com>
In-Reply-To
<CACsJy8Ab3HoVWSWOtCBRYcsnnHnpO-2oEfV60f=H15RuzwpWwQ@mail.gmail.com>

When fetching with recursing into submodules, the fetch logic inspects the superproject which submodules actually need to be fetched. This is tricky for submodules that were renamed in the fetched range of commits. This was implemented in c68f8375760 (implement fetching of moved submodules, 2017-10-16), and this patch fixes a mistake in the logic there.

When the warning is printed, the `name` might be NULL as default_name_or_path can return NULL, so fix the warning to use the path as obtained from the diff machinery, as that is not NULL.

While at it, make sure we only attempt to load the submodule if a git directory of the submodule is found as default_name_or_path will return NULL in case the git directory cannot be found. Note that passing NULL to submodule_from_name is just a semantic error, as submodule_from_name accepts NULL as a value, but then the return value is not the submodule that was asked for, but some arbitrary other submodule. (Cf. 'config_from' in submodule-config.c: "If any parameter except the cache is a NULL pointer just return the first submodule. Can be used to check whether there are any submodules parsed.")

Reported-by: Duy Nguyen <pclouds@gmail.com>
Helped-by: Duy Nguyen <pclouds@gmail.com>
Helped-by: Heiko Voigt <hvoigt@hvoigt.net>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 submodule.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/submodule.c b/submodule.c
index 939d6870ecd..0998ea23458 100644
--- a/submodule.c
+++ b/submodule.c
@@ -740,12 +740,14 @@ static void collect_changed_submodules_cb(struct diff_queue_struct *q,
 		else {
 			name = default_name_or_path(p->two->path);
 			/* make sure name does not collide with existing one */
-			submodule = submodule_from_name(the_repository, commit_oid, name);
+			if (name)
+				submodule = submodule_from_name(the_repository,
+								commit_oid, name);
 			if (submodule) {
 				warning("Submodule in commit %s at path: "
 					"'%s' collides with a submodule named "
 					"the same. Skipping it.",
-					oid_to_hex(commit_oid), name);
+					oid_to_hex(commit_oid), p->two->path);
 				name = NULL;
 			}
 		}
-- 
2.18.0.rc1.244.gcf134e6275-goog
Previous: Duy NguyenNext: Stefan Beller
Message 7 of 12 in “BUG: submodule code prints '(null)'”
  1. Duy NguyenJun 5, 2018
  2. Kaartic SivaraamJun 6, 2018
  3. Duy NguyenJun 9, 2018
  4. Stefan BellerJun 11, 2018
  5. Heiko VoigtJun 14, 2018
  6. Duy NguyenJun 14, 2018
  7. submodule: fix NULL correctness in renamed broken submodulesStefan Beller, Jun 14, 2018
  8. t5526: test recursive submodules when fetching moved submodulesStefan Beller, Jun 14, 2018
  9. Heiko VoigtJun 14, 2018
  10. Heiko VoigtJun 14, 2018
  11. Kaartic SivaraamJun 17, 2018
  12. Stefan BellerJun 12, 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.