Re: [PATCH v3 5/5] sparse-checkout: reject arguments in cone-mode that look like patterns
- From
Elijah Newren <newren@gmail.com>
- Date
- Feb 17, 2022, 01:46 UTC
- Message-ID
- <CABPp-BH2Jy8esb52JBZvFOk9CcBMk41oDzDZX6t3G+M9tiao4w@mail.gmail.com>
- In-Reply-To
- <xmqqpmnmsl2n.fsf@gitster.g>
On Wed, Feb 16, 2022 at 10:49 AM Junio C Hamano <gitster@pobox.com> wrote:
Show 18 quoted lines
>
> Victoria Dye <vdye@github.com> writes:
>
> >> I considered strtok, but strtok & strtok_r are documented as modifying
> >> their argument. Perhaps they don't modify the argument if they don't
> >> find any of the listed tokens, but I didn't want to rely on that since
> >> I found no guarantees in the documentation.
> >
> > Maybe `strpbrk` would work? Unless I'm misunderstanding, it should
> > consolidate the condition to one line without potentially modifying the
> > arguments. E.g.:
> >
> > if (!strpbrk(argv[i], "*?[]"))
> > die(_("specify directories rather than patterns. If your directory really has any of '*?[]' in it, pass --skip-checks"));
>
> Yes, either that or strspn() are good match for the problem (I
> suspect Ævar actually meant strspn() not strtok() in the first
> place, though ;-).After reading up on it, I think you mean strcspn() rather than strspn(), yes? Either way, strpbrk() seems more direct to me, so I'll use it.