Re: [PATCH v3 1/8] for-each-ref: add --stdin option
- From
Jeff King <peff@peff.net>
- Date
- Mar 15, 2023, 18:06 UTC
- Message-ID
- <ZBIJKrgI0+Qxd3pG@coredump.intra.peff.net>
- In-Reply-To
- <f9e80e233f1ca26f07f9db49261e54b7deaf83b8.1678902343.git.gitgitgadget@gmail.com>
On Wed, Mar 15, 2023 at 05:45:36PM +0000, Derrick Stolee via GitGitGadget wrote:
Show 19 quoted lines
> @@ -75,7 +79,21 @@ int cmd_for_each_ref(int argc, const char **argv, const char *prefix)
> ref_sorting_set_sort_flags_all(sorting, REF_SORTING_ICASE, icase);
> filter.ignore_case = icase;
>
> - filter.name_patterns = argv;
> + if (from_stdin) {
> + struct strbuf line = STRBUF_INIT;
> +
> + if (argv[0])
> + die(_("unknown arguments supplied with --stdin"));
> +
> + while (strbuf_getline(&line, stdin) != EOF)
> + strvec_push(&vec, line.buf);
> +
> + /* vec.v is NULL-terminated, just like 'argv'. */
> + filter.name_patterns = vec.v;
> + } else {
> + filter.name_patterns = argv;
> + }Now that you aren't detaching the "line" strbuf in each iteration of the loop, it needs to eventually be cleaned up. strbuf_getline() will _reset() it, which is good, but at the end we'd need a strbuf_release() or it will leak.
-Peff