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

[PATCH RFC] Convert ce_path_match() use to match_pathspec()

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
May 25, 2009, 08:42 UTC
Message-ID
<1243240924-5981-1-git-send-email-pclouds@gmail.com>

Back in history, ce_path_match() was first introduced in commit fdee7d07ba6c79b3e5125e96adbe1d9c3e75ce1d, in diff-cache.c. It seems to be used to handle pathspec that we have today. But it did not support wildcards.

About one year later, match_pathspec() was introduced as match() in commit 0d78153952e70c21e94dc6b7eefcb2ac5337a902, builtin-add.c. This version supported wildcards.

For some reasons diff code did not get converted to use match_pathspec(). So diff commands do not understand wildcards. I was not here that time to know the reasons. But I find it quite handy to do "git diff -- '*.sh'", just like the rest of git commands.

Hence this patch, which simply calls match_pathspec() inside ce_path_match(). With this, "git diff-files" and "git diff-index" now support wildcards. "git diff-tree" does not because it does not use ce_path_match().

"git update-index --again" is also affected (in a good way hopefully)
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 So.. comments?
 read-cache.c |   20 +-------------------
 1 files changed, 1 insertions(+), 19 deletions(-)
diff --git a/read-cache.c b/read-cache.c
index 3f58711..d2daf01 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -677,28 +677,10 @@ int ce_same_name(struct cache_entry *a, struct cache_entry *b)
 
 int ce_path_match(const struct cache_entry *ce, const char **pathspec)
 {
-	const char *match, *name;
-	int len;
-
 	if (!pathspec)
 		return 1;
 
-	len = ce_namelen(ce);
-	name = ce->name;
-	while ((match = *pathspec++) != 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, ce->name, ce_namelen(ce), 0, NULL);
 }
 
 /*
-- 
test
Next: Junio C Hamano
Message 1 of 3 in “Convert ce_path_match() use to match_pathspec()”
  1. Convert ce_path_match() use to match_pathspec()Nguyễn Thái Ngọc Duy, May 25, 2009
  2. Junio C HamanoMay 25, 2009
  3. Nguyen Thai Ngoc DuyMay 26, 2009

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.