Re: [RFC PATCH v1 1/2] pathspec: warn: long and short forms are incompatible
- From
- Stavros Ntentos <stdedos@gmail.com>
- Date
- Mar 28, 2021, 15:44 UTC
- Message-ID
- <20210328154432.23434-1-133706+stdedos@users.noreply.github.com>
- In-Reply-To
- <xmqqa6qoqw9n.fsf@gitster.g>
Junio C Hamano <gitster@pobox.com> writes:
Show 10 quoted lines
> Jeff King <peff@peff.net> writes:
>
> > It also feels like any checks like this should be relying on the
> > existing pathspec-magic parser a bit more. I don't know the pathspec
> > code that well, but surely at some point it has a notion of which parts
> > are magic flags (e.g., after parse_element_magic in init_pathspec_item).
>
> Absolutely. parse_element_magic() decides, by looking at the
> character after the initial ':', the we are looking at the longhand
> form when magic sequence is introduced by ":(".Absolutely from me too! I would want to re-use more of the existing code. In response to that, patch https://lore.kernel.org/git/20210328152629.16486-1-133706+stdedos@users.noreply.github.com/ clearly shows that it is possible to re-use the de-facto long form magic parsing code to attempt to parse the string that continues as a long form magic.
This could theoretically pave the road for mixed short/long form parsing (in that order), if would be so desired.
However, as probably suspected, it suffers from one big problem:
if (ARRAY_SIZE(pathspec_magic) <= i)
die(_("Invalid pathspec magic '%.*s' in '%s'"),
(int) len, pos, elem);which is an unconditional `exit(128)`.
I don't know if it's possible to rescue (or redirect) that `die` call. In any case, considering that, this again deviates from the "small informative" change this commit was supposed to be.
Having said that, I have cooked a working patch with the proposed code.