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

[PATCH 5/5] ce_path_match: drop prefix matching in favor of match_pathspec

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Sep 19, 2010, 23:30 UTC
Message-ID
<1284939000-16907-6-git-send-email-pclouds@gmail.com>
In-Reply-To
<1284939000-16907-1-git-send-email-pclouds@gmail.com>

ce_path_match() and tree_entry_interesting() are two functions that do entry filtering when traversing trees. Now that tree_entry_interesting() understands wildcard, ce_path_match() can just use match_pathspec() to also understand wildcard.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 read-cache.c             |   25 +------------------------
 t/t4010-diff-pathspec.sh |    9 +++++++++
 2 files changed, 10 insertions(+), 24 deletions(-)
diff --git a/read-cache.c b/read-cache.c
index 918a90c..c67d9e0 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -685,30 +685,7 @@ int ce_same_name(struct cache_entry *a, struct cache_entry *b)
 
 int ce_path_match(const struct cache_entry *ce, const struct pathspec *pathspec)
 {
-	const char *match, *name;
-	const char **p;
-	int len;
-
-	if (!pathspec || !pathspec->nr)
-		return 1;
-
-	len = ce_namelen(ce);
-	name = ce->name;
-	p = pathspec->raw;
-	while ((match = *p++) != NULL) {
-		int matchlen = strlen(match);
-		if (matchlen > len)
-			continue;
-		if (memcmp(name, match, matchlen))
-			continue;
-		if (matchlen && name[matchlen-1] == '/')
-			return 1;
-		if (name[matchlen] == '/' || !name[matchlen])
-			return 1;
-		if (!matchlen)
-			return 1;
-	}
-	return 0;
+	return match_pathspec(pathspec->raw, ce->name, ce_namelen(ce), 0, NULL) > 0;
 }
 
 /*
diff --git a/t/t4010-diff-pathspec.sh b/t/t4010-diff-pathspec.sh
index 4b120f8..d50fd2d 100755
--- a/t/t4010-diff-pathspec.sh
+++ b/t/t4010-diff-pathspec.sh
@@ -55,6 +55,15 @@ test_expect_success \
     'git diff-index --cached $tree -- file0 >current &&
      compare_diff_raw current expected'
 
+cat >expected.template <<\EOF
+:100644 100644 766498d93a4b06057a8e49d23f4068f1170ff38f 0a41e115ab61be0328a19b29f18cdcb49338d516 M	path1/file1
+EOF
+test_expect_success 'diff-index with wildcard' '
+	git diff-index --cached $tree -- "*1" >current &&
+	cp expected.template expected &&
+	compare_diff_raw current expected
+'
+
 cat >expected <<\EOF
 EOF
 test_expect_success \
-- 
1.7.1.rc1.70.g788ca
Previous: Nguyễn Thái Ngọc Duy
Message 9 of 9 in “Globbing support in diff family”
  1. 0/5 Globbing support in diff familyNguyễn Thái Ngọc Duy, Sep 19, 2010
  2. 1/5 pathspec: mark wildcard pathspecs from the beginningNguyễn Thái Ngọc Duy, Sep 19, 2010
  3. 2/5 pathspec: add tree_recursive_diff parameterNguyễn Thái Ngọc Duy, Sep 19, 2010
  4. Junio C HamanoSep 27, 2010
  5. Nguyen Thai Ngoc DuySep 28, 2010
  6. Junio C HamanoSep 28, 2010
  7. 3/5 tree_entry_interesting: turn to match_pathspec if wildcard is presentNguyễn Thái Ngọc Duy, Sep 19, 2010
  8. 4/5 Convert ce_path_match() to use struct pathspecNguyễn Thái Ngọc Duy, Sep 19, 2010
  9. 5/5 ce_path_match: drop prefix matching in favor of match_pathspecNguyễn Thái Ngọc Duy, Sep 19, 2010

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.