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

[GSoC][PATCH 1/5 v3] submodule--helper: introduce get_submodule_displaypath()

From
Prathamesh Chavan <pc44800@gmail.com>
Date
Jun 30, 2017, 19:47 UTC
Message-ID
<20170630194727.29787-1-pc44800@gmail.com>
In-Reply-To
<CAME+mvUrr8EA-6jbCZdpB7dMZ5CN3RyY7yoRoUBoiZw=sH6Ysw@mail.gmail.com>

Introduce function get_submodule_displaypath() to replace the code occurring in submodule_init() for generating displaypath of the submodule with a call to it.

This new function will also be used in other parts of the system in later patches.

Mentored-by: Christian Couder <christian.couder@gmail.com>
Mentored-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Prathamesh Chavan <pc44800@gmail.com>
---
The patch series is updated, and is based on 'master' branch.

This patch series contains updates patches about Introduction of the function: get_submodule_displaypath() (This patch wasn't posted in the last update by mistake) Introduction of the function: for_each_submodule() Port shell function set_name_rev() to C Port submodule subcommand 'status' from shell to C Port submodule subcommand 'sync' from shell to C

Complete build report of this patch-series is available at:
https://travis-ci.org/pratham-pc/git/builds
Branch: patch-series-1
Build #114
Also, the above series was also build by basing it on the 'next'
branch for the purpose of testing the code.
Since the function is_submodule_initialized changed to
is_submodule_active, this change was required to be added in the
above patches while basing it on next.
After doing the required changes,
Complete build report of the above is available at:
https://travis-ci.org/pratham-pc/git/builds
Branch: patch-series-1-next
Build #116

I have held back the following patch since some work is still required to be done: Port submodule subcommand 'foreach' from shell to C Port submodule subcommand 'deinit' from shell to C Port submodule subcommand 'summary' from shell to C I hope to complete this and post these patches later with the weekly updates.

 builtin/submodule--helper.c | 33 ++++++++++++++++++++++-----------
 1 file changed, 22 insertions(+), 11 deletions(-)
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 8517032b3..1bfc91bca 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -220,6 +220,27 @@ static int resolve_relative_url_test(int argc, const char **argv, const char *pr
 	return 0;
 }
 
+static char *get_submodule_displaypath(const char *path, const char *prefix)
+{
+	const char *super_prefix = get_super_prefix();
+
+	if (prefix && super_prefix) {
+		BUG("cannot have prefix '%s' and superprefix '%s'",
+		    prefix, super_prefix);
+	} else if (prefix) {
+		struct strbuf sb = STRBUF_INIT;
+		char *displaypath = xstrdup(relative_path(path, prefix, &sb));
+		strbuf_release(&sb);
+		return displaypath;
+	} else if (super_prefix) {
+		int len = strlen(super_prefix);
+		const char *format = is_dir_sep(super_prefix[len - 1]) ? "%s%s" : "%s/%s";
+		return xstrfmt(format, super_prefix, path);
+	} else {
+		return xstrdup(path);
+	}
+}
+
 struct module_list {
 	const struct cache_entry **entries;
 	int alloc, nr;
@@ -339,16 +360,7 @@ static void init_submodule(const char *path, const char *prefix, int quiet)
 
 	/* Only loads from .gitmodules, no overlay with .git/config */
 	gitmodules_config();
-
-	if (prefix && get_super_prefix())
-		die("BUG: cannot have prefix and superprefix");
-	else if (prefix)
-		displaypath = xstrdup(relative_path(path, prefix, &sb));
-	else if (get_super_prefix()) {
-		strbuf_addf(&sb, "%s%s", get_super_prefix(), path);
-		displaypath = strbuf_detach(&sb, NULL);
-	} else
-		displaypath = xstrdup(path);
+	displaypath = get_submodule_displaypath(path, prefix);
 
 	sub = submodule_from_path(null_sha1, path);
 
@@ -363,7 +375,6 @@ static void init_submodule(const char *path, const char *prefix, int quiet)
 	 * Set active flag for the submodule being initialized
 	 */
 	if (!is_submodule_initialized(path)) {
-		strbuf_reset(&sb);
 		strbuf_addf(&sb, "submodule.%s.active", sub->name);
 		git_config_set_gently(sb.buf, "true");
 	}
-- 
2.13.0
Previous: Prathamesh ChavanNext: Prathamesh Chavan
Message 13 of 28 in “[GSoC] Update: Week 6”
  1. Prathamesh ChavanJun 26, 2017
  2. [GSoC][PATCH 1/6 v2] submodule--helper: introduce for_each_submodule_listPrathamesh Chavan, Jun 26, 2017
  3. [GSoC][PATCH 2/6 v2] submodule: port subcommand foreach from shell to CPrathamesh Chavan, Jun 26, 2017
  4. Christian CouderJun 27, 2017
  5. [GSoC][PATCH 3/6 v2] submodule: port set_name_rev from shell to CPrathamesh Chavan, Jun 26, 2017
  6. [GSoC][PATCH 6/6 v2] submodule: port submodule subcommand 'deinit' from shell to CPrathamesh Chavan, Jun 26, 2017
  7. Christian CouderJun 27, 2017
  8. [GSoC][PATCH 4/6 v2] submodule: port submodule subcommand statusPrathamesh Chavan, Jun 26, 2017
  9. [GSoC][PATCH 5/6 v2] submodule: port submodule subcommand sync from shell to CPrathamesh Chavan, Jun 26, 2017
  10. Christian CouderJun 27, 2017
  11. Junio C HamanoJun 28, 2017
  12. Prathamesh ChavanJun 29, 2017
  13. [GSoC][PATCH 1/5 v3] submodule--helper: introduce get_submodule_displaypath()Prathamesh Chavan, Jun 30, 2017
  14. [GSoC][PATCH 5/5 v3] submodule: port submodule subcommand 'sync' from shell to CPrathamesh Chavan, Jun 30, 2017
  15. Stefan BellerJun 30, 2017
  16. Junio C HamanoJun 30, 2017
  17. [GSoC][PATCH 2/5 v3] submodule--helper: introduce for_each_submodule_list()Prathamesh Chavan, Jun 30, 2017
  18. [GSoC][PATCH 4/5 v3] submodule: port submodule subcommand 'status' from shell to CPrathamesh Chavan, Jun 30, 2017
  19. Junio C HamanoJun 30, 2017
  20. [GSoC][PATCH 3/5 v3] submodule: port set_name_rev() from shell to CPrathamesh Chavan, Jun 30, 2017
  21. Junio C HamanoJun 30, 2017
  22. Junio C HamanoJun 30, 2017
  23. [GSoC][PATCH 1/5 v4] submodule--helper: introduce get_submodule_displaypath()Prathamesh Chavan, Jul 13, 2017
  24. [GSoC][PATCH 2/5 v4] submodule--helper: introduce for_each_submodule_list()Prathamesh Chavan, Jul 13, 2017
  25. [GSoC][PATCH 3/5 v4] submodule: port set_name_rev() from shell to CPrathamesh Chavan, Jul 13, 2017
  26. [GSoC][PATCH 4/5 v4] submodule: port submodule subcommand 'status' from shell to CPrathamesh Chavan, Jul 13, 2017
  27. Stefan BellerJul 13, 2017
  28. [GSoC][PATCH 5/5 v4] submodule: port submodule subcommand 'sync' from shell to CPrathamesh Chavan, Jul 13, 2017

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.