From: Pratyush Yadav <me@yadavpratyush.com>
To: Derrick Stolee <stolee@gmail.com>
Cc: phillip.wood@dunelm.org.uk,
Derrick Stolee via GitGitGadget <gitgitgadget@gmail.com>,
git@vger.kernel.org, Junio C Hamano <gitster@pobox.com>,
Derrick Stolee <dstolee@microsoft.com>
Subject: Re: [PATCH 1/1] checkout: add simple check for 'git checkout -b'
Date: Fri, 30 Aug 2019 03:10:14 +0530 [thread overview]
Message-ID: <20190829214014.vijdotp4g65a5mk3@yadavpratyush.com> (raw)
In-Reply-To: <20190829203037.vzxuaxpsghbdc6vl@yadavpratyush.com>
On 30/08/19 02:00AM, Pratyush Yadav wrote:
> On 29/08/19 04:07PM, Derrick Stolee wrote:
> > On 8/29/2019 2:54 PM, Phillip Wood wrote:
> > > Hi Stolee
> > >
> > > On 29/08/2019 18:01, Derrick Stolee via GitGitGadget wrote:
> > >> +
> > >> + if (argc == 3 && !strcmp(argv[1], "-b")) {
> > >> + /*
> > >> + * User ran 'git checkout -b <branch>' and expects
> > >
> > > What if the user ran 'git checkout -b<branch>'? Then argc == 2.
> >
> > Good catch. I'm tempted to say "don't do that" to keep this
> > simple. They won't have incorrect results, just slower than
> > the "with space" option.
> >
> > However, if there is enough interest in correcting the "-b<branch>"
> > case, then I can make another attempt at this.
>
> You can probably do this with:
>
> !strncmp(argv[1], "-b", 2)
>
> The difference is so little, might as well do it IMO.
Actually, that is not correct. I took a quick look before writing this
and missed the fact that argc == 3 is the bigger problem.
Thinking a little more about this, you can mix other options with
checkout -b, like --track. You can also specify <start_point>.
Now I don't know enough about this optimization you are doing to know
whether we need to optimize when these options are given, but at least
for --track I don't see any reason not to.
So maybe you are better off using something like getopt() (warning:
getopt modifies the input string so you probably want to duplicate it)
if you want to support all cases. Though for this simple case you can
probably get away by just directly scanning the argv list for "-b"
(using strncmp instead of strcmp to account for "-b<branch-name>)
--
Regards,
Pratyush Yadav
next prev parent reply other threads:[~2019-08-29 21:40 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-29 17:01 [PATCH 0/1] checkout: add simple check for 'git checkout -b' Derrick Stolee via GitGitGadget
2019-08-29 17:01 ` [PATCH 1/1] " Derrick Stolee via GitGitGadget
2019-08-29 17:25 ` Elijah Newren
2019-08-29 18:54 ` Phillip Wood
2019-08-29 20:07 ` Derrick Stolee
2019-08-29 20:30 ` Pratyush Yadav
2019-08-29 21:40 ` Pratyush Yadav [this message]
2019-08-30 0:19 ` Elijah Newren
2019-08-30 0:43 ` Taylor Blau
2019-08-30 16:56 ` Derrick Stolee
2019-08-30 17:18 ` 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
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=20190829214014.vijdotp4g65a5mk3@yadavpratyush.com \
--to=me@yadavpratyush.com \
--cc=dstolee@microsoft.com \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.com \
--cc=gitster@pobox.com \
--cc=phillip.wood@dunelm.org.uk \
--cc=stolee@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).