diff --git a/builtin/add.c b/builtin/add.c index f5d6a33a6a4a9b0c8459bcfeafd8bf17d469db7e..34c935826011ba5a02d66421d034e9f93a6e27f2 100644 --- a/builtin/add.c +++ b/builtin/add.c @@ -507,6 +507,7 @@ int cmd_add(int argc, const char **argv, const char *prefix) if (add_new_files) { int baselen; + struct pathspec empty_pathspec; /* Set up the default git porcelain excludes */ memset(&dir, 0, sizeof(dir)); @@ -515,8 +516,9 @@ int cmd_add(int argc, const char **argv, const char *prefix) setup_standard_excludes(&dir); } + memset(&empty_pathspec, 0, sizeof(empty_pathspec)); /* This picks up the paths that are not tracked */ - baselen = fill_directory(&dir, implicit_dot ? NULL : pathspec.raw); + baselen = fill_directory(&dir, implicit_dot ? &empty_pathspec : &pathspec); if (pathspec.nr) seen = prune_directory(&dir, pathspec.raw, baselen, implicit_dot ? WARN_IMPLICIT_DOT : 0); diff --git a/builtin/clean.c b/builtin/clean.c index fdd4980b12e94c6c3b9bb76df874b7f52df3ecdd..d540ca4a0a862ae33222df34bad63d799941774e 100644 --- a/builtin/clean.c +++ b/builtin/clean.c @@ -214,7 +214,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix) PATHSPEC_PREFER_CWD, 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 4bc075422e3c17e7666ed90e4a35be020586be49..76a6a60906e4c26508a63950dc72b4250155e271 100644 --- a/builtin/grep.c +++ b/builtin/grep.c @@ -523,7 +523,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 50e6edf07e9d706ed5208ced7d0740ab2310b84e..fa1a6bec01fd65ca70f4c9a53d4f835537272361 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 19978d3d59753a810503cf6dbac9eacb0f16c474..290c7a33cbd38aaccd5510a3b2cf50b90da89dff 100644 --- a/dir.c +++ b/dir.c @@ -142,7 +142,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; @@ -150,10 +150,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; } @@ -1388,14 +1388,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 | PATHSPEC_MAXDEPTH); + 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 229ccc8d7947394ad67036d154dd5cee8d90e6bd..076dd962efd60ba450979fee0d5d3d923e3f24d8 100644 --- a/dir.h +++ b/dir.h @@ -137,8 +137,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 fae0c276222937e7a5ad5a01a13d60bbe108637f..33baf0a698176c7df93e14046b388b0750fcaee4 100644 --- a/wt-status.c +++ b/wt-status.c @@ -514,7 +514,7 @@ static void wt_status_collect_untracked(struct wt_status *s) dir.flags |= DIR_SHOW_IGNORED_TOO; 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];