From: Shourya Shukla <shouryashukla.oo@gmail.com>
To: Denton Liu <liu.denton@gmail.com>
Cc: git@vger.kernel.org, christian.couder@gmail.com,
kaartic.sivaraam@gmail.com, gitster@pobox.com
Subject: Re: [PATCH 1/2] submodule: port subcommand 'set-branch' from shell to C
Date: Sat, 16 May 2020 16:07:44 +0530 [thread overview]
Message-ID: <20200516103744.GA25211@konoha> (raw)
In-Reply-To: <20200514101013.GA28018@generichostname>
On 14/05 06:10, Denton Liu wrote:
> > + 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!
> > + 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?
> > +
> > + 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!
> 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
next prev parent reply other threads:[~2020-05-16 10:38 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-13 20:17 [PATCH 1/2] submodule: port subcommand 'set-branch' from shell to C Shourya Shukla
2020-05-13 20:17 ` [PATCH 2/2] submodule: Add 'quiet' option in subcommand 'set-branch' Shourya Shukla
2020-05-14 10:15 ` Denton Liu
2020-05-16 5:50 ` Shourya Shukla
2020-05-16 8:56 ` Denton Liu
2020-05-16 10:40 ` Shourya Shukla
2020-05-16 11:06 ` Denton Liu
2020-05-14 9:07 ` [PATCH 1/2] submodule: port subcommand 'set-branch' from shell to C Kaartic Sivaraam
2020-05-17 15:06 ` Junio C Hamano
2020-05-17 15:21 ` Kaartic Sivaraam
2020-05-14 10:10 ` Denton Liu
2020-05-16 10:37 ` Shourya Shukla [this message]
2020-05-16 10:55 ` Denton Liu
2020-05-17 16:11 ` Đoàn Trần Công Danh
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200516103744.GA25211@konoha \
--to=shouryashukla.oo@gmail.com \
--cc=christian.couder@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=kaartic.sivaraam@gmail.com \
--cc=liu.denton@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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).