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

[PATCH v2 2/9] Convert some match_pathspec_depth() to dir_path_match()

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Jan 24, 2014, 13:40 UTC
Message-ID
<1390570836-20394-3-git-send-email-pclouds@gmail.com>
In-Reply-To
<1390570836-20394-1-git-send-email-pclouds@gmail.com>

This helps reduce the number of match_pathspec_depth() call sites and show how m_p_d() is used. And it usage is:

 - match against an index entry (ce_path_match or match_pathspec_depth
   in ls-files)
 - match against a dir_entry from read_directory (dir_path_match and
   match_pathspec_depth in clean.c, which will be converted later)
 - resolve-undo (rerere.c and ls-files.c)
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 builtin/add.c      | 3 +--
 builtin/grep.c     | 4 +---
 builtin/ls-files.c | 2 +-
 dir.h              | 7 +++++++
 wt-status.c        | 4 ++--
 5 files changed, 12 insertions(+), 8 deletions(-)
diff --git a/builtin/add.c b/builtin/add.c
index 2a2722f..672adc0 100644
--- a/builtin/add.c
+++ b/builtin/add.c
@@ -208,8 +208,7 @@ static char *prune_directory(struct dir_struct *dir, struct pathspec *pathspec,
 	i = dir->nr;
 	while (--i >= 0) {
 		struct dir_entry *entry = *src++;
-		if (match_pathspec_depth(pathspec, entry->name, entry->len,
-					 prefix, seen))
+		if (dir_path_match(entry, pathspec, prefix, seen))
 			*dst++ = entry;
 		else if (flag & WARN_IMPLICIT_DOT)
 			/*
diff --git a/builtin/grep.c b/builtin/grep.c
index 3d924c2..69ac2d8 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -524,9 +524,7 @@ static int grep_directory(struct grep_opt *opt, const struct pathspec *pathspec,
 
 	fill_directory(&dir, pathspec);
 	for (i = 0; i < dir.nr; i++) {
-		const char *name = dir.entries[i]->name;
-		int namelen = strlen(name);
-		if (!match_pathspec_depth(pathspec, name, namelen, 0, NULL))
+		if (!dir_path_match(dir.entries[i], pathspec, 0, NULL))
 			continue;
 		hit |= grep_file(opt, dir.entries[i]->name);
 		if (hit && opt->status_only)
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index e1cf6d8..e238608 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -64,7 +64,7 @@ static void show_dir_entry(const char *tag, struct dir_entry *ent)
 	if (len >= ent->len)
 		die("git ls-files: internal error - directory entry not superset of prefix");
 
-	if (!match_pathspec_depth(&pathspec, ent->name, ent->len, len, ps_matched))
+	if (!dir_path_match(ent, &pathspec, len, ps_matched))
 		return;
 
 	fputs(tag, stdout);
diff --git a/dir.h b/dir.h
index 42793e5..65f54b6 100644
--- a/dir.h
+++ b/dir.h
@@ -212,4 +212,11 @@ static inline int ce_path_match(const struct cache_entry *ce,
 	return match_pathspec_depth(pathspec, ce->name, ce_namelen(ce), 0, seen);
 }
 
+static inline int dir_path_match(const struct dir_entry *ent,
+				 const struct pathspec *pathspec,
+				 int prefix, char *seen)
+{
+	return match_pathspec_depth(pathspec, ent->name, ent->len, prefix, seen);
+}
+
 #endif
diff --git a/wt-status.c b/wt-status.c
index 295c09e..a452407 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -552,7 +552,7 @@ static void wt_status_collect_untracked(struct wt_status *s)
 	for (i = 0; i < dir.nr; i++) {
 		struct dir_entry *ent = dir.entries[i];
 		if (cache_name_is_other(ent->name, ent->len) &&
-		    match_pathspec_depth(&s->pathspec, ent->name, ent->len, 0, NULL))
+		    dir_path_match(ent, &s->pathspec, 0, NULL))
 			string_list_insert(&s->untracked, ent->name);
 		free(ent);
 	}
@@ -560,7 +560,7 @@ static void wt_status_collect_untracked(struct wt_status *s)
 	for (i = 0; i < dir.ignored_nr; i++) {
 		struct dir_entry *ent = dir.ignored[i];
 		if (cache_name_is_other(ent->name, ent->len) &&
-		    match_pathspec_depth(&s->pathspec, ent->name, ent->len, 0, NULL))
+		    dir_path_match(ent, &s->pathspec, 0, NULL))
 			string_list_insert(&s->ignored, ent->name);
 		free(ent);
 	}
-- 
1.8.5.2.240.g8478abd
Previous: Nguyễn Thái Ngọc DuyNext: Nguyễn Thái Ngọc Duy
Message 12 of 24 in “problematic git log submodule-dir/”
  1. Paweł SikoraJan 20, 2014
  2. Jens LehmannJan 22, 2014
  3. Duy NguyenJan 22, 2014
  4. 1/2 tree-walk.c: ignore trailing slash on submodule in tree_entry_interesting()Nguyễn Thái Ngọc Duy, Jan 23, 2014
  5. 2/2 t4010: match_pathspec_depth() and trailing slash after submoduleNguyễn Thái Ngọc Duy, Jan 23, 2014
  6. Junio C HamanoJan 23, 2014
  7. Jens LehmannJan 23, 2014
  8. Junio C HamanoJan 23, 2014
  9. Duy NguyenJan 24, 2014
  10. 0/9 About the trailing slashesNguyễn Thái Ngọc Duy, Jan 24, 2014
  11. 1/9 Convert some match_pathspec_depth() to ce_path_match()Nguyễn Thái Ngọc Duy, Jan 24, 2014
  12. 2/9 Convert some match_pathspec_depth() to dir_path_match()Nguyễn Thái Ngọc Duy, Jan 24, 2014
  13. 3/9 Rename match_pathspec_depth() to match_pathspec()Nguyễn Thái Ngọc Duy, Jan 24, 2014
  14. 4/9 dir.c: prepare match_pathspec_item for taking more flagsNguyễn Thái Ngọc Duy, Jan 24, 2014
  15. 5/9 match_pathspec: match pathspec "foo/" against directory "foo"Nguyễn Thái Ngọc Duy, Jan 24, 2014
  16. 6/9 Pass directory indicator to match_pathspec_item()Nguyễn Thái Ngọc Duy, Jan 24, 2014
  17. Eric SunshineJan 24, 2014
  18. Duy NguyenJan 25, 2014
  19. 7/9 clean: replace match_pathspec() with dir_path_match()Nguyễn Thái Ngọc Duy, Jan 24, 2014
  20. 8/9 clean: use cache_name_is_other()Nguyễn Thái Ngọc Duy, Jan 24, 2014
  21. 9/9 tree-walk.c: ignore trailing slash on submodule in tree_entry_interesting()Nguyễn Thái Ngọc Duy, Jan 24, 2014
  22. Junio C HamanoJan 24, 2014
  23. Duy NguyenJan 25, 2014
  24. Junio C HamanoJan 27, 2014

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.