From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-3.9 required=3.0 tests=AWL,BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by dcvr.yhbt.net (Postfix) with ESMTP id A81681F428 for ; Wed, 15 Mar 2023 18:06:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232017AbjCOSGi (ORCPT ); Wed, 15 Mar 2023 14:06:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34528 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231253AbjCOSGh (ORCPT ); Wed, 15 Mar 2023 14:06:37 -0400 Received: from cloud.peff.net (cloud.peff.net [104.130.231.41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4292814201 for ; Wed, 15 Mar 2023 11:06:36 -0700 (PDT) Received: (qmail 18810 invoked by uid 109); 15 Mar 2023 18:06:35 -0000 Received: from Unknown (HELO peff.net) (10.0.1.2) by cloud.peff.net (qpsmtpd/0.94) with ESMTP; Wed, 15 Mar 2023 18:06:35 +0000 Authentication-Results: cloud.peff.net; auth=none Received: (qmail 2902 invoked by uid 111); 15 Mar 2023 18:06:34 -0000 Received: from coredump.intra.peff.net (HELO sigill.intra.peff.net) (10.0.0.2) by peff.net (qpsmtpd/0.94) with (TLS_AES_256_GCM_SHA384 encrypted) ESMTPS; Wed, 15 Mar 2023 14:06:34 -0400 Authentication-Results: peff.net; auth=none Date: Wed, 15 Mar 2023 14:06:34 -0400 From: Jeff King To: Derrick Stolee via GitGitGadget Cc: git@vger.kernel.org, gitster@pobox.com, me@ttaylorr.com, vdye@github.com, Phillip Wood , =?utf-8?B?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Derrick Stolee Subject: Re: [PATCH v3 1/8] for-each-ref: add --stdin option Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org On Wed, Mar 15, 2023 at 05:45:36PM +0000, Derrick Stolee via GitGitGadget wrote: > @@ -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