Article View: linux.kernel.git
Article #4182[PATCH v3] dir: ignore CRLF-empty and space-only lines in pattern files
From: Aniket Gupta
Date: Tue, 01 Dec 2026 08:00
Date: Tue, 01 Dec 2026 08:00
73 lines
13445 bytes
13445 bytes
add_patterns_from_buffer() skips an empty line which starts right at the
'\n', before it strips the '\r' or any trailing spaces. A two byte
"\r\n" line in a CRLF file, or a line that holds only spaces (with or
without the '\r') is not empty at that point. Stripping the '\r' and
calling trim_trailing_spaces() reduces it to an empty string, which is
then passed to add_pattern().
parse_path_pattern() turns that empty string into a 0 length pattern
with PATTERN_FLAG_NODIR. The directory walk checks a directory before it
appends the trailing slash. Thus, status and a plain add are not
affected. A path argument that ends in a slash is a different scenario.
For eg, with "git check-ignore foo/", the basename is empty and
match_basename() matches the 0 length pattern and "check-ignore -v"
names that line as the reason foo/ is ignored.
Cone-mode sparse-checkout is affected as well. For such a line,
add_pattern_to_hashsets() sees a pattern shorter than 2 characters,
warns "unrecognized pattern: ''" and disables cone pattern matching.
Skip calling add_pattern() when the trimmed line is empty. This follows
gitignore(5) which says that trailing spaces are ignored unless quoted
with backslash. A file name made of spaces can still be matched by
quoting the spaces.
Reported-by: Mike Beaton <mjsbeaton@gmail.com>
Signed-off-by: Aniket Gupta <aniketgupta3001@gmail.com>
---
Changes in v3:
- Say "path argument" instead of "path" and drop "like before" in the
log message (Matt).
dir.c | 3 ++-
t/t0008-ignores.sh | 7 +++++++
2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/dir.c b/dir.c
index d896e7be4b..5a8a28afef 100644
--- a/dir.c
+++ b/dir.c
@@ -1249,7 +1249,8 @@ int add_patterns_from_buffer(char *buf, size_t size,
if (entry != buf + i && entry[0] != '#') {
buf[i - (i && buf[i-1] == '\r')] = 0;
trim_trailing_spaces(entry);
- add_pattern(entry, base, baselen, pl, lineno);
+ if (*entry)
+ add_pattern(entry, base, baselen, pl, lineno);
}
lineno++;
entry = buf + i + 1;
diff --git a/t/t0008-ignores.sh b/t/t0008-ignores.sh
index ed95faf327..9884f67650 100755
--- a/t/t0008-ignores.sh
+++ b/t/t0008-ignores.sh
@@ -875,6 +875,13 @@ EOF
test_must_be_empty err
'
+test_expect_success 'trailing-slash directory is not ignored by CRLF-empty or space-only lines' '
+ printf "\r\n \n \r\n" >empty-lines &&
+ test_expect_code 1 git -c core.excludesfile=empty-lines \
+ check-ignore dir/ >actual &&
+ test_must_be_empty actual
+'
+
test_expect_success !MINGW 'quoting allows trailing whitespace' '
rm -rf whitespace &&
mkdir whitespace &&
base-commit: 03b41523c576f26ad34085378717a0c1b287470f
--
2.54.0 (Apple Git-157)
Technical Details
Message-ID:
<20261201080040.47247-1-aniketgupta3001@gmail.com>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!git+bounces-76752-linux-kernel-git=dewy.ruReferences:
<20261106182945.1316297-1-aniketgupta3001@gmail.com> <20261129060057.74590-1-aniketgupta3001@gmail.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!git+bounces-76752-linux-kernel-git=dewy.ru
From: aniketgupta3001@gmail.com (Aniket Gupta)
Newsgroups: linux.kernel.git
Subject: [PATCH v3] dir: ignore CRLF-empty and space-only lines in pattern files
Date: Tue, 1 Dec 2026 13:30:40 +0530
Organization: Usenet Network
Message-ID: <20261201080040.47247-1-aniketgupta3001@gmail.com>
References: <20261106182945.1316297-1-aniketgupta3001@gmail.com> <20261129060057.74590-1-aniketgupta3001@gmail.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
logging-data="1653663"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:KBZTW/CP+V2k0eyAJzXwC7TyQa8= sha256:A5gAxPsbzKmHFQfByEPDq0j8uTq63Dy8nROCr/GDS1A=
sha1:9MyuLEJZuVLgUkaEhHMSy669280= sha256:ofF6pl3mgeRAKdCHBHwHldd6w0f1oDgFOhrmb30advg=
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 997661172AD; Tue, 1 Dec 2026 11:01:10 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.148
X-Spam-Status: No, score=-3.148 tagged_above=-9999 required=6.31
tests=[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,
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 5uJ_sFb5wHEt;
Tue, 1 Dec 2026 11:01:06 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=git+bounces-76752-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 sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74])
by mail.dewy.ru (Postfix) with ESMTPS id C7070117240; Tue, 1 Dec 2026 11:00:57 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
by sto.lore.kernel.org (Postfix) with ESMTP id 38D9B601BFA; Tue, 1 Dec 2026 08:00:51 +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=1796112048;
b=Bj62yRgG03cxwoZRzSVmLYcjK+JOsHomVMYQ7EwRfnPnoFvie3XcPcwZ2A9nihtKlKuA
oegZ0KSE3gtbQeUe5SxiRVev6WNdIuJNCKwLmaeCZjcxZqh2MRTw/GX6VivSbthffBaM/
BUZYd3m2C6mEQUth4Ulu9J/HgE2i6e16xE2caiNqUb484I4CuYOCaAe71ifXkbLA6n5h2
ymEKA3VUH9Du7r7nglG9e4Tc03BbZum1Scrb8fxiatCroCVQNBiJArBAALvs/mYdD3mdU
HV1Nxz7Zw5TyG7Adi8NSQe9Eqalfl6SF2e2NCdoNLpG4irRX6yNyh4W8IKFJEedheOQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1796112048;
h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
X-Google-DKIM-Signature:X-Gm-Message-State:X-Gm-Gg:X-Received:
Received:From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:
References:X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
List-Unsubscribe:List-Owner:Precedence:MIME-Version:
Content-Transfer-Encoding;
bh=8aAmW5RsLtF9ubD9rkZzE1Ro9i8cO9ZKeZchkX12ajg=;
b=NCDrCjFNepsXKuHJPQW9fmYxFqMdkCAU7w3WJ1uGthWL7NAlSw4wpAH0YeKVIbIqsU0C
YRoC+JCN+fgMgl8YyPRsiHuQlU57xd7QxlzXHqmo7wUp61gIW6X1ZvyZBy6QIjdgv+XiY
NF2thCyLUw9YvmwBKwrfKSZPyKz64+b4DRu3tjiuCGQcaUzxezViqUXpR+wSVE1CC504N
TcRRMUG39nWEUXNMl88CokrRZf5cRFvnWTW5+DsA0C4zr7db3RjhhNr/JwR2A7HeZf72f
zFWOXfJRTRbTwPuX8P62S2u+b5LCkxK/wtpmOJxqAxE1Oz0qogxClDrMVQwTrP20Bwg==
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=aMvmUdsq;
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 D5886606A32D;
Tue, 1 Dec 2026 08:00:48 +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=aMvmUdsq
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.173
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1796112048;
b=zPK5pOjs5SIhnfxMGYPnbAer4V8xAYQAi861+T/veAJAdpf9s3ri6Mw2etZZAfjiosmA
2ScyEiIzxt6MygssL9Tnh1eRYY5pR9afPaqLztMAebPyCmuHW08l6/oXsZ5jjyK+u4Qt7
of/1UNl8g2dDxdGQGkGXTHDFDzx9Vl3Lx6YJr31wXozqxNBzcgYg446S9Uf4uX4m4khKC
tcYRAVUPo0qWeL/VeYRv94eg/xnBbrJx9KVgIaVpJg0yZ3ssFZWeC6nSbKf6jj8+PC4Ed
jST6JMoej7KjrTsMV24kFhXBBHHEdgv4h6Cvm5MFjF2W8kzngKRPwbGMZDQ9Yw8NG7g==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1796112048;
h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject:
Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version:
Content-Transfer-Encoding;
bh=8aAmW5RsLtF9ubD9rkZzE1Ro9i8cO9ZKeZchkX12ajg=;
b=FhPfEM1pVCkV8Clj65La0ePqpwlLEcpPndzcUgiZG86sA2ZfNjzHx+tLNqMESmGNBdJX
na7pfN2iz7WLbgl+tcxA/z9bEhszeNYF4ykwc4WeRcFSpn3AwDGfJ5zPNIf2Z5ur0ECLM
aDLuMqHgHN8AAn65uVJGjtInD4fPOGyZhhmB40Vo34boDYgZo8EueP1wPSNlx4Ra/44jx
Kc8sUKWkp4X8sV6vR7oi5+cuTS6a8TYXRMy5Fep0UKi4sljnXfGeJ3ahpLHBT33pKmlJz
SNNdgfGlD5z0mpLAcsTFFrCgUAgvA2kSJI+ZsgsZXEOToh36JnJr/bKKLmftVJsltuw==
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=aMvmUdsq;
arc=none smtp.remote-ip=209.85.210.173
X-Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173])
(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 95F1D606A31A
for <git@vger.kernel.org>; Tue, 1 Dec 2026 08:00:47 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 95F1D606A31A
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-pf1-f173.google.com with SMTP id d2e1a72fcca58-8b2382bf051so5992500b3a.3
for <git@vger.kernel.org>; Tue, 01 Dec 2026 00:00:47 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20260707; t=1796112047; x=1796716847; 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=8aAmW5RsLtF9ubD9rkZzE1Ro9i8cO9ZKeZchkX12ajg=;
b=aMvmUdsqq6rJzqwSassUSaoHS9qQKM9mrAOM0MybpTi4LUBRDhPRE3ZB9XW91oipIk
5FKitTzyf1yHAIRciCmSdmzt+13l5lOmPYQ5pD2G2NUSs/tCIWFrziRtGmcWfn//fnY+
Hgs3ug9LctKQsDngGLVSZJlU48SGDrD4I/1ZjoWxS1a6kAKJwBnuZPcBYACp2PhEsSb3
RUqc7TxJt1kNhF/9S7O3kfGjdxARH6plYTuRj98uyTvCnJ5iJAQ398TFGx9toneGhVW9
dCyl/OfZ441mKOJzbP367y1ZmhEUbmokDt7Lq43gmmiSRwXr87a9z5EdAZ8weceeah2h
a4sA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1796112047; x=1796716847;
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=8aAmW5RsLtF9ubD9rkZzE1Ro9i8cO9ZKeZchkX12ajg=;
b=HQ+nspYolAxEZj3lp8UdqKuaBWWgu9XGRAEzZfzNbLRBf+pxQsKO/MALgZjblRqIaL
RbVa/QEy82vCu0LJrBPNwPhx4l0kWmzlBhxzSV7wM+k7WPqg9+L8yMiezindZTrUkEMR
/KfjbcChjS7URKmAs53eHdXYuD5PDFAOg2HV9PTGvj5G7bGZAE1wmo5qG+dfPlrwE/s9
gRuczDNH3pt8XtKo3E1Ldl3VjnMY6SpVaexJ8wuC26fEpDjOyDaZBcaHjCskMuv4cLCB
kTHHTL/vmc0ImfZQYEIJWNAKNF58maryCKxxBVzYXmogINPwEnx/9HM8n8ragP40qpH8
ZKlg==
X-Gm-Message-State: APuU4Z/vdD0Nng0f7S0+vac3r7EUBSBRo6hY2FkshyBy4okTjnI5tUS4
kmrMZWRRuAl9A36IwLeUEbzUl6qerMa7cBxmiNvnG9tLfWFgGYk7G/UJP9HYDt6Ve40=
X-Gm-Gg: AZFdTZcEFRKRZRVkmxxq8l5A/jduX8ssbJBN1CQ3udreuN8B/FweReeDtGUiHnr2qZO
YcdxWMSZ9CGFZGo6AV1MKQikBTduaCE0x9K4+phg9vBZ7lYFFQ1ShivZknHHJYmceyO0YGoX8dC
1ZsmHh/mJuUqv0Swvk9qtSK7GSkYYnuHfVLpQtRg1EuE41QTS1UAQes1HD9dITsnsZzljlMH1xD
C29q86Gr5Jazr0d7A3CyJY4LiAR+3NU8i3anJGqomqLel7tywD8W9v6OMagHBFYZwxSyOXWin+b
5c0LXoIPHLrqF8SFRJfs2BLuHyLcuiVG433kRJYqyF6FNxhoWQG/8l5yt63nYntCa+dAUk+K+Zg
hLuubUOnv7Ox27SKwqMB8xT+BWUZZhWLtzJUpzANrj21sehfRxaki4Z0mBUOhQ/pmX1YJfy856L
1iqSuNyeaf9y/imkwqipfusjSqdwiXAJAMWaV28DGq+24qMHIexRzo1eOEZXZpqfAcgauYY07A5
EF4C9ZM1qrzUq46/GJ56UvKwW+oyh3D7wSrC5y716h9RQG63l14ukEbIcXWCLA2V9vuJM0ujiFZ
vYHwBgbdtionkNarcEmUKsQnI/iTVOhJizCGy6lmlkcSg8PrWNfvrepx+kbMUfSF1rhiK3CWKnI
+lTSsmrbna41CL1VwK3awdA==
X-Received: by 2002:a05:6a00:3491:b0:899:53a9:1dd9 with SMTP id d2e1a72fcca58-8c87d519a66mr32414477b3a.57.1796112046583;
Tue, 01 Dec 2026 00:00:46 -0800 (PST)
X-Received: from localhost.localdomain ([103.25.231.125])
by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-8c873442863sm19585533b3a.43.2026.12.01.00.00.44
(version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256);
Tue, 01 Dec 2026 00:00:46 -0800 (PST)
X-Cc: Junio C Hamano <gitster@pobox.com>,
Matt Hunter <m@lfurio.us>,
Mike Beaton <mjsbeaton@gmail.com>,
Phillip Wood <phillip.wood123@gmail.com>
X-Mailer: git-send-email 2.54.0
X-In-Reply-To: <20261129060057.74590-1-aniketgupta3001@gmail.com>
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