🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.git
Article #4063

[PATCH v2] dir: ignore CRLF-empty and space-only lines in pattern files

#4063
From: Aniket Gupta
Date: Sun, 29 Nov 2026 06:00
83 lines
13987 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 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, like before.

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. Making match_basename() reject empty patterns can be a
   separate change.

Thanks Junio and Matt for the review.

 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: <20261129060057.74590-1-aniketgupta3001@gmail.com>
Path: mbox-mo1.pugleaf.net!news-can.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!git+bounces-76617-linux-kernel-git=dewy.ru
References: <20261106182945.1316297-1-aniketgupta3001@gmail.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-can.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!git+bounces-76617-linux-kernel-git=dewy.ru
From: aniketgupta3001@gmail.com (Aniket Gupta)
Newsgroups: linux.kernel.git
Subject: [PATCH v2] dir: ignore CRLF-empty and space-only lines in pattern files
Date: Sun, 29 Nov 2026 11:30:57 +0530
Organization: Usenet Network
Message-ID: <20261129060057.74590-1-aniketgupta3001@gmail.com>
References: <20261106182945.1316297-1-aniketgupta3001@gmail.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="1114277"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:WBmxwtX9Sf98VHYhqouK7xjt2/0= sha256:X4PRrS1LOjXmjzLYyt5Djx+afERVng6zej860a/ifr8=
	sha1:61DJDweZOT3j6bz0Z6qYAgedRYc= sha256:F/cU08WMYcklToSDkO6bPFkWnmouK/+ku01YHyI6mQQ=
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 93543125F95; Sun, 29 Nov 2026 09:01:22 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -1.948
X-Spam-Status: No, score=-1.948 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, 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 gVVC293P1D3j;
	Sun, 29 Nov 2026 09:01:19 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=git+bounces-76617-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 5CE45125F8A; Sun, 29 Nov 2026 09:01:09 +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 BA8E326036; Sun, 29 Nov 2026 06:01:06 +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=1795932066;
	b=EH9f9gHJAUf+SFOiZlSVTDhFkyG8iw8+7F8yIvjnAzOXxISiVyFZsKG+t26KxXRsE9Xd
	 KdGxFWb0XfgofR/D2pUjHzbunLBOQsbALx8/l5B6umSbx/FQWm4aVCTPo3mcgCtVKTVMs
	 1Y8MbdnqOoZ2gPw06MPp36YEJ3RcJfdK5ftQb2cmFJfhv05JAvLOOibkGMMwRKqBbBMX3
	 eeR4umT9ZTRwFl/QuhPDWBTimxoevNKVS9Xxu9GRMfACqXxtXYXURGFcv4cm1wfAjiNzL
	 oz48mw1yUpFdSt2ZtYHc5DYCgpO3AL80OoU4jqq0Bw5kWsx6DOc/xcdy97M2mMaMBIw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795932066;
	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=+YUObsSmi8Tv9FrxZlFrFnkotLzkUnUi32Y1NGh1KnQ=;
	b=H/v+Oj0YB2//b4kBksfwsknS6zM8QqNaU4KEPAbfKfI2w0tjKuazKe5Q2XGYcp6odTuV
	 a7V6ZxEUuh/41rmYTuNwIWyxUUTx33Jc5/1vZL/kC5ZwF8sTPJUyfOskPuTD8QSUq/3yu
	 hujRtwmpd1s6lc4ifE1MSrQCazyuCqBaVTLC9A9RQ1W3wfh6poVNGcG8Ioxw++XlSuaYk
	 FL9KcP3eunTJBN6Hd5rvoPmxsWXL9OwfIbVblVz81YMf2Mt62p3FlajebSZIhOfO/WyVf
	 7EQJzJOv9KS638ONL4Uy1egLPRp63Tl3xlAPCsu1jd3cKqyIec4d18VKfBooE6ya4sQ==
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=issRkgJc;
	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 21F7C606A329;
	Sun, 29 Nov 2026 06:01:06 +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=issRkgJc
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.214.178
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1795932065;
	b=Qbqz3LFSSOQeBVEnI3rM+4SrIPuQeE7gCOsZFn3UzCdHzKnTsS3uMrr8h49aH8hW6w2v
	 ufD1hePmgbc1jWKJxvAqtVF+sQXVyeE7843jhlj8GqQKN7yhpE9PUUncN5R5cWwCooNs1
	 A/Q5uj8utg2Kdt/veRhtkunKy41R07sGTclxztnpBKqZsRyWbtmOGdweWIMobb67TvBIa
	 sFUdchExQa7daFbq4PNfH0rUk9Y+rG+QqeaaYnzVYFt7sidav9wgRP7RMruJ2nBNWRx7v
	 YB2pBPLbuyNoVPZQomSz7s4u+Lxf33MCIs8mxzu34WRTeE/1xZZFNAP+2vRvu5WbwZg==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795932065;
	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=+YUObsSmi8Tv9FrxZlFrFnkotLzkUnUi32Y1NGh1KnQ=;
	b=OEBsLIz05B3q+2eYza9bvRt9sNicd/EE0S/dzXy3jNhrXZqrNzGVfqINdntVDkxO000R
	 CRWqvmzgaP0aEqhQ3kRvJccHv0tvph/1Q3rGe/96Tvvj8wPU89lngFJqievQOJUeEcEsc
	 s5JRFrJ0XYsYQfP5y5cxDVld7nF8qfD1PeHIMvRck+0pr3L7/eI5I4hWkSujrXv23aVQW
	 zKYb1yeQ+xP+xsKKNdPESN5dSeGQHapJSuY2IhKOdjW7xsmCeUPR1tVfZ1/VgDafFzNAJ
	 wscQzouRCwXD6tcaYqt8SuZI7WLjfOgaxYnjSy/wZyMOsPKGD5U4yAz6pfXlK6w6qQg==
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=issRkgJc;
	arc=none smtp.remote-ip=209.85.214.178
