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

[PATCH 2/4] exclude: fix a bug in prefix compare optimization

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Oct 14, 2012, 11:55 UTC
Message-ID
<1350215742-20761-3-git-send-email-pclouds@gmail.com>
In-Reply-To
<1350215742-20761-1-git-send-email-pclouds@gmail.com>

When "namelen" becomes zero at this stage, we have matched the fixed part, but whether it actually matches the pattern still depends on the pattern in "exclude". As demonstrated in t3001, path "three/a.3" exists and it matches the "three/a.3" part in pattern "three/a.3[abc]", but that does not mean a true match.

Don't be too optimistic and let fnmatch() do the job.
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 dir.c                              | 2 +-
 t/t3001-ls-files-others-exclude.sh | 6 ++++++
 2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/dir.c b/dir.c
index d81498e..0f4aea6 100644
--- a/dir.c
+++ b/dir.c
@@ -601,7 +601,7 @@ int excluded_from_list(const char *pathname,
 			namelen -= prefix;
 		}
 
-		if (!namelen || !fnmatch_icase(exclude, name, FNM_PATHNAME))
+		if (!fnmatch_icase(exclude, name, FNM_PATHNAME))
 			return to_exclude;
 	}
 	return -1; /* undecided */
diff --git a/t/t3001-ls-files-others-exclude.sh b/t/t3001-ls-files-others-exclude.sh
index c8fe978..dc2f045 100755
--- a/t/t3001-ls-files-others-exclude.sh
+++ b/t/t3001-ls-files-others-exclude.sh
@@ -214,4 +214,10 @@ test_expect_success 'subdirectory ignore (l1)' '
 	test_cmp expect actual
 '
 
+test_expect_success 'pattern matches prefix completely' '
+	: >expect &&
+	git ls-files -i -o --exclude "/three/a.3[abc]" >actual &&
+	test_cmp expect actual
+'
+
 test_done
-- 
1.8.0.rc2.11.g2b79d01
Previous: Nguyễn Thái Ngọc DuyNext: Nguyễn Thái Ngọc Duy
Message 3 of 6 in “nd/attr-match-optim-more updates”
  1. 0/4 nd/attr-match-optim-more updatesNguyễn Thái Ngọc Duy, Oct 14, 2012
  2. 1/4 exclude: stricten a length check in EXC_FLAG_ENDSWITH caseNguyễn Thái Ngọc Duy, Oct 14, 2012
  3. 2/4 exclude: fix a bug in prefix compare optimizationNguyễn Thái Ngọc Duy, Oct 14, 2012
  4. 3/4 exclude/attr: share basename matching codeNguyễn Thái Ngọc Duy, Oct 14, 2012
  5. Junio C HamanoOct 14, 2012
  6. 4/4 exclude/attr: share full pathname matching codeNguyễn Thái Ngọc Duy, Oct 14, 2012

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.