From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.47 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796056777; b=mxWdZVp9LtVAFYPtr5wGZuKo4DTwmONLrzJUk070RWzSjzkPAWh+zOSpINrmpA2YXpuc F3j5kKGN+ZK8ERImW8x5+N0IRNTExEg242+++EEQP/alzw2MXlAGkdbM1yJDFUxjrCJX4 dsqmbhVkJ1OZN4sm0Klsi+QA7bPQii8vHUabEwpmu5UnwfivnuHYNEx8u3xXWWgjlU2lb aeyYv4XmAyq2knHg9hDn9QCVNJrjMviW3C42zedO1Rb7SPI+jMYuAcILa8gBcGwN+OAcw qlY9RsUHZNcHBpMr6EKlBl/tEdJ/PLjg8d6UlqBpqWJp3EV3m4sH0lwuUHlCczpsE7g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796056777; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:Message-ID:Date: MIME-Version:User-Agent:Reply-To:Subject:To:Cc:References: Content-Language:From:In-Reply-To:Content-Type: Content-Transfer-Encoding; bh=iIzEERbOtkMXGG+Dvj96FKfIAZzsdcfG8cJjcofI5T8=; b=hYNNdX9AmgzTI8+GwzIqbffs0DhwLmvpOCpniE5xwhb3Xx7LjVM4CXnj5LCQUWtjIBRW CL34KdtKt4Kd4dhlXhRJK9WSYtyGp0OEIhaznfqkOh+wz924hi/xNubEkAfQGogblt5dj wvjHLOWQzNA3UdnPLIbPKd/FJksDp21GwlvFkl/muXF6lgUiTXB2fyl/M3Qf/TJqK76F5 aY7BevXRenxWXHjbMjxj3/4tHuTaAHJqWbLYPkrd6LZl6PwnX/ex5ME8ogwaXfxMAsKc3 MBrn5bhzPpNe27x8Tr1FqTgVSwCSkFdPo44gnztQxhHhf8VWF6Z4o5BjoZ7Y4jYqwwA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=ahiTaiMp; arc=none smtp.remote-ip=209.85.128.47 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 34964606A320 for ; Mon, 30 Nov 2026 16:39:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 34964606A320 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=ahiTaiMp Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-4bb6c7b6dbdso98831815e9.0 for ; Mon, 30 Nov 2026 08:39:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796056775; x=1796661575; darn=vger.kernel.org; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:reply-to:user-agent :mime-version:date:message-id:from:to:cc:subject:date:message-id :reply-to:content-type; bh=iIzEERbOtkMXGG+Dvj96FKfIAZzsdcfG8cJjcofI5T8=; b=ahiTaiMpD3Me8CBdFUQZxc5bPANpUjzUbj1vFwSaLny0a3GEaJxcocIJ2CD4C5OtXV hRMp+hfvN9LRcfECunNoODinCP7tFrLzmKAgXo5mTzNlJAaWxp0hwKYutJHQiYtmchJL cqVxdpZOI9f6ZJheXZhi9+hOxbhW2K3NIxAhX5h02gq7RoLcUHqZOQBDmTcq2i8+wMmz 6md8Y0bUGzsMtjEREnzzajJg9F9vq1CiuyFGNN7lLefToldKOhZV41yTsIt0ga5OcVPa TvGAd/VWxpTLRE1w663JEvY0qFwr1U8PtJ5a9SvsJ96e/2Xm+mTqBV2IuXIOo9dpQsdR iq9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796056775; x=1796661575; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:reply-to:user-agent :mime-version:date:message-id:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to:content-type; bh=iIzEERbOtkMXGG+Dvj96FKfIAZzsdcfG8cJjcofI5T8=; b=M4EAc8gOY8pVb3HZzbEo1ixZ+rf6h3j4npEYdaav8LbFdDqjWSDsoEwkLGxP4pXXfk y8uEUGv/VnGms7Qi5h1mGUtUVeTwoRHWJbT3IiJ6jCRSUxm0k9qaSGj/ewVwEjfjhxpX VKqMcDsqOT1wg+qUWBcrqCwmIB0o7HsXd4wRO+heqEg15zWUhOlWoHQ7uEv+Pb9V0eIc QNrG9dNj4KNkNQIO/+htFRZOrdOL2LYfjJirugFOs2seAyS3jlEx/QekrC41OEt7NJX9 Q4Z5/vyh8Ae5BMrebnEMYKeLMwROxDo2A3qhrfcyihM0BellaOSKSWGz2uXaj9ctPqH0 FkRQ== X-Gm-Message-State: APuU4Z+fUBeyl+olSfW5VYdiGD8Fb0I07K5FH4iWX3vVAeq4aH7fnGC9 6Tt4W7rH5gFl/axW6mlDa2RfGt7WUTfKFSw1wE4JyBovx8RtiNKZFqeS X-Gm-Gg: AZFdTZcQty2Y18c9uvoO16klbipuqIcSPknuGc+62edxA+teoIn1eSq/8zpnAlTCByN 3DCaGK1VtlVNsjBkvdRHUgEwVj4LYIA/RzVzGbavd9beJk3cVadtKKHANV0q1J3dDYKdHCW7w/p od0EgiBmadNI9mX8qKvqgHh0BSsGGVAiQ0xmcoUDMErKPnSVaCJui5T7HiXsVOliNuZQLJeTtHV tRy9qaON0qyu87i3Hp8EZMlBfeXtKtTfEkcJn6TI3sLlVMnUZ+ACDFAxb35rFYiNmaqaTO4UfVv tUwqAOlzBansS5aaZYxGRyNLI/cGXmgc3j226DVDIKXY8fvysay6Se9waKRuc6B4H6p134TC+pI gb42+qWx/MipZE88XRTrXRpp5jh/f18fWIMCe8OwVljDvG4DXw0aNaakLjzA1Hul0L0ajV1VC2Y ZuLvWas6i9A4FFI40Z7RarEqEX4mBfUAHRVMPmT+TFCJQs2UcUAF9blqSP2vrmoXg20o6dBvpNH QT3/RJb0L7VnVfTnAN3NCvbjO24Y30QUguKDonEi4ulH3jMgnpaE2lxMrzfkXYvXp2onW/OaN9H stRHmrmMBe47BieegLtnaydqrgohZ1rMyiHtVEYPm2r6rOy4QKNjnj7sZsmallW5MqEfY3GPRNt Taue0wXnmM6j6sW8Sch+oC3q1R6vS X-Received: by 2002:a05:600c:3511:b0:4ba:73f:ef5 with SMTP id 5b1f17b1804b1-4bb88828304mr722833875e9.34.1796056775219; Mon, 30 Nov 2026 08:39:35 -0800 (PST) Received: from ?IPV6:2a0a:ef40:724:6601:f3ff:aebc:61f8:d91f? ([2a0a:ef40:724:6601:f3ff:aebc:61f8:d91f]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bbab390cf5sm511393185e9.7.2026.11.30.08.39.34 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 30 Nov 2026 08:39:34 -0800 (PST) Message-ID: <27a384cb-7279-4061-9925-c55107575f6d@gmail.com> Date: Mon, 30 Nov 2026 16:38:24 +0000 X-Mailing-List: git@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Reply-To: phillip.wood@dunelm.org.uk Subject: Re: [RFC PATCH] quote: make sq_quote_buf_pretty() prettier To: "D. Ben Knoble" , Phillip Wood Cc: git@vger.kernel.org, Harald Nordgren , Junio C Hamano , MD Nahid Hasan Sagor References: Content-Language: en-US From: Phillip Wood In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Hi Ben On 30/11/2026 15:19, D. Ben Knoble wrote: > Hi Phillip, thanks for working on this! Thanks > On Fri, Nov 27, 2026 at 11:54 AM Phillip Wood wrote: > >> + for (q = p; *q; q++) { >> + if (need_bs_quote(*q)) { >> + if (brace) >> + quote_it = true; >> + if (quote_it) >> + strbuf_addch(dst, '\''); >> + strbuf_add(dst, p, q - p); >> + p = q + 1; >> + if (quote_it) >> + strbuf_addch(dst, '\''); >> + strbuf_addch(dst, '\\'); >> + strbuf_addch(dst, *q); >> + if (!brace) >> + quote_it = false; >> + } else if (*q == '{') { >> + brace++; >> + } else if (*q == '}' && brace) { >> + brace--; > > I think this simple counter may count wrongly for scenarios like > "}{a,b}", but I haven't tried it myself yet. My shells (Zsh and Bash) > both do the following: > > $ echo }{a,b} > }a }b > > and I *think* that brace==0 when we see the comma here, even though it > would need quoted to avoid expansion. We only decrement "brace" when we see '}' if "brace > 0". If we see '}' when "brace == 0" then we quote everything up to the next backslash escape or the end of the string. So we decide to quote this before we see the comma. Thanks Phillip > > I think we are unlikely to emit such strange punctuation ourselves, > but this would be one corner case of potentially many, I suspect. > >> + } else if (!quote_it && needs_sq_quote(*q, brace)) { >> + quote_it = true; >> + } >> + } >> + if (brace && !quote_it) >> + quote_it = true; /* Quote unpaired '{' */ >> + if (quote_it) >> + strbuf_addch(dst, '\''); >> + strbuf_add(dst, p, q - p); >> + if (quote_it) >> + strbuf_addch(dst, '\''); >> } >> >> void sq_quotef(struct strbuf *dst, const char *fmt, ...) >> -- >> 2.56.1.576.g0cfbda1d5c7.dirty >> > >