Re: [PATCH 1/1] checkout: add simple check for 'git checkout -b'

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux