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

[PATCH v3 24/31] Convert {read,fill}_directory to take struct pathspec

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Jan 13, 2013, 12:35 UTC
Message-ID
<1358080539-17436-25-git-send-email-pclouds@gmail.com>
In-Reply-To
<1358080539-17436-1-git-send-email-pclouds@gmail.com>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 builtin/add.c      |  2 +-
 builtin/clean.c    |  2 +-
 builtin/grep.c     |  2 +-
 builtin/ls-files.c |  2 +-
 dir.c              | 16 +++++++++++-----
 dir.h              |  4 ++--
 wt-status.c        |  4 ++--
 7 files changed, 19 insertions(+), 13 deletions(-)
diff --git a/builtin/add.c b/builtin/add.c
index 7069b77..dcea98f 100644
--- a/builtin/add.c
+++ b/builtin/add.c
@@ -397,7 +397,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
 		}
 
 		/* This picks up the paths that are not tracked */
-		baselen = fill_directory(&dir, pathspec.raw);
+		baselen = fill_directory(&dir, &pathspec);
 		if (pathspec.nr)
 			seen = prune_directory(&dir, pathspec.raw, baselen);
 	}
diff --git a/builtin/clean.c b/builtin/clean.c
index fb0fe9a..1d8ff5f 100644
--- a/builtin/clean.c
+++ b/builtin/clean.c
@@ -102,7 +102,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
 
 	parse_pathspec(&pathspec, PATHSPEC_FROMTOP, 0, prefix, argv);
 
