All of lore.kernel.org
 help / color / mirror / Atom feed
From: Denton Liu <liu.denton@gmail.com>
To: Shourya Shukla <shouryashukla.oo@gmail.com>
Cc: git@vger.kernel.org, christian.couder@gmail.com, peff@peff.net,
	heba.waly@gmail.com, gitster@pobox.com
Subject: Re: [PATCH v2] submodule: port subcommand 'set-url' from shell to C
Date: Fri, 1 May 2020 06:01:09 -0400	[thread overview]
Message-ID: <20200501100109.GA55820@generichostname> (raw)
In-Reply-To: <20200501073232.18409-1-shouryashukla.oo@gmail.com>

Hi Shourya,

I ran into a few whitespace errors when applying this patch. You should
run `git diff --check` before committing so that you can fix these.

On Fri, May 01, 2020 at 01:02:32PM +0530, Shourya Shukla wrote:
> This aims to convert submodule subcommand 'set-url' to a builtin.
> 'set-url' is ported to 'submodule--helper.c' and the latter is called
> via 'git-submodule.sh'.

Commit messages should be written in imperative mood. This could be
rewritten as

	Convert submodule subcommand 'set-url' to a builtin. Port
	'set-url' to 'submodule--helper.c' and call the latter via
	'git-submodule.sh'.

> 'module_set_url()' accepts the the user input, which is parsed by

s/the the/the/

> 'parse_options()', followed by the setting of the appropriate entry
> (i.e., the submodule URL here). Finally, the URL is synced, via
> 'sync_submodule()', with the upstream.

Others might disagree with me but I believe that this paragraph dives
in too deeply. It might be more helpful to give a higher level overview
than repeating what the code.

> Signed-off-by: Shourya Shukla <shouryashukla.oo@gmail.com>
> ---
> I finally fixed the implementation, was making a silly mistake.
> The test './t7420-submodule-set-url.sh' passes (both tests 1 and 2
> are successful now). I have deleted the function,
> 'update_url_in_gitmodules()' because I was able to suffice that
> functionality in the 'module_set_url()' function itself.
> 
> Thank you so much Christian and Denton for helping me :)

No problem :)

