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