-	fill_directory(&dir, pathspec.raw);
+	fill_directory(&dir, &pathspec);
 
 	for (i = 0; i < dir.nr; i++) {
 		struct dir_entry *ent = dir.entries[i];
diff --git a/builtin/grep.c b/builtin/grep.c
index 705f9ff..f370bad 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -522,7 +522,7 @@ static int grep_directory(struct grep_opt *opt, const struct pathspec *pathspec,
 	if (exc_std)
 		setup_standard_excludes(&dir);
 
-	fill_directory(&dir, pathspec->raw);
+	fill_directory(&dir, pathspec);
 	for (i = 0; i < dir.nr; i++) {
 		const char *name = dir.entries[i]->name;
 		int namelen = strlen(name);
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index 4bf3238..9655cc5 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -216,7 +216,7 @@ static void show_files(struct dir_struct *dir)
 
 	/* For cached/deleted files we don't need to even do the readdir */
 	if (show_others || show_killed) {
-		fill_directory(dir, pathspec.raw);
+		fill_directory(dir, &pathspec);
 		if (show_others)
 			show_other_files(dir);
 		if (show_killed)
diff --git a/dir.c b/dir.c
index 37280c8..6657b02 100644
--- a/dir.c
+++ b/dir.c
@@ -98,7 +98,7 @@ char *common_prefix(const char **pathspec)
 	return len ? xmemdupz(*pathspec, len) : NULL;
 }
 
-int fill_directory(struct dir_struct *dir, const char **pathspec)
+int fill_directory(struct dir_struct *dir, const struct pathspec *pathspec)
 {
 	size_t len;
 
@@ -106,10 +106,10 @@ int fill_directory(struct dir_struct *dir, const char **pathspec)
 	 * Calculate common prefix for the pathspec, and
 	 * use that to optimize the directory walk
 	 */
-	len = common_prefix_len(pathspec);
+	len = common_prefix_len(pathspec->raw);
 
 	/* Read the directory and prune it */
-	read_directory(dir, pathspec ? *pathspec : "", len, pathspec);
+	read_directory(dir, pathspec->nr ? pathspec->raw[0] : "", len, pathspec);
 	return len;
 }
 
@@ -1323,14 +1323,20 @@ static int treat_leading_path(struct dir_struct *dir,
 	return rc;
 }
 
-int read_directory(struct dir_struct *dir, const char *path, int len, const char **pathspec)
+int read_directory(struct dir_struct *dir, const char *path, int len, const struct pathspec *pathspec)
 {
 	struct path_simplify *simplify;
 
+	/*
+	 * Check out create_simplify()
+	 */
+	if (pathspec)
+		GUARD_PATHSPEC(pathspec, PATHSPEC_FROMTOP);
+
 	if (has_symlink_leading_path(path, len))
 		return dir->nr;
 
-	simplify = create_simplify(pathspec);
+	simplify = create_simplify(pathspec ? pathspec->raw : NULL);
 	if (!len || treat_leading_path(dir, path, len, simplify))
 		read_directory_recursive(dir, path, len, 0, simplify);
 	free_simplify(simplify);
diff --git a/dir.h b/dir.h
index 0cf5ccf..36bb4dd 100644
--- a/dir.h
+++ b/dir.h
@@ -97,8 +97,8 @@ extern int match_pathspec_depth(const struct pathspec *pathspec,
 				int prefix, char *seen);
 extern int within_depth(const char *name, int namelen, int depth, int max_depth);
 
-extern int fill_directory(struct dir_struct *dir, const char **pathspec);
-extern int read_directory(struct dir_struct *, const char *path, int len, const char **pathspec);
+extern int fill_directory(struct dir_struct *dir, const struct pathspec *pathspec);
+extern int read_directory(struct dir_struct *, const char *path, int len, const struct pathspec *pathspec);
 
 extern int is_excluded_from_list(const char *pathname, int pathlen, const char *basename,
 				 int *dtype, struct exclude_list *el);
diff --git a/wt-status.c b/wt-status.c
index 76edadc..c5b979e 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -502,7 +502,7 @@ static void wt_status_collect_untracked(struct wt_status *s)
 			DIR_SHOW_OTHER_DIRECTORIES | DIR_HIDE_EMPTY_DIRECTORIES;
 	setup_standard_excludes(&dir);
 
-	fill_directory(&dir, s->pathspec.raw);
+	fill_directory(&dir, &s->pathspec);
 	for (i = 0; i < dir.nr; i++) {
 		struct dir_entry *ent = dir.entries[i];
 		if (cache_name_is_other(ent->name, ent->len) &&
@@ -514,7 +514,7 @@ static void wt_status_collect_untracked(struct wt_status *s)
 	if (s->show_ignored_files) {
 		dir.nr = 0;
 		dir.flags = DIR_SHOW_IGNORED | DIR_SHOW_OTHER_DIRECTORIES;
-		fill_directory(&dir, s->pathspec.raw);
+		fill_directory(&dir, &s->pathspec);
 		for (i = 0; i < dir.nr; i++) {
 			struct dir_entry *ent = dir.entries[i];
 			if (cache_name_is_other(ent->name, ent->len) &&
-- 
1.8.0.rc2.23.g1fb49df
Previous: Nguyễn Thái Ngọc DuyNext: Nguyễn Thái Ngọc Duy
Message 29 of 37 in “nd/parse-pathspec”
  1. 00/31 nd/parse-pathspecNguyễn Thái Ngọc Duy, Jan 13, 2013
  2. 01/31 clean: remove unused variable "seen"Nguyễn Thái Ngọc Duy, Jan 13, 2013
  3. 02/31 Add copy_pathspecNguyễn Thái Ngọc Duy, Jan 13, 2013
  4. 03/31 Add parse_pathspec() that converts cmdline args to struct pathspecNguyễn Thái Ngọc Duy, Jan 13, 2013
  5. Martin von ZweigbergkJan 14, 2013
  6. Duy NguyenJan 14, 2013
  7. 04/31 parse_pathspec: save original pathspec for reportingNguyễn Thái Ngọc Duy, Jan 13, 2013
  8. 05/31 Export parse_pathspec() and convert some get_pathspec() callsNguyễn Thái Ngọc Duy, Jan 13, 2013
  9. 06/31 Guard against new pathspec magic in pathspec matching codeNguyễn Thái Ngọc Duy, Jan 13, 2013
  10. 07/31 clean: convert to use parse_pathspecNguyễn Thái Ngọc Duy, Jan 13, 2013
  11. 08/31 parse_pathspec: add PATHSPEC_EMPTY_MATCH_ALLNguyễn Thái Ngọc Duy, Jan 13, 2013
  12. Martin von ZweigbergkJan 21, 2013
  13. Duy NguyenJan 22, 2013
  14. 09/31 commit: convert to use parse_pathspecNguyễn Thái Ngọc Duy, Jan 13, 2013
  15. 10/31 status: convert to use parse_pathspecNguyễn Thái Ngọc Duy, Jan 13, 2013
  16. 11/31 rerere: convert to use parse_pathspecNguyễn Thái Ngọc Duy, Jan 13, 2013
  17. 12/31 checkout: convert to use parse_pathspecNguyễn Thái Ngọc Duy, Jan 13, 2013
  18. 13/31 rm: convert to use parse_pathspecNguyễn Thái Ngọc Duy, Jan 13, 2013
  19. 14/31 parse_pathspec: support stripping submodule trailing slashesNguyễn Thái Ngọc Duy, Jan 13, 2013
  20. 15/31 ls-files: convert to use parse_pathspecNguyễn Thái Ngọc Duy, Jan 13, 2013
  21. 16/31 archive: convert to use parse_pathspecNguyễn Thái Ngọc Duy, Jan 13, 2013
  22. 17/31 parse_pathspec: support stripping/checking submodule pathsNguyễn Thái Ngọc Duy, Jan 13, 2013
  23. 18/31 add: convert to use parse_pathspecNguyễn Thái Ngọc Duy, Jan 13, 2013
  24. 19/31 Convert read_cache_preload() to take struct pathspecNguyễn Thái Ngọc Duy, Jan 13, 2013
  25. 20/31 Convert unmerge_cache to take struct pathspecNguyễn Thái Ngọc Duy, Jan 13, 2013
  26. 21/31 checkout: convert read_tree_some to take struct pathspecNguyễn Thái Ngọc Duy, Jan 13, 2013
  27. 22/31 Convert report_path_error to take struct pathspecNguyễn Thái Ngọc Duy, Jan 13, 2013
  28. 23/31 Convert refresh_index to take struct pathspecNguyễn Thái Ngọc Duy, Jan 13, 2013
  29. 24/31 Convert {read,fill}_directory to take struct pathspecNguyễn Thái Ngọc Duy, Jan 13, 2013
  30. 25/31 Convert add_files_to_cache to take struct pathspecNguyễn Thái Ngọc Duy, Jan 13, 2013
  31. 26/31 Convert common_prefix() to use struct pathspecNguyễn Thái Ngọc Duy, Jan 13, 2013
  32. 27/31 Remove diff_tree_{setup,release}_pathsNguyễn Thái Ngọc Duy, Jan 13, 2013
  33. 28/31 Remove init_pathspec() in favor of parse_pathspec()Nguyễn Thái Ngọc Duy, Jan 13, 2013
  34. 29/31 Remove match_pathspec() in favor of match_pathspec_depth()Nguyễn Thái Ngọc Duy, Jan 13, 2013
  35. 30/31 tree-diff: remove the use of pathspec's raw[] in follow-rename codepathNguyễn Thái Ngọc Duy, Jan 13, 2013
  36. 31/31 Rename field "raw" to "_raw" in struct pathspecNguyễn Thái Ngọc Duy, Jan 13, 2013
  37. Junio C HamanoJan 13, 2013

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.