From: Jeff King Date: Thu, 11 Apr 2013 05:31:45 GMT Subject: Re: [PATCH 2/5] check-ignore: allow incremental streaming of queries via --stdin Message-ID: <20130411053145.GB28915@sigill.intra.peff.net> In-Reply-To: <1365645575-11428-2-git-send-email-git@adamspiers.org> On Thu, Apr 11, 2013 at 02:59:32AM +0100, Adam Spiers wrote: > @@ -111,14 +110,11 @@ static int check_ignore_stdin_paths(struct path_exclude_check check, const char > die("line is badly quoted"); > strbuf_swap(&buf, &nbuf); > } > - ALLOC_GROW(pathspec, nr + 1, alloc); > - pathspec[nr] = xcalloc(strlen(buf.buf) + 1, sizeof(*buf.buf)); > - strcpy(pathspec[nr++], buf.buf); > + pathspec[0] = xcalloc(strlen(buf.buf) + 1, sizeof(*buf.buf)); > + strcpy(pathspec[0], buf.buf); > + num_ignored += check_ignore(check, prefix, (const char **)pathspec); > + maybe_flush_or_die(stdout, "check-ignore to stdout"); Now that you are not storing the whole pathspec at once, the pathspec buffer only needs to be valid for the length of check_ignore, right? That means you can drop this extra copy and just pass in buf.buf: pathspec[0] = buf.buf; num_ignored += check_ignore(check, prefix, pathspec); > +test_expect_success 'setup: have stdbuf?' ' > + if which stdbuf >/dev/null 2>&1 > + then > + test_set_prereq STDBUF > + fi > +' Hmm. Today I learned about stdbuf. :) -Peff