Re: [PATCH v4 05/21] check-attr: there are only two possible line terminations
- From
Jeff King <peff@peff.net>
- Date
- Jan 15, 2016, 19:16 UTC
- Message-ID
- <20160115191611.GB11301@sigill.intra.peff.net>
- In-Reply-To
- <1452815916-6447-6-git-send-email-gitster@pobox.com>
On Thu, Jan 14, 2016 at 03:58:20PM -0800, Junio C Hamano wrote:
Show 25 quoted lines
> The program by default reads LF terminated lines, with an option to
> use NUL terminated records. Instead of pretending that there can be
> other useful values for line_termination, use a boolean variable,
> nul_term_line, to tell if NUL terminated records are used, and
> switch between strbuf_getline_{lf,nul} based on it.
>
> Signed-off-by: Junio C Hamano <gitster@pobox.com>
> ---
> builtin/check-attr.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/builtin/check-attr.c b/builtin/check-attr.c
> index 265c9ba..087325e 100644
> --- a/builtin/check-attr.c
> +++ b/builtin/check-attr.c
> @@ -73,12 +73,13 @@ static void check_attr_stdin_paths(const char *prefix, int cnt,
> struct git_attr_check *check)
> {
> struct strbuf buf, nbuf;
> - int line_termination = nul_term_line ? 0 : '\n';
> + strbuf_getline_fn getline_fn;
>
> + getline_fn = nul_term_line ? strbuf_getline_nul : strbuf_getline_lf;
> strbuf_init(&buf, 0);
> strbuf_init(&nbuf, 0);Not really relevant to your series, but I find it slightly confusing when `strbuf_init` is used instead of a static initializer (it makes me wonder _why_, and whether there are any code paths that miss initialization).
Maybe worth doing:
struct strbuf buf = STRBUF_INIT; struct strbuf nbuf = STRBUF_INIT;
at the top while we are in the area (and also maybe giving the latter a more meaningful name!). But I don't want to derail the main point of your series.
-Peff