Article View: linux.kernel.git
Article #4008Re: [RFC PATCH] quote: make sq_quote_buf_pretty() prettier
From: Junio C Hamano
Date: Sat, 28 Nov 2026 00:26
Date: Sat, 28 Nov 2026 00:26
68 lines
14426 bytes
14426 bytes
Phillip Wood <phillip.wood123@gmail.com> writes:
I forgot to mention a couple of things.
> ... It also adds unnecessary pairs
> of empty quotes when a string starts or ends with a single quote.
"a single quote or an exclamation point." We can see the example in the
table you have below, for the entry for 'danger!'.
> + 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;
When brace > 0, quote_it stays true after emitting the backslash-escaped
character.
If the next character also needs backslash quoting (such as "{a'!b}"),
or if the string ends right there with an unclosed brace (such as "{!",
p == q (i.e., an empty segment) but we emit it in a pair of single
quotes.
> + } else if (*q == '{') {
> + brace++;
> + } else if (*q == '}' && brace) {
> + brace--;
> + } 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, '\'');
After the loop, here also is an instance of single quote pair around
potentially an empty segment. Perhaps a short helper or macro that does
an equivalent of
if (p < q) {
if (quote_it)
strbuf_addch(dst, '\'');
strbuf_add(dst, p, q - p);
if (quote_it)
strbuf_addch(dst, '\'');
}
and use it twice (the bs-quote code path needs to be slightly rewritten
if we wanted to share this piece of code that way)?
> }
>
> void sq_quotef(struct strbuf *dst, const char *fmt, ...)
Technical Details
Message-ID:
<xmqqmrqt3ior.fsf@gitster.g>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!3.eu.feeder.erje.net!feeder.erje.net!feeder1.feed.ams11.usenet.farm!feed.usenet.farm!peer01.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!git+bounces-76560-linux-kernel-git=dewy.ruReferences:
<ee7de58093c69fbbab686a68b5b781bc60d90a2b.1795798429.git.phillip.wood@dunelm.org.uk>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!3.eu.feeder.erje.net!feeder.erje.net!feeder1.feed.ams11.usenet.farm!feed.usenet.farm!peer01.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!git+bounces-76560-linux-kernel-git=dewy.ru From: gitster@pobox.com (Junio C Hamano) Newsgroups: linux.kernel.git Subject: Re: [RFC PATCH] quote: make sq_quote_buf_pretty() prettier Date: Fri, 27 Nov 2026 16:26:12 -0800 Organization: Usenet Network Message-ID: <xmqqmrqt3ior.fsf@gitster.g> References: <ee7de58093c69fbbab686a68b5b781bc60d90a2b.1795798429.git.phillip.wood@dunelm.org.uk> MIME-Version: 1.0 Content-Type: text/plain Injection-Info: usenet.network; logging-data="848458"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:sa1KRekuO+GHSOShMght60qQtM8= sha256:BB1Y8JAQlUmsQkMfAOuVv8HHGFOv8e3v6Vq/7fqzuHc= sha1:OCciF1YDRNnXBjlP2Q6gqNQcrd4= sha256:rYVmhR5ZGf0sr98dBsW6emsIxPtnsk+rPpGe7fPXHbo= 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 7CE7A125F6A; Sat, 28 Nov 2026 03:26:36 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -1.95 X-Spam-Status: No, score=-1.95 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, 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, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=pobox.com header.b=BnAvkPjd; dkim=pass (2048-bit key) header.d=messagingengine.com header.b=cWLrX0I3 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 locWIVYlAfQS; Sat, 28 Nov 2026 03:26:33 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=git+bounces-76560-linux-kernel-git=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=pobox.com X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mail.dewy.ru (Postfix) with ESMTPS id 84D7B125F68; Sat, 28 Nov 2026 03:26:19 +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 63B192CBE0; Sat, 28 Nov 2026 00:26:17 +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=1795825576; b=vhVfHI54j4xfEGf9sWVGP8laJS/u6deqrvaD5GvPvN6e7u0hiXlsIPo53MQrINmvzJa0 uToUC9E+4ARa/H0PQLSYoDoCV3FNGzW28ud8fKh50HEmj0XgQ+ihE/RYcoGOC7CHGw92J S9UlixiQ82SevGhX3+A0gJBypHSrreE5xSAWp+jpA1/hLUHiUnvgkH4c4FiRVXle0tptK kXY+AJbxkakxhPbzZi2qDyDC+oRJfvWMjQaqrJZz90LoximcABuh/0VddzWIbGM9eNZfu Z2D1RfaifaPoJrHzpPC7thmeKwF+T75OlgZ2STayU33qIWfR288zWIUG4/wFLm0iI2Q== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795825576; h=X-Original-To:Received:DMARC-Filter:Received:Received:DKIM-Signature: DKIM-Signature:X-DKIM2-Info:DKIM2-Signature:X-DKIM2-Info: Message-Instance:X-ME-Sender:X-ME-Received:X-ME-Proxy-Cause: X-ME-Proxy:Feedback-ID:Received:From:To:Cc:Subject:In-Reply-To: References:Date:Message-ID:User-Agent:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version:Content-Type; bh=C+BeUVgh+8IrXFfIaMHtUy/xcV4XUJedXAOyXHUAlvM=; b=5sm9pxC8MJC3YgFCWJfqJRPA3Izx3rjnk3UXfaCPKdYm/GJSVKawwmPHeh2s/BSx5/wm 2L1sUYzZoE8npHnk7hRIwaP8Apf8DIJZCAv96ZXF06l5AB1ay0VxVXboaxG6mcqMDGNkS 9VYFu0aAmTM/rb0niEeinv+FJNuT7OjTi1hJQs9w7ouWxUM3DJ4C4TL31qXiyuk34MgaK bVfBAc/5TVhb3GL47KJRzXvJB6vcgxuPdNTWk2fewYkUoKue/yrtWT/eetwSZH5Vvbm/I d145Dxkzf0O8YQLdSb3js7Y0Xc7EBDucsXagjoUszy91YcaUmLuREiVEeHy5ZPSe5Lw== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=pobox.com header.i=@pobox.com header.a=rsa-sha256 header.s=fm2 header.b=BnAvkPjd; dkim=pass header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b=cWLrX0I3; dmarc=pass header.from=pobox.com; spf=pass smtp.mailfrom=pobox.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 A2996606A326; Sat, 28 Nov 2026 00:26:16 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=pobox.com header.i=@pobox.com header.a=rsa-sha256 header.s=fm2 header.b=BnAvkPjd; dkim=pass (2048-bit key, unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b=cWLrX0I3 X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=202.12.124.158 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795825575; b=At1zNXX7+peSJM11NA/1Jfql/+Xa+ZvrPIyRmY8eOw8z2KW1f2bbSzs2sV9+gfWVT0jS VI0+jbZ18Bh3QYG1EruzCJXQotwIO41YpCenvneiQUofHwfPyAu/r6kZiUTeRam9oAQCY YXZT3TuHobRuC/qnplCxxC++ZlEJOXxUFPaNvBaW9+RyCU2TyanEWbxVmtDzu9tqnHgZu peAJ0PYImb+0uz1EEfZ2w8XDFDPzNXX2mHTqJosa4ZUceREJBgaJqjlkpJoF/lIXMjgCm W70J3i/VO3gGxD14Mbge79/YCyhTY6eFwBxbZKwgvsRd/stVSIiHMafhHBgC9aelsBQ== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795825575; h=DMARC-Filter:Received:Received:DKIM-Signature:DKIM-Signature: X-DKIM2-Info:DKIM2-Signature:X-DKIM2-Info:Message-Instance: X-ME-Sender:X-ME-Received:X-ME-Proxy-Cause:X-ME-Proxy:Feedback-ID: Received:From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: User-Agent:MIME-Version:Content-Type; bh=C+BeUVgh+8IrXFfIaMHtUy/xcV4XUJedXAOyXHUAlvM=; b=D+xuSyVtHKtaJF99EZ5txiVyEm2Ra1QIJQwdzaXcblYn7XI2E2HPesK3anbHm9gZ6Jmd tlkCLniZqmyZrr9toYCUIe0D/jzVcQSVrIQ/JcmJ9CRziqRBGdfhrjIYVvjlYcPfCBGxN TWGg+9dPHAFrJ/0pZa2YbaY3ByhxI0z9/Ru8vMPiS9zRIfG2gE3ujovDlMtVT/+0HbBe0 gv3Q9/pBvD3xvogCpfRjxrb5UQrudUpSsUNsbGzsRbLX5/AzYTk8BBbhu7679qWPik4Nv 3I5oRyTGoBKvxVBUVoPdAGoSEh61Fznginkxeu8+VjW9DcHTku5UjbkB1OxdqRys6/g== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=pobox.com; spf=pass smtp.mailfrom=pobox.com; dkim=pass header.d=pobox.com header.i=@pobox.com header.a=rsa-sha256 header.s=fm2 header.b=BnAvkPjd; dkim=pass header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b=cWLrX0I3; arc=none smtp.remote-ip=202.12.124.158 X-Received: from fhigh-b7-smtp.messagingengine.com (fhigh-b7-smtp.messagingengine.com [202.12.124.158]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 61D0F606A31C for <git@vger.kernel.org>; Sat, 28 Nov 2026 00:26:15 +0000 (UTC) X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 61D0F606A31C X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pobox.com X-Received: from phl-compute-03.internal (phl-compute-03.internal [10.202.2.43]) by mailfhigh.stl.internal (Postfix) with ESMTP id A2EC47A04D0 for <git@vger.kernel.org>; Fri, 27 Nov 2026 19:26:14 -0500 (EST) X-Received: from phl-frontend-02 ([10.202.2.161]) by phl-compute-03.internal (MEProxy); Fri, 27 Nov 2026 19:26:14 -0500 X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pobox.com; h=cc :cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm2; t=1795825574; x=1795911974; bh=C+BeUVgh+8 IrXFfIaMHtUy/xcV4XUJedXAOyXHUAlvM=; b=BnAvkPjdVZm9H2OZFFljEndaB5 VIVZx0u6VqnCJV54V2xBHeQHlkrN0x9Q+90XVQJVoFjIIHUteichp7P3tIkqLern iYniYr2VeTRWL6/E3p2sQy7WqOtTnsB3V378fTWfxWRgeHyTXBS5OS1Cpvi3yF9g jnRAG9W3HqFylLy+Mo9LFYsaYdvWXjEooB3NDJvGt6De0PZTk5oeZYnTYA/lOUn1 bgHzRfajvaBxypQoEnQJQBK3JRwXt9nvQzenVQKTisOQYYYNTs3s8T/zW6KMs1nH n4FGYPIIFCILyf76pS9pAmDtGbkOSJnI7eWVu1OXyaCjO4/hfPN7GEQLy6AA== X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1795825574; x=1795911974; bh=C+BeUVgh+8IrXFfIaMHtUy/xcV4XUJedXAO yXHUAlvM=; b=cWLrX0I3hrWqGBfLeIqnb3C/YRVDIyJ2FFv5exw6y0D6cOVek+Z IvKNwaLclivauYEdpZN+lKH7/6TmGfdNGpdHq5SdSChMoqndfTce9u++WuvlksQK 5Gi2leIKwOLTSZpluNm9rfPG6F4e7lJ8qqSEpSQfsPt7byOW0QJYV4vjKqVav5Pf bmDlOOEnfbl9sR6ppjrjlAAA92H1jO8HfASthw5pBufTsCxxnA0ywRskJxJykpiU VsF7FMol4LuGpcilIhSS8I4xo74dXmWcy/BuVgX3SRgxCbwrs75mIpB3jfd+mrkU kZOfzCsHEOwBAYg7u4tZnYw/qDH2PPjrK2g== X-DKIM2-Info: draft=ietf-dkim-dkim2-spec-09; repo=github.com/dkim2wg/interop; date=2026-11-03; sw=lmtpprox; action=sign d=pobox.com a=rsa-sha256; X-DKIM2-Signature: i=1; m=1; t=1795825574; d=pobox.com; mf=PGdpdHN0ZXJAcG9ib3guY29tPg==; rt=PGdpdEB2Z2VyLmtlcm5lbC5vcmc+; s=fm2:rsa-sha256:SdwuzW2i55oRUGiyYrbpw4OWk083B1hcWAU5Anog+4fLmbZ ddP4AIjNGowBwgz6K4lbt5AYhAn+T9uCuROebmB2msQX2K+AtVk9WpfJYF6wx5vz 0a1qUCbffwMXncgnv5gr5j2UUimtQ+yz8P59A5FL/Vos1v2UcXjNTO8lr2RcBk9H Allzn4rf40CKEgi1YUCQhOH4qVPyReCiFIm3NPm3IKK+T5R4yJHTD88qskrLD7qj DmB5ZqBWBGXBTVVVW8e5sADY4Afa/WGuk0Pubftp2ac66ZitiOtcq8Ri2Bj/bKAY /CPhEp8rvSU02CZrrygPrrLKwRE5hh8IYC86wJQ==; X-DKIM2-Info: draft=ietf-dkim-dkim2-spec-09; repo=github.com/dkim2wg/interop; date=2026-11-03; sw=lmtpprox; action=mi-m=1; hc=12; hn=cc,content-type,date,feedback-id,from,in-reply-to,message-id, mime-version,references,subject,to,user-agent; X-Message-Instance: m=1; h=sha256:MHfbz/l0YQ3lMmE+MyGTuX5vQDzISgKLdjjWDbc/xOk=:saq3gWckM4mjVEmfvjKK75GaAEtVMqye+8vy5+V030U=; X-ME-Sender: <xms:ph8Ka3bII6tLTXfRIPVv1SGRAGjHP-kcc0b-bPBK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1H2GB2YlBgaGU_q3HubfoeT-yWwvA> <xmx:ph8Ka-y45-qHTlUjtBqsivt5ogSdoJ3hZtut6jCX5oqX9wRebG7ioA> <xmx:ph8Kaxo7ZmR_PmGLTsjmCgSiEzAhJbxuj-I94g5hjlL4aOpwSMerCA> <xmx:ph8KaxqMgOF-LQ8JsGIlkCC5ReHsEucK1Oa3RyL3AGOx_vLbgLn3hlRK> X-Feedback-ID: if26b431b:Fastmail X-Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 27 Nov 2026 19:26:13 -0500 (EST) 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: <ee7de58093c69fbbab686a68b5b781bc60d90a2b.1795798429.git.phillip.wood@dunelm.org.uk> (Phillip Wood's message of "Fri, 27 Nov 2026 16:54:27 +0000") X-User-Agent: Gnus/5.13 (Gnus v5.13) 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-Received-Bytes: 14171