Thread (1 message) 1 message, 1 author, 2016-06-15

Re: What's cooking in git.git (Jan 2016, #02; Mon, 11)

From: Junio C Hamano <hidden>
Date: 2016-06-15 23:07:44

Jeff King [off-list ref] writes:
I think you'll end up with some of the callers being a bit uglier. I.e.,
where we say:

  strbuf_getline(&buf, in, delim);

and "delim" is set elsewhere. These will become:

  if (delim == '\n') /* or maybe even "if (nul_terminate)" */
	strbuf_getline_lf(&buf, in);
  else
	strbuf_getline_nul(&buf, in);
My plan is to use a function pointer to switch between them.  A code
like the above in practice look more like

(1) there is a config/option parser that sets line_terminator that
    is typically a file-scope global.

	if (z_option)
        	line_terminator = '\0';
	else
        	line_terminator = '\n';

(2) the callsite calls getline with it

	strbuf_getline(..., line_terminator);

So we can introduce a file-scope global, (*getline_fn)(), and then
tweak (1) by removing line_terminator and replacing the assignment
with an assignment to getline_fn.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help