Thread (98 messages) flat view 98 messages, 5 authors, 2016-06-15

Re: [PREVIEW v3 8/9] checkout-index: there are only two line terminators

From: Jeff King <hidden>
Date: 2016-06-15 23:07:45

Possibly related (same subject, not in this thread)

On Wed, Jan 13, 2016 at 07:03:08PM -0800, Junio C Hamano wrote:
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?
quoted hunk ↗ jump to hunk
@@ -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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help