Article View: linux.kernel.git
Article #4146Re: [RFC PATCH] quote: make sq_quote_buf_pretty() prettier
From: Phillip Wood
Date: Mon, 30 Nov 2026 16:39
Date: Mon, 30 Nov 2026 16:39
68 lines
13837 bytes
13837 bytes
On 27/11/2026 20:31, Junio C Hamano wrote:
> Phillip Wood <phillip.wood123@gmail.com> writes:
>
>> +static bool needs_sq_quote(char c, unsigned brace)
>> +{
>> + if (isalnum(c) || (unsigned char)c > 0x7f)
>> + return false;
>> +
>> + switch (c) {
>> + case ',':
>> + return brace > 0; /* Prevent brace expansion */
>
> Web search tells me that bash, zsh, and ksh93 expands sequence
> expressions such as "{1..5}" or "{a..z}" without any comma in the pair
> of braces. Because '.' returns false unconditionally here and no other
> check triggers quoting for "..", sq_quote_buf_pretty() leaves "{1..5}"
> unquoted, which expands to five arguments if pasted into those shells.
Oh, thanks for pointing that out. I think it should be fairly easy to
detect '..' when brace != 0
>> + /* '~' is only special if it is the first character */
>> + if (*p == '~') {
>> + quote_it = true;
>> + p++;
>> }
>
> As noticed by Nahid already, this loses the leading '~'. Also, do we
> want to do something to this corner case?
>
> $ echo P=A:~/B:C
> P=A:/home/gitster/B:C
>
> i.e., bash and friends seem to expand ~ that is not at the beginning of
> value when the whole thing looks like a variable assignment. Without
> "P=" at front, this does not seem to expand.
Thanks, having read the manuals bash, zsh and ksh all have slightly
different behaviors (and the zsh behavior depends on which options are
set). Quoting strings that start with '~', or contain '=~' or ':~', is
sufficient to prevent tilde expansion while avoiding quoting 'HEAD~1'.
zsh has an EXTENDED_GLOB option where '<pattern1>~<pattern2>' matches
everything that <pattern1> would match that <pattern2> does not.
Luckily, it seems to need another special character in one of the
patterns to trigger it so we don't need to quote "HEAD~1". The
EXTENDED_GLOB option also treats '^' specially, so to be safe we should
be quoting anything containing '^' which we don't at the moment. That's
a shame it means we need to quote "HEAD^2". EXTENDED_GLOB is not enabled
by default, but I think it is worth making our output safe when it is
enabled.
By default, zsh also expands "=cmd" to the absolute path of "cmd" in the
same places as '~' would be subject to tilde expansion.
On a related note our treatment of assignments is a bit strange - if the
right hand side needs quoting then we quote the whole thing which
disables the assignment, but we don't quote it otherwise. When
sq_quote_buf_pretty() was introduced the aim seems to have been to be
able to copy and paste tracing output to rerun the command being traced,
which would imply we don't want to disable assignments when the right
hand side needs to be quoted.
I'll try and re-roll later this week
Thanks
Phillip
Technical Details
Message-ID:
<01526f4d-b40e-4288-aa22-441c3e6e68e2@gmail.com>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!git+bounces-76709-linux-kernel-git=dewy.ruReferences:
<ee7de58093c69fbbab686a68b5b781bc60d90a2b.1795798429.git.phillip.wood@dunelm.org.uk> <xmqq7bhy819l.fsf@gitster.g>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!git+bounces-76709-linux-kernel-git=dewy.ru
From: phillip.wood123@gmail.com (Phillip Wood)
Newsgroups: linux.kernel.git
Subject: Re: [RFC PATCH] quote: make sq_quote_buf_pretty() prettier
Date: Mon, 30 Nov 2026 16:39:54 +0000
Organization: Usenet Network
Message-ID: <01526f4d-b40e-4288-aa22-441c3e6e68e2@gmail.com>
References: <ee7de58093c69fbbab686a68b5b781bc60d90a2b.1795798429.git.phillip.wood@dunelm.org.uk>
<xmqq7bhy819l.fsf@gitster.g>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: usenet.network;
logging-data="1470732"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:3wopbuRW9O2EQtM2Cgfm8EdcDQU= sha256:cm6UWH/H/jtsy6IOcZGODWMbrGpenP3hZu0toQF2uCQ=
sha1:PjgBwoKQkglVsjqO735j5eDYMHQ= sha256:xkhivXLTrRQtwXxaMQ4E7BJnAEqvTkXaH84xR57/dY8=
Content-Language: en-US
List-ID: <git.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
by mail.dewy.ru (Postfix) with ESMTP id 83A34125FF6; Mon, 30 Nov 2026 19:40:12 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -1.949
X-Spam-Status: No, score=-1.949 tagged_above=-9999 required=6.31
tests=[DCC_CHECK=1.1, DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1,
DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.001,
FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249,
MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
header.d=gmail.com
X-Received: from mail.dewy.ru ([127.0.0.1])
by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
with ESMTP id ylwhG3PFzrUY;
Mon, 30 Nov 2026 19:40:09 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=git+bounces-76709-linux-kernel-git=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
by mail.dewy.ru (Postfix) with ESMTPS id 0DF82125FF2; Mon, 30 Nov 2026 19:40:00 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
by sea.lore.kernel.org (Postfix) with ESMTP id E4A94231B4; Mon, 30 Nov 2026 16:39:58 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
t=1796056798;
b=4K7neUZM+F1XVe3JuUt0BsDU0qU0mTMeRdgSs9Mwh3vjuO1FPkDbGCyGt2Gt50VpLKjo
khBNWMuf5TkvX6K9p1WVU44rfZvL47wwYCZWrrVXMabsFwAI3IwuipIIYsvfKjxHRoD+a
bxiPC5k8Dddzh8+h5xaMNrAv/VzJTsJZsEQbqJitlJr0BIIvglCd5q9dxWnzzdlKhIIIP
5Y5XQpxIXjLZvo9NC3q+orz9MR0rUWYcZ2szIgZ4/eG/tdd9QjgsZ0K2JaoxNE6oXbDNB
3D6dUL7og5SFxdzLTNkfd/dbmAZsKXq1QbtX+8ktvCpiDcT7+XREqB0dTtrEhn5U34w==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1796056798;
h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
X-Google-DKIM-Signature:X-Gm-Message-State:X-Gm-Gg:X-Received:
Received:Message-ID:Date:X-Mailing-List:List-Id:List-Post:List-Help:
List-Subscribe:List-Unsubscribe:List-Owner:Precedence:MIME-Version:
User-Agent:From:Reply-To:Subject:To:Cc:References:Content-Language:
In-Reply-To:Content-Type:Content-Transfer-Encoding;
bh=voU8exZkDufjVOQSwdMGclep6MnLVwP2t9t+7BBAQJ4=;
b=e4Fbre2LmCCq1HpAGPlCCQXvBBMQoGnhvv2xrYZL0dSLcD/DME0wwLlqBt2Wv2Gktl+a
7J+UgSJzeW7LTf4UoUhWbJ+44QKm/YLpHPqB4A7uXitSNkRmjdsuV86wXPe3D6hbUa+Li
Zi5dOdZHoxiwjurBCmX8mQUZFcEvqZIN1vJdJRnDWjp3pBek+JGUiz77EsQZfzxy+zrLP
PWZECOAFkmNDRfj+cPK09+C4yHZooChu3mHTVAPy9eOxzPRS1h3t3bcjsqAwXP/8nlaqy
8kLuz1V8QoVVVKsbxgGRV353MjXrNW9c6NBlEV8qaCXNZQzzqLnjXphHCA4QD6kRZSA==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org;
dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=ltxMRHQx;
dmarc=pass header.from=gmail.com;
spf=pass smtp.mailfrom=gmail.com;
arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
by smtp.subspace.kernel.org (Postfix) with ESMTP id BD82C606A32C;
Mon, 30 Nov 2026 16:39:58 +0000 (UTC)
X-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=ltxMRHQx
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.42
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1796056797;
b=rQKtLALDeiO/lZe8PEtIMjeXaUTmnnVuvJHezo2mVCYEgnYDGlpR7DtKnMiXgzLvx6ed
ABIkLxzyq22hPCbtvei4ZlBqdcg3RuUEt0BA4fnZZvBV3E7ARBwgFImH/K2ONAJqfgZY6
6ymCGxz7fn7M9N0O7nyVLdXg2Y2IiayP7COLCb1TqeZ1bGknRoA/sh706WBWJcrrsL5v9
SnN3EP9K4C9rlHCK8JMjurWfNFfo98fgwu/RUHMSMnCAZ93RLn1s5jZnKVa42tDPWrLre
tK0taggYcDm3Oa/hd2o2VUlbcH//llrRbo9JoUE0BN1/nL+UM9HcriMchT4y7Hq1fDQ==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1796056797;
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:From:Reply-To:Subject:To:Cc:References:
Content-Language:In-Reply-To:Content-Type:Content-Transfer-Encoding;
bh=voU8exZkDufjVOQSwdMGclep6MnLVwP2t9t+7BBAQJ4=;
b=PcK0SBexo0GmUZFSgyfODhPIJcXMIVz9GPNVThmYFki6fydq7XknqjJPZBZvviZGo1Xk
8Mh28d6y5+fA82jIyfbjjQgwqlisZdOhbJxIQQXEhMJzDzmj/j8KLadyz5/dYvq3AhLE8
j49aD6zpgFTH59t3CdQHGxFMbOmKP3LBSuavqqzbMIYDjrVPiYQwoNKScKGCmYH7qZCPi
28A7rugJQX2bmN+AcAgyi9/dydLT8C9O1w0sUx9OGDzd5f+zSvv2lyvfAAvKWY6mGii8g
WRjp2Pnk6wegpQi6QM1DZFDP2+pVDKh4L4O8U55d1zjEZ9IN1pIGTHR+d0nzRJnuCLg==
X-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=ltxMRHQx;
arc=none smtp.remote-ip=209.85.221.42
X-Received: from mail-wr1-f42.google.com (mail-wr1-f42.google.com [209.85.221.42])
(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 93B60606A31C
for <git@vger.kernel.org>; Mon, 30 Nov 2026 16:39:57 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 93B60606A31C
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-wr1-f42.google.com with SMTP id ffacd0b85a97d-491f34b4e0fso4776831f8f.2
for <git@vger.kernel.org>; Mon, 30 Nov 2026 08:39:57 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20260707; t=1796056796; x=1796661596; darn=vger.kernel.org;
h=content-transfer-encoding:content-type:in-reply-to:content-language
:references:cc:to:subject:reply-to:from:user-agent:mime-version:date
:message-id:from:to:cc:subject:date:message-id:reply-to:content-type;
bh=voU8exZkDufjVOQSwdMGclep6MnLVwP2t9t+7BBAQJ4=;
b=ltxMRHQxvvUOeN7dQBggZyjG7oJvTJVXJKwFjdqrlAHpz92EyZvebsfLSyaCPBb3fK
VrcZ9O9c6Z7ezi/EvmYuwqbUEH8sreJ8wXrmRkacPvgWGHNbb/1N97seusLnypwKSSWd
k67ORsZU10bULkmuHsOpoVPZ2loMBHj6fNG17SYeWN6NY7BDdn+CIpFljwDzlqZ5GNpD
08rPmvazfP0Y4vP1All7IiWIaUkhUVKDYBb3nwFBAYQoWcPh42CL5kYBmmm6a+ISxoBf
F27NA3bb9N/t9x7Dyq4+Cqm0QiV+6sr+RaSo1W7bBd6jRCLMKkyrP1AqdG+rNeOg62xu
9qdQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1796056796; x=1796661596;
h=content-transfer-encoding:content-type:in-reply-to:content-language
:references:cc:to:subject:reply-to:from: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=voU8exZkDufjVOQSwdMGclep6MnLVwP2t9t+7BBAQJ4=;
b=iVklrNRRB/mLAIZlxcdidF7fa168ufery8/KFGQqnGAwoM5DWD0C7VkRFHMLFOlg/8
b/aAAae1TH5IPREnmc4N9V/ZTSU9Af6onH15Dbpu/g2WKnbso16sGTh50CrA4z8vl9Py
0DgLl1Ye4QSnRo8ZSYHzm+ASCIj4aFHs1osCT5/NWzhNsPWtrmXlXpwIIHo+9m5wkaPr
+twJckBRjfZnNF+99pmWN20Q1oZeUuIpeNfJTlDgzaFLbMEkzzBUDU2XLFE//JsnDIDy
bZNWA8ls8nnWrzp2qOONLZFqtpe1T5DSRc+CRU7JJALQ8a3u7Xeijt8emHUH5aSHOJDG
/zvQ==
X-Gm-Message-State: APuU4Z9ic7ItD02N8f9IEFTNHTXiTjFQ65InF0iI48WgtFIo3iheIO/K
ju8GKimK+GprOWB3qxZgcoX6IyjFHry4rZM6kr+Oy3IUL2M3FFaZt96j
X-Gm-Gg: AZFdTZfbATXEuM/BEsh9U7m7x5IaWsdyto9Y9VvzbKpsITTBZaKNflYFIZdcpHovzRF
9tMwTdyrIMbHdSFguwmdKrijzNgNDZhkD0mgn66IdyNFUjJ7P8xGOtgMaI5sh8m9hJZp+ikCE7o
X0FgZMDVL6LTO829awGMFPEQi+tkaV621q9Xjvltaxx3vTZY98Dcvb/TTlUUXQzkHGCq8Mmkpao
6gSPd2GJ7FcofaYPhRszhDK7gbz3INclaZC2MFJq/FfNqXbd2T4Bcgm7Ea+mmgVtqcpquS8lp4F
birEAVQ184A4+fsonBkzctMgdLnv11w2y2DqlHqzPFdeJtxbUlWTlpceaCQ6LvMZ+Ld+lsI8zAT
DiiiTWVs6s6Mo5xweH0eb+0THkVlL623y1Hcz4bT8y7xT3jjyUhwbJg/ldqKdCPLzEUpWGLzo/T
b/HB3Yhq74YnSvXS8EHV4yIe7jDusNqOEeEtHKCr2ZejPsk/G7lkRcmoE6L7TVZEHo+LGUekg03
3ry0eSN/MfFKXSwfTvfQeElboNY5KhKR55aaH+gKKcVhcQuQzx/TIpmLzT26F9uWv4nObd7qMCk
TxoIUfRips4rdrgDhmV7utIOEnChtWR8kIqa7IoArNwIdCIiNUWDa6e6A9sHAgD/ukAXy2HUF5/
QepDC9Qii
X-Received: by 2002:a05:6000:2512:b0:4b7:75cf:37fc with SMTP id ffacd0b85a97d-4b775cf386amr39376744f8f.52.1796056795639;
Mon, 30 Nov 2026 08:39:55 -0800 (PST)
X-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 ffacd0b85a97d-4ab6a67f204sm82022176f8f.21.2026.11.30.08.39.54
(version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);
Mon, 30 Nov 2026 08:39:55 -0800 (PST)
X-Mailing-List: git@vger.kernel.org
X-List-Post: <mailto:git@vger.kernel.org>
X-List-Help: <mailto:git+help@vger.kernel.org>
X-List-Subscribe: <mailto:git+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:git+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:git+owner@vger.kernel.org>
X-Precedence: list
X-User-Agent: Mozilla Thunderbird
X-Reply-To: phillip.wood@dunelm.org.uk
X-Cc: git@vger.kernel.org, Ben Knoble <ben.knoble@gmail.com>,
Harald Nordgren <haraldnordgren@gmail.com>,
MD Nahid Hasan Sagor <nahidhasan141400@gmail.com>
X-In-Reply-To: <xmqq7bhy819l.fsf@gitster.g>