git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/4] dir.c: fix match_pathname()

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Feb 15, 2016, 09:03 UTC
Message-ID
<1455527019-7787-2-git-send-email-pclouds@gmail.com>
In-Reply-To
<1455527019-7787-1-git-send-email-pclouds@gmail.com>

Given the pattern "1/2/3/4" and the path "1/2/3/4/f", the pattern prefix is "1/2/3/4". We will compare and remove the prefix from both pattern and path and come to this code

	/*
	 * If the whole pattern did not have a wildcard,
	 * then our prefix match is all we need; we
	 * do not need to call fnmatch at all.
	 */
	if (!patternlen && !namelen)
		return 1;

where patternlen is zero (full pattern consumed) and the remaining path in "name" is "/f". We fail to realize it's matched in this case and fall back to fnmatch(), which also fails to catch it. Fix it.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 dir.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/dir.c b/dir.c
index f0b6d0a..bcaafac 100644
--- a/dir.c
+++ b/dir.c
@@ -878,7 +878,7 @@ int match_pathname(const char *pathname, int pathlen,
 		 * then our prefix match is all we need; we
 		 * do not need to call fnmatch at all.
 		 */
-		if (!patternlen && !namelen)
+		if (!patternlen && (!namelen || *name == '/'))
 			return 1;
 	}
 
-- 
2.7.0.377.g4cd97dd
Previous: Nguyễn Thái Ngọc DuyNext: Junio C Hamano
Message 2 of 10 in “.gitignore, reinclude rules, take 2”
  1. 0/4 .gitignore, reinclude rules, take 2Nguyễn Thái Ngọc Duy, Feb 15, 2016
  2. 1/4 dir.c: fix match_pathname()Nguyễn Thái Ngọc Duy, Feb 15, 2016
  3. Junio C HamanoFeb 15, 2016
  4. Duy NguyenFeb 16, 2016
  5. 2/4 dir.c: support tracing excludeNguyễn Thái Ngọc Duy, Feb 15, 2016
  6. 3/4 dir.c: support marking some patterns already matchedNguyễn Thái Ngọc Duy, Feb 15, 2016
  7. Junio C HamanoFeb 15, 2016
  8. Duy NguyenFeb 16, 2016
  9. 4/4 dir.c: don't exclude whole dir prematurelyNguyễn Thái Ngọc Duy, Feb 15, 2016
  10. Junio C HamanoFeb 15, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.