Article View: linux.kernel.git
Article #4068Re: [PATCH v2] dir: ignore CRLF-empty and space-only lines in pattern files
From: "Matt Hunter"
Date: Sun, 29 Nov 2026 11:14
Date: Sun, 29 Nov 2026 11:14
73 lines
10896 bytes
10896 bytes
On Sun Nov 29, 2026 at 1:00 AM EST, Aniket Gupta wrote: > 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 that ends in a slash is a different scenario. For eg, s/path/path argument/ ? Outside of a user's spelling, a directory name would not actually contain a slash, right? > 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, like before. Perhaps drop the "like before", since "still be matched" suggests unchanged behavior. > > Reported-by: Mike Beaton <mjsbeaton@gmail.com> > Signed-off-by: Aniket Gupta <aniketgupta3001@gmail.com> > --- > Changes in v2: > > - Rewrite the log message without the word "blank" (Junio). > - Explain in the log message why status and add are not affected, > with check-ignore as the example (Matt), and mention that > cone-mode sparse-checkout warns on such lines (Junio). > - Rename the test and drop the mkdir (Matt). > - Keep the fix in add_patterns_from_buffer() instead of moving it > into match_basename() as I suggested to Matt. Cone mode warns > before any matching runs (Junio), so the line has to be skipped > here. I think this is the better choice. > Making match_basename() reject empty patterns can be a > separate change. > > @@ -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' ' I debated suggesting to say "patterns" instead of "lines" here. But the word "lines" is used much more consistently throughout the patch (and doing so makes more sense). So never mind? > + 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 The updated test looks good.
Technical Details
Message-ID:
<DN7NG3OHVFKZ.X7LE2MUJVZJ8@lfurio.us>Path:
mbox-mo1.pugleaf.net!srl.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-76622-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!srl.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-76622-linux-kernel-git=dewy.ru
From: m@lfurio.us ("Matt Hunter")
Newsgroups: linux.kernel.git
Subject: Re: [PATCH v2] dir: ignore CRLF-empty and space-only lines in
pattern files
Date: Sun, 29 Nov 2026 06:14:21 -0500
Organization: Usenet Network
Message-ID: <DN7NG3OHVFKZ.X7LE2MUJVZJ8@lfurio.us>
References: <20261106182945.1316297-1-aniketgupta3001@gmail.com>
<20261129060057.74590-1-aniketgupta3001@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Injection-Info: usenet.network;
logging-data="1157365"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:QCtGa6cKS9NmFX56RRrcL2/CLzo= sha256:yyUsKM/cWmivOHBq28aCDIFMnZbjaa+bnZMGQGjC/rM=
sha1:eX3F43647XOhR4zghWIK67V74r4= sha256:SreEVlB8oe3VAJbJpaFRd31myRQokSeZc3bTypxGA0o=
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 0DA15125CEE; Sun, 29 Nov 2026 14:15:05 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -1.951
X-Spam-Status: No, score=-1.951 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]
autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (1024-bit key)
header.d=lfurio.us
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 KwVe-rux1ley;
Sun, 29 Nov 2026 14:15:02 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=git+bounces-76622-linux-kernel-git=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=lfurio.us
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
by mail.dewy.ru (Postfix) with ESMTPS id 90E33125F94; Sun, 29 Nov 2026 14:14:52 +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 77F242482E; Sun, 29 Nov 2026 11:14:50 +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=1795950890;
b=agi+Lh2I1cNe+7MOFksYyM6irP2wXcuI3PwqebIIOJxrSwo3a8jrKw+h4K13oPy/T/LK
ZNVDoMBofDxfW9N5RrXaoECEzpz6XEpVA/2Hkwy9R1asKODo7FVqK3N/zxnMpURuIk65m
27CJVLZw/EYP2EPfYWtS/FJYYiYqi0pbPfcjO6Uf9Vo2TZOoSIg0NRQgk++NnAS8BQqdx
wXaN0r/WaHYRrohNFwF5srj5HDKLUnuyzT9GQqpCIKIoPAarS8Zrbg+0yM3PtPanlr3kx
QTXNVFHoRXc7tzb6OEk5Zw5Rl4p0kwBORRr+0k4sL784cd9IAxwbUHEi5xPAWiXufnw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1795950890;
h=X-Original-To:Received:DMARC-Filter:DKIM-Signature:Received:
X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
List-Unsubscribe:List-Owner:Precedence:Mime-Version:
Content-Transfer-Encoding:Content-Type:Date:Message-Id:Subject:Cc:To:
From:X-Mailer:References:In-Reply-To;
bh=WbnUDAOH/zhfwqmdHLkpLDhaTvgHMVRkOv1wsUARMvk=;
b=4zzClu/GBuVmyAfaxiVoYNTLoCsv8BYIkOZNeTdzSRs89vDsNCpl4SRDE4e2lRzxaKdZ
EX8qgyJSlD6Ca9XZNL0GWLPV6FUmlyKZEW99D9TG2veqJI+asSt2Sc1Kml8GbPrpgdbLr
njqXbKCDtGT39Gx/5EZPk91sM9NfiEpsi4+knJazuw+lhAWiQQh/f2z1UIjz1PvB3I/4w
AiwUQ1a545aecvV5i3AtBXDYZaM/LL3xghXSgT1DBShz2TyqoBRbOqeLIpIVyrGe3Qjf3
hm7/hsLNiG2x3PptzeAjedUi9UmaoD6iEbxUbnMQ19NqxkjNwAD3zBwkNPAs6um2jcw==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org;
dkim=pass header.d=lfurio.us header.i=@lfurio.us header.a=rsa-sha256 header.s=default header.b=Px5tNFkN;
dmarc=pass header.from=lfurio.us;
spf=pass smtp.mailfrom=lfurio.us;
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 43F5B606A327;
Sun, 29 Nov 2026 11:14:50 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (1024-bit key) header.d=lfurio.us header.i=@lfurio.us header.a=rsa-sha256 header.s=default header.b=Px5tNFkN
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=157.230.60.252
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1795950889;
b=u4feQNb0SGVFBAAVyL1Ap4nka+KdiTKAZhUNVAcNmMg5yJ/Rz8K+y/B0HeWmOU/hYMl5
HC5o0LbMat2zbWdoqR8le4MSVMFrh7GvW0vrUpgKreLmU3Ic8DbTrig7zjqFOlP9u1sHZ
D7poqeOCJL1ZgBLHcOaGbj8XA8kQ7aRiS6wshOPfnJ2gDaXpb/Ej+veBLr94Ega5MxJ8L
2SZXOqDe+bXNrQu0VPh3aB/B+X4e+KAOpNAzxwb9rSYNwBdGopmjsL1EbFU5GD2qBumk1
FLe1KnJe7GUxDRIot9U0rZ3tPgpI41kvN8HvPJSY0s8jfwmu4y96TwiGpzW30fY1e1w==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1795950889;
h=DMARC-Filter:DKIM-Signature:Received:Mime-Version:
Content-Transfer-Encoding:Content-Type:Date:Message-Id:Subject:Cc:To:
From:X-Mailer:References:In-Reply-To;
bh=WbnUDAOH/zhfwqmdHLkpLDhaTvgHMVRkOv1wsUARMvk=;
b=ybkhdfpVknOh2jwE8BiL4UtXn154GWkeQFVLNpujvnGBlLQnyTpi+qr915hycRkDhS+B
XH5lPDMtcNj/vJrm/UfgekppFAEI6cJyZVaBfwGZTDMsE6JYgKtWr2ZdappXd9ISCcjCa
HmjDd7BX7sAOncRfryWvfK5qHLQ6SmhDovfpnOksOYD0fBUISZcphngaPdeV6AxKn4oyi
IIk6WB4zHmBkfmwdq7GKpa91kkZ9lS4uOUxmliT+Ao/3x5R+HlIT6wqK0F0FoSP0Q4EsL
oB4r31Q1iy2NNLd+AMhYm0G1qIEioZP/0VbnkzeWYeQ18T5Evs79olFCeEV31M1C3sw==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org;
dmarc=pass header.from=lfurio.us;
spf=pass smtp.mailfrom=lfurio.us;
dkim=pass header.d=lfurio.us header.i=@lfurio.us header.a=rsa-sha256 header.s=default header.b=Px5tNFkN;
arc=none smtp.remote-ip=157.230.60.252
X-Received: from mail.normalmode.org (h01.normalmode.org [157.230.60.252])
(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
(No client certificate requested)
by smtp.subspace.kernel.org (Postfix) with ESMTPS id D10BA606A323
for <git@vger.kernel.org>; Sun, 29 Nov 2026 11:14:48 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D10BA606A323
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lfurio.us
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=lfurio.us
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=lfurio.us; s=default;
t=1795950887; bh=cBsDkeDamnQXdtGibvU7oszkl3chOwShRBiYX5I1RmQ=;
h=Date:Subject:Cc:To:From:References:In-Reply-To:From;
b=Px5tNFkNmZYj3MxD6qyWOuHs5thGc2wBts9OcWFW+ebFKWTViyV0zZB0NkAbkIVeN
NXMvd384YZh+DMwD8d4q7jUg3P0XBQG4P7mn0Sx6ipi2gzts3Br/xUfWDLZ3ZASwO8
+WDt9h/Om3AZneFeNUcDEpAzVw2VexqsDSeNIoF0=
X-Received: by mail.normalmode.org (Postfix) with ESMTPSA id 7C2BB63B1E;
Sun, 29 Nov 2026 11:14:47 +0000 (UTC)
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-Cc: "Junio C Hamano" <gitster@pobox.com>, "Mike Beaton"
<mjsbeaton@gmail.com>, "Phillip Wood" <phillip.wood123@gmail.com>
X-Mailer: aerc 0.21.0-0-g5549850facc2
X-In-Reply-To: <20261129060057.74590-1-aniketgupta3001@gmail.com>