>  builtin/submodule--helper.c | 55 +++++++++++++++++++++++++++++++++++++
>  git-submodule.sh            | 25 ++---------------
>  2 files changed, 58 insertions(+), 22 deletions(-)
> 
> diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
> index 1a4b391c88..59334d4286 100644
> --- a/builtin/submodule--helper.c
> +++ b/builtin/submodule--helper.c
> @@ -2246,6 +2246,60 @@ static int module_config(int argc, const char **argv, const char *prefix)
>  	usage_with_options(git_submodule_helper_usage, module_config_options);
>  }
>  
> +struct set_url_cb {
> +	const char *prefix;
> +	unsigned int flags;
> +};
> +
> +#define SET_URL_CB_INIT { NULL, 0 }
> +
> +static int module_set_url(int argc, const char **argv, const char *prefix)
> +{
> +	struct set_url_cb info = SET_URL_CB_INIT;
> +	int quiet = 0;
> +
> +	const char *newurl = NULL;
> +	const char *path = NULL;
> +	
> +	struct strbuf entry = STRBUF_INIT;
> +
> +	struct option module_set_url_options[] = {
> +		OPT__QUIET(&quiet, N_("Suppress output for setting url of a submodule")),

I know that many options in the rest of the file don't follow this
convention but the help string should begin with a lowercase.

> +		OPT_END()
> +	};
> +
> +	const char *const git_submodule_helper_usage[] = {
> +		N_("git submodule--helper set-url [--quiet] [<path>] [<newurl>]"),

<path> and <newurl> should be mandatory arguments.

> +		NULL
> +	};
> +
> +	argc = parse_options(argc, argv, NULL, module_set_url_options,

How come you aren't passing in the prefix here?

> +			     git_submodule_helper_usage, 0);
> +
> +	info.prefix = prefix;
> +	if (quiet)
> +		info.flags |= OPT_QUIET;
> +

Over here, you should check argc to ensure that we have exactly two
arguments...

> +	path = argv[0];
> +	newurl = argv[1];

...otherwise this may segfault.

> +
> +	if(!path || !newurl){

nit: space after `if` and betwen `) {`. Also, this won't be necessary
once you check the argc.

> +		usage_with_options(git_submodule_helper_usage,module_set_url_options);

nit: space after the `,`

> +		return 1;
> +	}
> +
> +	strbuf_addstr(&entry, "submodule.");
> +	strbuf_addstr(&entry, path);
> +	strbuf_addstr(&entry, ".url");
> +	
> +	/* Setting the new URL in .gitmodules */

I don't think these comments are necessary. It's pretty obvious what's
happening in the code.

> +	config_set_in_gitmodules_file_gently(entry.buf, newurl);  
> +	/* Syncing the updated URL */
> +	sync_submodule(path, prefix, info.flags);
> +

Make sure you strbuf_release() the strbuf here.

> +	return 0;
> +}
> +
>  #define SUPPORT_SUPER_PREFIX (1<<0)
>  
>  struct cmd_struct {
> @@ -2276,6 +2330,7 @@ static struct cmd_struct commands[] = {
>  	{"is-active", is_active, 0},
>  	{"check-name", check_name, 0},
>  	{"config", module_config, 0},
> +	{"set-url", module_set_url, 0},
>  };
>  
>  int cmd_submodule__helper(int argc, const char **argv, const char *prefix)
> diff --git a/git-submodule.sh b/git-submodule.sh
> index 89f915cae9..ea72d5a5f5 100755
> --- a/git-submodule.sh
> +++ b/git-submodule.sh
> @@ -783,11 +783,13 @@ cmd_set_branch() {
>  # $@ = requested path, requested url
>  #
>  cmd_set_url() {
> +
>  	while test $# -ne 0
>  	do
>  		case "$1" in
>  		-q|--quiet)
>  			GIT_QUIET=1
> +			shift
>  			;;
>  		--)
>  			shift
> @@ -800,30 +802,9 @@ cmd_set_url() {
>  			break
>  			;;
>  		esac
> -		shift

Hmmm, I don't understand why the above hunk and this line are necessary.

>  	done
>  
> -	if test $# -ne 2
> -	then
> -		usage
> -	fi
> -
> -	# we can't use `git submodule--helper name` here because internally, it
> -	# hashes the path so a trailing slash could lead to an unintentional no match
> -	name="$(git submodule--helper list "$1" | cut -f2)"
> -	if test -z "$name"
> -	then
> -		exit 1
> -	fi
> -
> -	url="$2"
> -	if test -z "$url"
> -	then
> -		exit 1
> -	fi
> -
> -	git submodule--helper config submodule."$name".url "$url"
> -	git submodule--helper sync ${GIT_QUIET:+--quiet} "$name"
> +	git ${wt_prefix:+-C "$wt_prefix"} ${prefix:+--super-prefix "$prefix"} submodule--helper set-url ${GIT_QUIET:+--quiet} -- "$@"

This looks good, though :)

Thanks,

Denton

>  }
>  
>  #
> -- 
> 2.26.2
> 

  reply	other threads:[~2020-05-01 10:01 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-01  7:32 [PATCH v2] submodule: port subcommand 'set-url' from shell to C Shourya Shukla
2020-05-01 10:01 ` Denton Liu [this message]
2020-05-01 18:54   ` Junio C Hamano
2020-05-01 18:27 ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200501100109.GA55820@generichostname \
    --to=liu.denton@gmail.com \
    --cc=christian.couder@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=heba.waly@gmail.com \
    --cc=peff@peff.net \
    --cc=shouryashukla.oo@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.