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

Re: [PATCH 1/2] submodule: port subcommand 'set-branch' from shell to C

From
Shourya Shukla <shouryashukla.oo@gmail.com>
Date
May 16, 2020, 10:37 UTC
Message-ID
<20200516103744.GA25211@konoha>
In-Reply-To
<20200514101013.GA28018@generichostname>
On 14/05 06:10, Denton Liu wrote:
Show 10 quoted lines
> > +	const char *path;
> > +	char *config_name;
> > +
> > +	struct option options[] = {
> > +		OPT__QUIET(&quiet, N_("Suppress output for setting default tracking branch of a submodule")),
> > +		OPT_BOOL(0, "default", &opt_default, N_("Set the default tracking branch to master")),
> > +		OPT_BOOL(0, "branch", &opt_branch, N_("Set the default tracking branch to the one specified")),
> 
> This should use OPT_STRING and accept a string argument instead of using
> the implicit command-line ordering.

I actually was not able to understand the point of this change until I tried it out myself. It has made the code more aethetic as well as less redundant. Thanks a ton!

Show 15 quoted lines
> > +		OPT_END()
> > +	};
> > +	const char *const usage[] = {
> > +		N_("git submodule--helper set-branch [--quiet] (-d|--default) <path>"),
> > +		N_("git submodule--helper set-branch [--quiet] (-b|--branch) <branch> <path>"),
> > +		NULL
> > +	};
> > +
> > +	argc = parse_options(argc, argv, prefix, options, usage, 0);
> > +
> > +	if ((!opt_branch && !opt_default))
> > +		die(_("At least one of --branch and --default required"));
> 
> Error messages in Git are generally written without capitalising the
> first letter of the sentence.

Corrected. BTW, many other subcommands have this problem (the error messages as well as the options start with a caps and end with a fullstop). Should they be corrected or let them be as is?

Show 7 quoted lines
> > +
> > +	if (opt_branch) {
> > +		if (opt_default)
> > +			die(_("--branch and --default do not make sense"));
> 
> This error message should be qualified, perhaps with something like "do
> not make sense together".
Done!
Show 17 quoted lines
> The same arguments for the above apply to this case too. Actually, the
> only place where they both really differ is in the call to
> config_set_in_gitmodules_file_gently(). Can you do all of your argument
> checks together? Something like
> 
> 	if (!!new_branch == opt_default)
> 		usage_with_options(usage, options);
> 
> Then the call to config_set_in_gitmodules_file_gently() could look like
> this:
> 
> 	config_name = xstrfmt("submodule.%s.branch", path);
> 	config_set_in_gitmodules_file_gently(config_name, new_branch ? new_branch : NULL);
> 	free(config_name);
> 
> and we wouldn't need the ifs at all.
> 
Sure, I have made the changes.

Regards, Shourya Shukla

Previous: Denton LiuNext: Denton Liu
Message 12 of 14 in “submodule: port subcommand 'set-branch' from shell to C”
  1. 1/2 submodule: port subcommand 'set-branch' from shell to CShourya Shukla, May 13, 2020
  2. 2/2 submodule: Add 'quiet' option in subcommand 'set-branch'Shourya Shukla, May 13, 2020
  3. Denton LiuMay 14, 2020
  4. Shourya ShuklaMay 16, 2020
  5. Denton LiuMay 16, 2020
  6. Shourya ShuklaMay 16, 2020
  7. Denton LiuMay 16, 2020
  8. Kaartic SivaraamMay 14, 2020
  9. Junio C HamanoMay 17, 2020
  10. Kaartic SivaraamMay 17, 2020
  11. Denton LiuMay 14, 2020
  12. Shourya ShuklaMay 16, 2020
  13. Denton LiuMay 16, 2020
  14. Đoàn Trần Công DanhMay 17, 2020

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.