Article View: linux.kernel.git
Article #532[PATCH] pretty: fix lost indent after newline in %w()
From: Andy Koppe
Date: Wed, 14 Oct 2026 17:23
Date: Wed, 14 Oct 2026 17:23
88 lines
10815 bytes
10815 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. For example,
git log --format="%w(11) This is%n the %s%n commit."
printed " the ..." and " commit." rather than " the ..." and
" commit.".
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.
Signed-off-by: Andy Koppe <andy.koppe@gmail.com>
---
t/t4202-log.sh | 6 ++++++
t/t4205-log-pretty-formats.sh | 2 +-
utf8.c | 4 +++-
3 files changed, 10 insertions(+), 2 deletions(-)
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:
<20261014172333.2224123-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-72040-linux-kernel-git=dewy.ruShow 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-72040-linux-kernel-git=dewy.ru
From: andy.koppe@gmail.com (Andy Koppe)
Newsgroups: linux.kernel.git
Subject: [PATCH] pretty: fix lost indent after newline in %w()
Date: Wed, 14 Oct 2026 18:23:33 +0100
Organization: Usenet Network
Message-ID: <20261014172333.2224123-1-andy.koppe@gmail.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
logging-data="2344281"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:9+UivT9VpKCJ6potDuW2TNsizG8= sha256:halduVUKlW+VHWsJ+CnePjEIl524bO08kjnsc2jxJVg=
sha1:xmcRrno0Hu4ibQLH+T9P/ee7WS0= sha256:OczQZeW4plu6WsG7QAAAO6JTvny0U7KAeIs70LB/5fc=
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 1455611017B; Wed, 14 Oct 2026 20:27:08 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.047
X-Spam-Status: No, score=-3.047 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, 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=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 CFAkkTpXOUR5;
Wed, 14 Oct 2026 20:27:02 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=git+bounces-72040-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 tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
by mail.dewy.ru (Postfix) with ESMTPS id AEFCB11017D; Wed, 14 Oct 2026 20:26:53 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.90.174.1])
by tor.lore.kernel.org (Postfix) with ESMTP id DA38F2E7B4; Wed, 14 Oct 2026 17:25:10 +0000 (UTC)
X-Received: from localhost.localdomain (localhost.localdomain [127.0.0.1])
by smtp.subspace.kernel.org (Postfix) with ESMTP id C29BA54A7E1;
Wed, 14 Oct 2026 17:25:09 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="k2ecZvBp"
X-Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.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 126163E024B
for <git@vger.kernel.org>; Wed, 14 Oct 2026 17:25:06 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.53
X-ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
t=1791998708; cv=none; b=Cd50QC2wbFG7DcQe9Mzj1ecz/YdZ+lr71SlhcAdrkrkZDD4KZi6AJyfM3J1ynLZWYmzFwS7wZKS6uowwONqtLDdG6GaRL+Y9QVFponXofoBggUTBg9pMNcv1WIS7WMGF4JbiMdw/puHHc1Tn++ePr6rUBdY0TxJhCipB42jeBPs=
X-ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org;
s=arc-20240116; t=1791998708; c=relaxed/simple;
bh=NcQa0pXlPGN/yrxYIcIPL4416s/PKYggwFIDqZ12ZEI=;
h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=Jr8zS/rEqJBRgUgjeQMK+ydC9OoSTbSJOieVCowa6RuXTQZy/D+6u72u2dt0j/VPmYtp1x+KVFlXtQk66kIsdZZGYG2EjRqNvy3ysC1EDd/2MbaZIO0MzodxT/ivdCybl05qT47+GpPVggvVu6SVwDZEsaECiOJJfXInR4V9hpQ=
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=k2ecZvBp; arc=none smtp.client-ip=209.85.221.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-wr1-f53.google.com with SMTP id ffacd0b85a97d-48b042c0759so3297312f8f.2
for <git@vger.kernel.org>; Wed, 14 Oct 2026 10:25:06 -0700 (PDT)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20251104; t=1791998705; x=1792603505; darn=vger.kernel.org;
h=content-transfer-encoding:mime-version:message-id:date:subject:cc
:to:from:from:to:cc:subject:date:message-id:reply-to:content-type;
bh=ExqWh9eWv6TicI092moE7SX2IVhbVL/RSB62YgyrWFs=;
b=k2ecZvBpfGXXjNpXXba3Vj6p4eFcaM2QKDyF7231JtsN/FXpDOyDJlYCbCSODrktF6
xV+3ZjCwRLGcR5Y76SE7tvTBuacY6yz5yaCf2TDCtIv/1XU0FQDEvOPN/e66Jda3Ffz3
kclXd8RqFLPq48z7sJ3cM+EskelyD9Q6cZR0+cWCO9qEQZpr1zZlRG4w3jW8pc4fRIeh
8Kn0Gw1BK84PDv9EAq3Iog/I3H1htdrbzb5D+giZCF5Sz7Ob/EB9VknCf3Xj0v5R8ZwF
y8RbAdNG1DVEk8spkbl4tDmvRWC8Kgul5toNrXmsoAX2H9Sal5qjFJizLJUB5nPgqRrd
9gog==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1791998705; x=1792603505;
h=content-transfer-encoding:mime-version: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=ExqWh9eWv6TicI092moE7SX2IVhbVL/RSB62YgyrWFs=;
b=HIK8UUmUR0cTq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-Received: by 2002:a05:6000:4a14:b0:487:15a3:1cab with SMTP id ffacd0b85a97d-48dbaadb081mr31235053f8f.18.1791998704979;
Wed, 14 Oct 2026 10:25:04 -0700 (PDT)
X-Received: from u.ad.analog.com (dynamic-078-054-209-001.78.54.pool.telefonica.de. [78.54.209.1])
by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48de0bc506asm13658916f8f.47.2026.10.14.10.25.04
(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
Wed, 14 Oct 2026 10:25:04 -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-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>