From patchwork Sun Mar 29 15:02:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff King X-Patchwork-Id: 11464065 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 68058913 for ; Sun, 29 Mar 2020 15:02:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 500482073E for ; Sun, 29 Mar 2020 15:02:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728236AbgC2PC2 (ORCPT ); Sun, 29 Mar 2020 11:02:28 -0400 Received: from cloud.peff.net ([104.130.231.41]:54946 "HELO cloud.peff.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1728142AbgC2PC2 (ORCPT ); Sun, 29 Mar 2020 11:02:28 -0400 Received: (qmail 2287 invoked by uid 109); 29 Mar 2020 15:02:27 -0000 Received: from Unknown (HELO peff.net) (10.0.1.2) by cloud.peff.net (qpsmtpd/0.94) with SMTP; Sun, 29 Mar 2020 15:02:27 +0000 Authentication-Results: cloud.peff.net; auth=none Received: (qmail 9338 invoked by uid 111); 29 Mar 2020 15:12:28 -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; Sun, 29 Mar 2020 11:12:28 -0400 Authentication-Results: peff.net; auth=none Date: Sun, 29 Mar 2020 11:02:26 -0400 From: Jeff King To: Junio C Hamano Cc: git@vger.kernel.org Subject: [PATCH] test-lib-functions: simplify packetize() stdin code Message-ID: <20200329150226.GA16068@coredump.intra.peff.net> References: <20200327080210.GA604725@coredump.intra.peff.net> <20200327080300.GA605934@coredump.intra.peff.net> <20200328112010.GC639140@coredump.intra.peff.net> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20200328112010.GC639140@coredump.intra.peff.net> Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org On Sat, Mar 28, 2020 at 07:20:10AM -0400, Jeff King wrote: > > perl -e ' > > my $data = do { local $?; }; > > printf "%04x%s", length($data), $data; > > ' > > > > That's one process but much heavier than cat/wc/printf/cat, I guess. > > Yeah, I was tempted to do that, but ${#packet} is even one process > shorter. :) It might be worth simplifying the stdin path above, but it's > much less important if most of those call-sites go away. Here it is as a patch on top. I doubt it matters that much (there are only two stdin calls in the whole suite). So I'm not sure if this patch should be "eh, why not?" or "meh, pointless churn". -- >8 -- Subject: [PATCH] test-lib-functions: simplify packetize() stdin code The code path in packetize() for reading stdin needs to handle NUL bytes, so we can't rely on shell variables. However, the current code takes a whopping 4 processes and uses a temporary file. We can do this much more simply and efficiently by using a single perl invocation (and we already rely on perl in the matching depacketize() function). We'll keep the non-stdin code path as it is, since that uses zero extra processes. Signed-off-by: Jeff King --- t/test-lib-functions.sh | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh index 216918a58c..88b7dbd69a 100644 --- a/t/test-lib-functions.sh +++ b/t/test-lib-functions.sh @@ -1373,11 +1373,10 @@ packetize() { packet="$*" printf '%04x%s' "$((4 + ${#packet}))" "$packet" else - cat >packetize.tmp && - len=$(wc -c }; + printf "%04x%s", 4 + length($packet), $packet; + ' fi }