diff mbox series

submodule: drop unused sm_name parameter from show_fetch_remotes()

Message ID YPqkHs47VDFBNZ0Z@coredump.intra.peff.net (mailing list archive)
State Accepted
Commit 7d315a0f67f9b1894b6a5e2200e3f66aea0c9776
Headers show
Series submodule: drop unused sm_name parameter from show_fetch_remotes() | expand

Commit Message

Jeff King July 23, 2021, 11:12 a.m. UTC
On Sat, Jul 10, 2021 at 01:18:01PM +0530, Atharva Raykar wrote:

> +static void show_fetch_remotes(FILE *output, const char *sm_name, const char *git_dir_path)
> +{
> +	struct child_process cp_remote = CHILD_PROCESS_INIT;
> +	struct strbuf sb_remote_out = STRBUF_INIT;
> +
> +	cp_remote.git_cmd = 1;
> +	strvec_pushf(&cp_remote.env_array,
> +		     "GIT_DIR=%s", git_dir_path);
> +	strvec_push(&cp_remote.env_array, "GIT_WORK_TREE=.");
> +	strvec_pushl(&cp_remote.args, "remote", "-v", NULL);
> +	if (!capture_command(&cp_remote, &sb_remote_out, 0)) {
> +		char *next_line;
> +		char *line = sb_remote_out.buf;
> +		while ((next_line = strchr(line, '\n')) != NULL) {
> +			size_t len = next_line - line;
> +			if (strip_suffix_mem(line, &len, " (fetch)"))
> +				fprintf(output, "  %.*s\n", (int)len, line);
> +			line = next_line + 1;
> +		}
> +	}
> +
> +	strbuf_release(&sb_remote_out);
> +}

The sm_name parameter is not used here. I don't think it's a bug; we
just don't need it (there's a message that mentions the name, but it
happens right before we call the function). Maybe this should go on top
of ar/submodule-add?

-- >8 --
Subject: submodule: drop unused sm_name parameter from show_fetch_remotes()

This parameter has not been used since the function was introduced in
8c8195e9c3 (submodule--helper: introduce add-clone subcommand,
2021-07-10).

Signed-off-by: Jeff King <peff@peff.net>
---
 builtin/submodule--helper.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

Comments

Atharva Raykar July 23, 2021, 5:12 p.m. UTC | #1
On 23-Jul-2021, at 16:42, Jeff King <peff@peff.net> wrote:
> 
> On Sat, Jul 10, 2021 at 01:18:01PM +0530, Atharva Raykar wrote:
> 
>> +static void show_fetch_remotes(FILE *output, const char *sm_name, const char *git_dir_path)
>> +{
>> +	struct child_process cp_remote = CHILD_PROCESS_INIT;
>> +	struct strbuf sb_remote_out = STRBUF_INIT;
>> +
>> +	cp_remote.git_cmd = 1;
>> +	strvec_pushf(&cp_remote.env_array,
>> +		     "GIT_DIR=%s", git_dir_path);
>> +	strvec_push(&cp_remote.env_array, "GIT_WORK_TREE=.");
>> +	strvec_pushl(&cp_remote.args, "remote", "-v", NULL);
>> +	if (!capture_command(&cp_remote, &sb_remote_out, 0)) {
>> +		char *next_line;
>> +		char *line = sb_remote_out.buf;
>> +		while ((next_line = strchr(line, '\n')) != NULL) {
>> +			size_t len = next_line - line;
>> +			if (strip_suffix_mem(line, &len, " (fetch)"))
>> +				fprintf(output, "  %.*s\n", (int)len, line);
>> +			line = next_line + 1;
>> +		}
>> +	}
>> +
>> +	strbuf_release(&sb_remote_out);
>> +}
> 
> The sm_name parameter is not used here. I don't think it's a bug; we
> just don't need it (there's a message that mentions the name, but it
> happens right before we call the function). Maybe this should go on top
> of ar/submodule-add?
> 
> -- >8 --
> Subject: submodule: drop unused sm_name parameter from show_fetch_remotes()
> 
> This parameter has not been used since the function was introduced in
> 8c8195e9c3 (submodule--helper: introduce add-clone subcommand,
> 2021-07-10).
> 
> Signed-off-by: Jeff King <peff@peff.net>
> ---
> builtin/submodule--helper.c | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
> index ed4a50c78e..1e65ff599e 100644
> --- a/builtin/submodule--helper.c
> +++ b/builtin/submodule--helper.c
> @@ -2782,7 +2782,7 @@ struct add_data {
> };
> #define ADD_DATA_INIT { .depth = -1 }
> 
> -static void show_fetch_remotes(FILE *output, const char *sm_name, const char *git_dir_path)
> +static void show_fetch_remotes(FILE *output, const char *git_dir_path)
> {
> 	struct child_process cp_remote = CHILD_PROCESS_INIT;
> 	struct strbuf sb_remote_out = STRBUF_INIT;
> @@ -2833,8 +2833,7 @@ static int add_submodule(const struct add_data *add_data)
> 				fprintf(stderr, _("A git directory for '%s' is found "
> 						  "locally with remote(s):"),
> 					add_data->sm_name);
> -				show_fetch_remotes(stderr, add_data->sm_name,
> -						   submod_gitdir_path);
> +				show_fetch_remotes(stderr, submod_gitdir_path);
> 				free(submod_gitdir_path);
> 				die(_("If you want to reuse this local git "
> 				      "directory instead of cloning again from\n"
> -- 
> 2.32.0.784.g92e169d3d7
> 

Yes, this is definitely an oversight on my part, and it looks like this
topic has already made it to 'next'.

Thanks for the fix.
Junio C Hamano July 26, 2021, 7:03 p.m. UTC | #2
Atharva Raykar <raykar.ath@gmail.com> writes:

> Yes, this is definitely an oversight on my part, and it looks like this
> topic has already made it to 'next'.
>
> Thanks for the fix.

Thanks, both.
diff mbox series

Patch

diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index ed4a50c78e..1e65ff599e 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -2782,7 +2782,7 @@  struct add_data {
 };
 #define ADD_DATA_INIT { .depth = -1 }
 
-static void show_fetch_remotes(FILE *output, const char *sm_name, const char *git_dir_path)
+static void show_fetch_remotes(FILE *output, const char *git_dir_path)
 {
 	struct child_process cp_remote = CHILD_PROCESS_INIT;
 	struct strbuf sb_remote_out = STRBUF_INIT;
@@ -2833,8 +2833,7 @@  static int add_submodule(const struct add_data *add_data)
 				fprintf(stderr, _("A git directory for '%s' is found "
 						  "locally with remote(s):"),
 					add_data->sm_name);
-				show_fetch_remotes(stderr, add_data->sm_name,
-						   submod_gitdir_path);
+				show_fetch_remotes(stderr, submod_gitdir_path);
 				free(submod_gitdir_path);
 				die(_("If you want to reuse this local git "
 				      "directory instead of cloning again from\n"