Article View: linux.kernel.git
Article #722[PATCH v2] pretty: fix lost indent after newline in %w()
From: Andy Koppe
Date: Sat, 17 Oct 2026 08:11
Date: Sat, 17 Oct 2026 08:11
110 lines
12396 bytes
12396 bytes
When strbuf_add_wrapped_text() meets a newline followed by a
non-alphanumeric character, it treats it as a hard line break and jumps
to the new_line label. That code was written for the case where a line
gets too long. It moves past the space where the line was broken by
setting the next line's start to 'space + isspace(*space)'.
After a hard line break, 'space' already points to the first character
of the next line. If that character is whitespace, it was wrongly
skipped, so the line lost one column of indentation. This affected
things like code examples or multi-line list items starting with "- "
and continuing with two spaces of indentation.
Fix this by skipping the space only in the line-too-long case. In the
double-newline case, skip the second newline explicitly, because that
case relied on the old skipping.
Add a test for this, and update the expected output of the "magical
wrapping directives" test in t4205. There, %+d emits a newline followed
by " (tag: ...)", and that leading space is no longer lost. With a wrap
width of 1, the space now causes an extra line break.
Document the %w placeholder properly, removing the reference to `git
shortlog -w`, which has different defaults and isn't concerned with
paragraph reflowing.
Signed-off-by: Andy Koppe <andy.koppe@gmail.com>
---
Documentation/pretty-formats.adoc | 9 +++++++--
t/t4202-log.sh | 6 ++++++
t/t4205-log-pretty-formats.sh | 2 +-
utf8.c | 4 +++-
4 files changed, 17 insertions(+), 4 deletions(-)
diff --git a/Documentation/pretty-formats.adoc b/Documentation/pretty-formats.adoc
index 2ae0eb11a9..4fb0419715 100644
--- a/Documentation/pretty-formats.adoc
+++ b/Documentation/pretty-formats.adoc
@@ -169,8 +169,13 @@ The placeholders are:
on the next placeholders until the color is switched
again.
++%m++:: left (`<`), right (`>`) or boundary (`-`) mark
-++%w(++`[<w>[,<i1>[,<i2>]]]`++)++:: switch line wrapping, like the `-w` option of
- linkgit:git-shortlog[1].
+++%w(++`[<w>[,<i1>[,<i2>]]]`++)++:: set line wrapping and indentation.
+ Output is word-wrapped at _<w>_ columns, with the first line
+ indented by _<i1>_ spaces and subsequent lines indented by
+ _<i2>_ spaces. A width of 0 disables wrapping. Omitted values
+ default to 0, so ++%w()++ turns off both wrapping and indentation.
+ Newlines that are followed by an ASCII letter or digit are replaced
+ by spaces to reflow paragraphs. Existing indentation is kept.
++%<(++`<n>[,(trunc|ltrunc|mtrunc)]`++)++:: make the next placeholder take at
least N column widths, padding spaces on
the right if necessary. Optionally
diff --git a/t/t4202-log.sh b/t/t4202-log.sh
index 06552a6271..5895780e8f 100755
--- a/t/t4202-log.sh
+++ b/t/t4202-log.sh
@@ -94,6 +94,12 @@ test_expect_success 'format %w(,1,2)' '
test_cmp expect actual
'
+test_expect_success 'format %w(11)' '
+
+ git log -2 --format="%w(11) This is%n the %s%n commit." > actual &&
+ test_cmp expect actual
+'
+
cat > expect << EOF
$(git rev-parse --short :/sixth ) sixth
$(git rev-parse --short :/fifth ) fifth
diff --git a/t/t4205-log-pretty-formats.sh b/t/t4205-log-pretty-formats.sh
index 4be5c51489..0733f22d58 100755
--- a/t/t4205-log-pretty-formats.sh
+++ b/t/t4205-log-pretty-formats.sh
@@ -1139,7 +1139,7 @@ test_expect_success 'log --pretty with invalid padding format' '
test_expect_success 'log --pretty with magical wrapping directives' '
commit_id=$(git commit-tree HEAD^{tree} -m "describe me") &&
git tag describe-me $commit_id &&
- printf "\n(tag:\ndescribe-me)%%+w(2)" >expect &&
+ printf "\n\n(tag:\ndescribe-me)%%+w(2)" >expect &&
git log -1 --pretty="format:%w(1)%+d%+w(2)" $commit_id >actual &&
test_cmp expect actual
'
diff --git a/utf8.c b/utf8.c
index 96460cc414..bb55bf357f 100644
--- a/utf8.c
+++ b/utf8.c
@@ -322,6 +322,7 @@ void strbuf_add_wrapped_text(struct strbuf *buf,
space++;
if (*space == '\n') {
strbuf_addch(buf, '\n');
+ space++;
goto new_line;
}
else if (!isalnum(*space))
@@ -333,9 +334,10 @@ void strbuf_add_wrapped_text(struct strbuf *buf,
text++;
}
else {
+ space += isspace(*space);
new_line:
strbuf_addch(buf, '\n');
- text = bol = space + isspace(*space);
+ text = bol = space;
space = NULL;
w = indent = indent2;
}
--
2.56.0
Technical Details
Message-ID:
<20261017081150.2295695-1-andy.koppe@gmail.com>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!git+bounces-72292-linux-kernel-git=dewy.ruReferences:
<20261014172333.2224123-1-andy.koppe@gmail.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!git+bounces-72292-linux-kernel-git=dewy.ru
From: andy.koppe@gmail.com (Andy Koppe)
Newsgroups: linux.kernel.git
Subject: [PATCH v2] pretty: fix lost indent after newline in %w()
Date: Sat, 17 Oct 2026 09:11:50 +0100
Organization: Usenet Network
Message-ID: <20261017081150.2295695-1-andy.koppe@gmail.com>
References: <20261014172333.2224123-1-andy.koppe@gmail.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
logging-data="2998685"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:rVRewqfx9Fzci/aD8L0ntz+JASs= sha256:uQemx+0ocmFhADbggH96tU7SWLWxSGWs31NoE5TQPAc=
sha1:EfXMVBErhiyuxOTFsE/ctjV3wzY= sha256:fNgYkvx3dT3LWcj01U6xRjy73E88AVHSyBkP0wzTC/U=
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 4BD561106B0; Sat, 17 Oct 2026 11:12:44 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -0.747
X-Spam-Status: No, score=-0.747 tagged_above=-9999 required=6.31
tests=[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.25,
MAILING_LIST_MULTI=-1, 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=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 03ct3He2XvHt;
Sat, 17 Oct 2026 11:12:37 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=git+bounces-72292-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 D09F8DF0B6; Sat, 17 Oct 2026 11:12:26 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.90.174.1])
by sea.lore.kernel.org (Postfix) with ESMTP id 5A0D83B58B; Sat, 17 Oct 2026 08:12:15 +0000 (UTC)
X-Received: from localhost.localdomain (localhost.localdomain [127.0.0.1])
by smtp.subspace.kernel.org (Postfix) with ESMTP id EC0E641D224;
Sat, 17 Oct 2026 08:12:13 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="V8g6Wv4J"
X-Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53])
(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
(No client certificate requested)
by smtp.subspace.kernel.org (Postfix) with ESMTPS id A5AED3DAABB
for <git@vger.kernel.org>; Sat, 17 Oct 2026 08:12:08 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.53
X-ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
t=1792224731; cv=none; b=VL5AFL+I8J83WhZPOLq7ULeBNUDGRSKFbZwBE4LCAYfZ/a7Z6EK7Zh5nfPpY87xzq0Zun5sUlTxhN9GFsAVjJ6pTWWKWpSiIE0zMm8lzGPeNgPwgCH73Yp6SQOy9vMw+ja8ljKpn+l+w4E5A+iBczqhgkuZ2SwBoc7pvb6srpTw=
X-ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org;
s=arc-20240116; t=1792224731; c=relaxed/simple;
bh=QjQhXYfd1RRsT7m0QH/C38XfyW3HJtg4Q27tgdXZNCQ=;
h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:
MIME-Version; b=A+CUZ4nnBRkKCUvp3fYD2a59dXrNHGXGXQ6Qo7LYM2FSz9ATBVJ/PlcGoh22jDmgA3PusZOL+Hs60WP7l039lZpE0UQ98ACaNc8Chj6FA6ITRyaP2N48eC37q6hfb0umx+zrfyQEoBQLqQ+YniHuPxdS3ZuVubjpJqqk4dVlME4=
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=V8g6Wv4J; arc=none smtp.client-ip=209.85.128.53
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-wm1-f53.google.com with SMTP id 5b1f17b1804b1-4a1df4c0966so196645e9.1
for <git@vger.kernel.org>; Sat, 17 Oct 2026 01:12:08 -0700 (PDT)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20251104; t=1792224727; x=1792829527; darn=vger.kernel.org;
h=content-transfer-encoding:mime-version:references:in-reply-to
:message-id:date:subject:cc:to:from:from:to:cc:subject:date
:message-id:reply-to:content-type;
bh=VyZh8O4mklsOddh2caBLoOxp7lBZNF3ZmiBmGRcSB9s=;
b=V8g6Wv4JgMheb0mZKG0baFm/RNFNCA8ot3gQ2d/mGVkerUtoak5yDRd+bVgpaNSn6H
054SBd3P8te5auzrl7wfW9XrFM3jVJtEW6u07Vu17iz1hNvLtujn4ntHqsKmAwhfTeTz
7SJHaf0DAlQvYcxIcG40PXUurDSW1HGxG2rSV3ZiY6OCfxjrvB5pwA6YLYpxFcirgZVS
YV+WBQL1vdYfmLL4vd+XjWCU4oj2Tt3ocr1Qelb8YdGJleT1pL0FxTKPE3iKfiJ9deJZ
Xl/10sWSyNMtDHVLeTe86UJvfOBodMp9N7dzaPpqza2O0LOjj07RNUKNKpGkN4fs+hM6
xn2A==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1792224727; x=1792829527;
h=content-transfer-encoding:mime-version:references:in-reply-to
:message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from
:to:cc:subject:date:message-id:reply-to:content-type;
bh=VyZh8O4mklsOddh2caBLoOxp7lBZNF3ZmiBmGRcSB9s=;
b=vLIbl85spoFFAgqQEFslWIByr2P5iqJCmunZTgWpApDR6bAWbrC3wRC1lDZw5V2veD
ZHMvRkMM5KUjwMJbbnlF6sZkQhKfFXNnYOradcFFRvZsU1SErFmJvysFIrwn9GarhpbF
Rq39lbf8H55JAW4PesxNGBlEhs/gkVWqClSttqbMCZrS5l+9wFeTw2Xiji/R6KOkZruI
ir1FGJsahJUilfJRTh6tIEROe/oqvwndlRwuBll4OSpEGA+8vW8t6skTahfDet5rpWqk
Y7gDEdXhpbzOZTxK8K9ZxS92sCWSrbjuv0wIkm0bN/a+4DeZvDGw20UE/6St+ymReyLh
ZdBA==
X-Gm-Message-State: AFq9FYKWS58yvM76HC/JQ1HbdI/AfWS1rTm5SLKO5asIXUHfdYvELF7P
Syu3O7NLAVnst0c1g5KSC1eMTmsWxdvw0WOm9dxvC2Aeinz8fHjRSXZR7lmVOmmO
X-Gm-Gg: AYBFou0e5qgCyrKQmds0FuyIE2B8nBy7jOlt9Sk46eT37EBPMSDgiZbqQmUTnhvgSQ6
0Q6kwnegVtgc0d38V2F0s89te7kq7CZD4Pwyupksir6k2KiKTL5sNO9+KYfAiPWJB1TP7n7S82s
wRwxlrL1k7w3RW1QST6dCkwmyiKimTcZTh4gTMxGZmM+2GKjCZ01Qrw/EqvgLq3+Ko+d2JXO3xz
/I4SmQIgL5iguJ3NXLgHv1aEAHimQjV3hNuYXByylaINpCAMupvQgFu5damEhLpptZddDAtdK09
6j6VLgk2DWZwrnDPTTwRS6OaBYs33n6HXjLZal5B5aM4jImQuj0SyOTIg2kJPls3ZwJqCqJQzTK
deTo74PlbkeqZibjU4qwaZ+NU2tTHheLk2b7qxTw/KcFoC2PkbBpiL7B3OE4+Vradl1loZG6i4J
xSTMmNmGdHKOloM0FM/rNBGWIjSzIiXu66765dUIsWDut1T1otPzbj22miGvge2oi7Bp4XnKgBP
FjbY0CxmghhI61KCo3mOtV1OATBsw/8QYX3ScS1G+gpqsZZsj0N4aY9OJ5gzjoZcI/w/mBFS5VP
7Q==
X-Received: by 2002:a05:600c:3046:b0:4a1:87fb:c8c0 with SMTP id 5b1f17b1804b1-4a1c66a71cfmr83822415e9.5.1792224726405;
Sat, 17 Oct 2026 01:12:06 -0700 (PDT)
X-Received: from u.ad.analog.com (sgyl-40-b2-v4wan-169439-cust3365.vm6.cable.virginm.net. [92.234.157.38])
by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48dfd5035bbsm9993400f8f.44.2026.10.17.01.12.05
(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
Sat, 17 Oct 2026 01:12:05 -0700 (PDT)
X-Cc: RenΓ© Scharfe <l.s.r@web.de>,
Johannes Schindelin <Johannes.Schindelin@gmx.de>,
Andy Koppe <andy.koppe@gmail.com>
X-Mailer: git-send-email 2.56.0
X-In-Reply-To: <20261014172333.2224123-1-andy.koppe@gmail.com>
X-Precedence: bulk
X-Mailing-List: git@vger.kernel.org
X-List-Subscribe: <mailto:git+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:git+unsubscribe@vger.kernel.org>