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

[PATCHv3 2/5] submodule--helper list: lose the extra prefix option

From
Stefan Beller <sbeller@google.com>
Date
Mar 25, 2016, 18:39 UTC
Message-ID
<1458931156-29125-3-git-send-email-sbeller@google.com>
In-Reply-To
<1458931156-29125-1-git-send-email-sbeller@google.com>

The usual early machinery of Git is to change the directory to the top level of the working tree and pass the actual path inside the working tree as `prefix` to the command being run. This is the case both for commands written in C (where the prefix is passed into the command in a function parameter) as well as in git-submodule.sh where the setup code runs

  wt_prefix=$(git rev-parse show-prefix)
  cd_to_top_level

So the prefix passed into the `submodule--helper list` is actually the relative path inside the working tree, but we were not using the standard way of passing it through.

Adhere to Gits standard of passing the relative path inside the working tree by passing it via -C. This is more readable for future readers of the code.

We do not need to pass it for `submodule foreach` as that command doesn't take further arguments ('$@') to operate on a subset of submodules, such that it is irrelevant for listing the submodules. The computation of the displaypath ('Entering <path>') is done separately there.

Signed-off-by: Stefan Beller <sbeller@google.com>
---
 builtin/submodule--helper.c |  5 +----
 git-submodule.sh            | 12 ++++++------
 2 files changed, 7 insertions(+), 10 deletions(-)
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 5295b72..6c3ff91 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -68,14 +68,11 @@ static int module_list(int argc, const char **argv, const char *prefix)
 	struct module_list list = MODULE_LIST_INIT;
 
 	struct option module_list_options[] = {
-		OPT_STRING(0, "prefix", &prefix,
-			   N_("path"),
-			   N_("alternative anchor for relative paths")),
 		OPT_END()
 	};
 
 	const char *const git_submodule_helper_usage[] = {
-		N_("git submodule--helper list [--prefix=<path>] [<path>...]"),
+		N_("git submodule--helper list [<path>...]"),
 		NULL
 	};
 
diff --git a/git-submodule.sh b/git-submodule.sh
index d83608c..2dd1b18 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -407,7 +407,7 @@ cmd_foreach()
 	# command in the subshell (and a recursive call to this function)
 	exec 3<&0
 
-	git submodule--helper list --prefix "$wt_prefix"|
+	git submodule--helper list |
 	while read mode sha1 stage sm_path
 	do
 		die_if_unmatched "$mode"
@@ -467,7 +467,7 @@ cmd_init()
 		shift
 	done
 
-	git submodule--helper list --prefix "$wt_prefix" "$@" |
+	git -C "$wt_prefix" submodule--helper list "$@" |
 	while read mode sha1 stage sm_path
 	do
 		die_if_unmatched "$mode"
@@ -549,7 +549,7 @@ cmd_deinit()
 		die "$(eval_gettext "Use '.' if you really want to deinitialize all submodules")"
 	fi
 
-	git submodule--helper list --prefix "$wt_prefix" "$@" |
+	git -C "$wt_prefix" submodule--helper list "$@" |
 	while read mode sha1 stage sm_path
 	do
 		die_if_unmatched "$mode"
@@ -683,7 +683,7 @@ cmd_update()
 	fi
 
 	cloned_modules=
-	git submodule--helper list --prefix "$wt_prefix" "$@" | {
+	git -C "$wt_prefix" submodule--helper list "$@" | {
 	err=
 	while read mode sha1 stage sm_path
 	do
@@ -1121,7 +1121,7 @@ cmd_status()
 		shift
 	done
 
-	git submodule--helper list --prefix "$wt_prefix" "$@" |
+	git -C "$wt_prefix" submodule--helper list "$@" |
 	while read mode sha1 stage sm_path
 	do
 		die_if_unmatched "$mode"
@@ -1199,7 +1199,7 @@ cmd_sync()
 		esac
 	done
 	cd_to_toplevel
-	git submodule--helper list --prefix "$wt_prefix" "$@" |
+	git -C "$wt_prefix" submodule--helper list "$@" |
 	while read mode sha1 stage sm_path
 	do
 		die_if_unmatched "$mode"
-- 
2.8.0.rc4.10.g52f3f33.dirty
Previous: Junio C HamanoNext: Stefan Beller
Message 4 of 15 in “[PATCHv3 0/5] submodule helper: cleanup prefix passing”
  1. Stefan BellerMar 25, 2016
  2. 1/5 submodule: prepare recursive path from non root directoryStefan Beller, Mar 25, 2016
  3. Junio C HamanoMar 25, 2016
  4. 2/5 submodule--helper list: lose the extra prefix optionStefan Beller, Mar 25, 2016
  5. 3/5 submodule update: add test for recursive from non root dirStefan Beller, Mar 25, 2016
  6. 4/5 submodule sync: test syncing one submoduleStefan Beller, Mar 25, 2016
  7. 5/5 submodule--helper clone: lose the extra prefix optionStefan Beller, Mar 25, 2016
  8. Junio C HamanoMar 25, 2016
  9. Junio C HamanoMar 25, 2016
  10. Stefan BellerMar 25, 2016
  11. Junio C HamanoMar 25, 2016
  12. Stefan BellerMar 25, 2016
  13. Junio C HamanoMar 25, 2016
  14. Stefan BellerMar 25, 2016
  15. Junio C HamanoMar 28, 2016

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.