Re: [PREVIEW v3 8/9] checkout-index: there are only two line terminators
- From
Jeff King <peff@peff.net>
- Date
- Jan 14, 2016, 10:18 UTC
- Message-ID
- <20160114101830.GC30772@sigill.intra.peff.net>
- In-Reply-To
- <1452740590-16827-9-git-send-email-gitster@pobox.com>
On Wed, Jan 13, 2016 at 07:03:08PM -0800, Junio C Hamano wrote:
Show 10 quoted lines
> The program by default works on LF terminated lines, with an option
> to use NUL terminated records. Instead of using line_termination
> that happens to take LF or NUL to call strbuf_getline(), switch
> between strbuf_getline_{lf,nul} based on the value of '-z' option.
>
> Note that this still leaves the option open to use NUL-terminated
> input mixed with LF-terminated output (and vice versa), and even
> HT-terminated output is still left as a possibility, because this
> series is only interested in tightening the overly broad interface
> on the input side.I see that we switch the line termination on the fly in option_parse_z. But I'm having trouble seeing how we could actually have mixed inputs. We don't actually look at the line-terminator until after all of the options are parsed.
IOW, could this OPT_CALLBACK for 'z' be simplified to a simple OPT_BOOL, or am I missing some case?
> #define CHECKOUT_ALL 4 > static int line_termination = '\n'; > +static strbuf_getline_fn getline_fn = strbuf_getline_lf;
This "line_termination" can become a boolean "1" now, right?
Show 13 quoted lines
> @@ -144,10 +145,13 @@ static int option_parse_u(const struct option *opt,
> static int option_parse_z(const struct option *opt,
> const char *arg, int unset)
> {
> - if (unset)
> + if (unset) {
> line_termination = '\n';
> - else
> + getline_fn = strbuf_getline_lf;
> + } else {
> line_termination = 0;
> + getline_fn = strbuf_getline_nul;
> + }Ditto here (though as before, I think I prefer it as the inverse bool: did somebody turn on "-z").
I'm also not sure how "unset" would trigger here. If we have a long option, we can use "--no-foo". But there isn't a long option for "-z". Is there a way to negate short options?
-Peff