X-Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178])
	(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 DECA1606A31C
	for <git@vger.kernel.org>; Sun, 29 Nov 2026 06:01:04 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org DECA1606A31C
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-pl1-f178.google.com with SMTP id d9443c01a7336-2f0426a65e0so54913065ad.3
        for <git@vger.kernel.org>; Sat, 28 Nov 2026 22:01:04 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20260707; t=1795932064; x=1796536864; 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=+YUObsSmi8Tv9FrxZlFrFnkotLzkUnUi32Y1NGh1KnQ=;
        b=issRkgJcHnX3Hlq4yFEMDqosDR6oxyf9JWNRU//bf1zeIZK1ezEUwxbu05kQo8U3OW
         2MJ/tyJc6CQy1iJIQNuGFV+lunyMQm1KvV9CVS/FKKb8TrnjbqpT0LfwYzxVIIBdbLaU
         4MTvz+wCYb0mbBpKHt+Evmv4Q/YRa8WtwLDQ0iES6eE9YFnhmY2DNzM+ydvXmAFeyYt8
         ht8mGdHyxIfeyqMzrW3TQyszxkzwHCK5cr0J5Hwmu1IXxrusRLB5umUv+PCx3EfRxAm4
         HNza/6W89EXKvZKRzqvsdxdQ7g4GiKq/PLg08KzT9S2SM24MAKyK5+k/5hoOXNmVP0fa
         85vg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20260707; t=1795932064; x=1796536864;
        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=+YUObsSmi8Tv9FrxZlFrFnkotLzkUnUi32Y1NGh1KnQ=;
        b=AwtIwjw0DlCT4eV+YiWyboSdt1Yi0ODZ0+H8Q7Y0fqNQPUjNKk6tazfoxDyifwFv28
         m/jXrYHIOMsmTDtehbpeFhCXbb0NUKL3DFjTvm0Cf4st/9HSYg3nj6a5LDAD8awp8b7/
         T2Nf0HDNj2R3UiiABFd+KMKXATBwYh4eQX91OD3BmbX25yt+CbEgJOAMWpxv0nDTONd7
         cXZjN17qq9dNtzLN7QUG5wQTfjsaW77MVvvsaPOngQtX1dW9c+5ZFbYrkSdE1i+ZyWSI
         KIXUSqTcuUuT35YeNPfnkSMeOllNPCKSuZp6utFEPEdlz7ZuwgxoewFioKZ984xR+h8Q
         gHwA==
X-Gm-Message-State: APuU4Z8uU3zcD91JgMiF3K0ZERGV3D3S4uLemyAemS0mjkS/ug0VHk9g
	tL7QGMi/5sHZbSQBJBunQq0dIZ1l6POkZaVCQGzcrRzz2oLWmKZOT2LeeMg+PXsJjDY=
X-Gm-Gg: AZFdTZcZJdKae2E6S+rQqJuKoOcJ2op6zkyuKwg4k8okI3fYNz3cWNdMTGYBsgMdnH4
	Zq6oIZOHGwaX69Zfa/D/XILExgTdwOKm8qUNmlGJW/maQS7DCjY+V83jU6eVQ0ReaDtp4KW4k1K
	JcDc10UDNbNmss9HJhX5oxcZrwFiTxdyN/UjrdRS6Oy/nYEDZReia6DMN7l8V3ESdoyaDpV7+rD
	kZdaU1ZfdsGEajtMyAlFR0Tn046pSwPr9/sYszVLNxxfYqtPdDJfRkmmP18pmQOdqBuVTu2bu0q
	V5NHU+L0PR8u21vdkUuEAwVTxiC6Fg0byo/lyqqNWfGz+rMbAW4wg//L+F7TpFFqPqvzzNn7mjA
	qRRqVIT/4OUC8oFxl/kJ72scQKlKR3E8o6zv8PoF+p5856O+T83IOC2d+6xryLJw+3iqTI1bqMA
	RCItjTc6ceVZy0rY0aDxh1DtO0qEoVhXDVQnN2SRO9YwYsu3LelvKaWAjHZOYPVKnpLuSWa8Ddj
	FCOQMFk1N3GWC+AMzUF6YWO+RPWEvcy0svyjmq4NpXV0Ptsd1tDKJ2b3NMITrV2TGm3NGQuUxPB
	PuP7FhxZ1cSF8p8m6bg1SVtt+QOS/DuKyKbvg6GWA0MZS3ti9w6aC5IWZdr61fGfQEOLLFqKJic
	fHMIKGyO9h1libP1CQDQG
X-Received: by 2002:a17:902:cec4:b0:2f0:436d:bdc1 with SMTP id d9443c01a7336-2f0436dc431mr270748675ad.33.1795932064109;
        Sat, 28 Nov 2026 22:01:04 -0800 (PST)
X-Received: from localhost.localdomain ([223.190.82.63])
        by smtp.gmail.com with ESMTPSA id d9443c01a7336-2f03f15663fsm143553065ad.76.2026.11.28.22.01.01
        (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256);
        Sat, 28 Nov 2026 22:01:03 -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: <20261106182945.1316297-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