Re: What's cooking in git.git (Jan 2016, #02; Mon, 11)
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Jan 13, 2016, 23:44 UTC
- Message-ID
- <xmqqpox5kpsy.fsf@gitster.mtv.corp.google.com>
- In-Reply-To
- <20160113232255.GA17937@sigill.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 11 quoted lines
> 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.