Skip to content

Commit 7327d3d

Browse files
pcloudsgitster
authored andcommitted
convert {read,fill}_directory to take struct pathspec
Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9b2d614 commit 7327d3d

File tree

7 files changed

+20
-12
lines changed

7 files changed

+20
-12
lines changed

builtin/add.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
507507

508508
if (add_new_files) {
509509
int baselen;
510+
struct pathspec empty_pathspec;
510511

511512
/* Set up the default git porcelain excludes */
512513
memset(&dir, 0, sizeof(dir));
@@ -515,8 +516,9 @@ int cmd_add(int argc, const char **argv, const char *prefix)
515516
setup_standard_excludes(&dir);
516517
}
517518

519+
memset(&empty_pathspec, 0, sizeof(empty_pathspec));
518520
/* This picks up the paths that are not tracked */
519-
baselen = fill_directory(&dir, implicit_dot ? NULL : pathspec.raw);
521+
baselen = fill_directory(&dir, implicit_dot ? &empty_pathspec : &pathspec);
520522
if (pathspec.nr)
521523
seen = prune_directory(&dir, pathspec.raw, baselen,
522524
implicit_dot ? WARN_IMPLICIT_DOT : 0);

builtin/clean.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
214214
PATHSPEC_PREFER_CWD,
215215
prefix, argv);
216216

217-
fill_directory(&dir, pathspec.raw);
217+
fill_directory(&dir, &pathspec);
218218

219219
for (i = 0; i < dir.nr; i++) {
220220
struct dir_entry *ent = dir.entries[i];

builtin/grep.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ static int grep_directory(struct grep_opt *opt, const struct pathspec *pathspec,
523523
if (exc_std)
524524
setup_standard_excludes(&dir);
525525

526-
fill_directory(&dir, pathspec->raw);
526+
fill_directory(&dir, pathspec);
527527
for (i = 0; i < dir.nr; i++) {
528528
const char *name = dir.entries[i]->name;
529529
int namelen = strlen(name);

builtin/ls-files.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ static void show_files(struct dir_struct *dir)
216216

217217
/* For cached/deleted files we don't need to even do the readdir */
218218
if (show_others || show_killed) {
219-
fill_directory(dir, pathspec.raw);
219+
fill_directory(dir, &pathspec);
220220
if (show_others)
221221
show_other_files(dir);
222222
if (show_killed)

dir.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,18 +142,18 @@ char *common_prefix(const char **pathspec)
142142
return len ? xmemdupz(*pathspec, len) : NULL;
143143
}
144144

145-
int fill_directory(struct dir_struct *dir, const char **pathspec)
145+
int fill_directory(struct dir_struct *dir, const struct pathspec *pathspec)
146146
{
147147
size_t len;
148148

149149
/*
150150
* Calculate common prefix for the pathspec, and
151151
* use that to optimize the directory walk
152152
*/
153-
len = common_prefix_len(pathspec);
153+
len = common_prefix_len(pathspec->raw);
154154

155155
/* Read the directory and prune it */
156-
read_directory(dir, pathspec ? *pathspec : "", len, pathspec);
156+
read_directory(dir, pathspec->nr ? pathspec->raw[0] : "", len, pathspec);
157157
return len;
158158
}
159159

@@ -1388,14 +1388,20 @@ static int treat_leading_path(struct dir_struct *dir,
13881388
return rc;
13891389
}
13901390

1391-
int read_directory(struct dir_struct *dir, const char *path, int len, const char **pathspec)
1391+
int read_directory(struct dir_struct *dir, const char *path, int len, const struct pathspec *pathspec)
13921392
{
13931393
struct path_simplify *simplify;
13941394

1395+
/*
1396+
* Check out create_simplify()
1397+
*/
1398+
if (pathspec)
1399+
GUARD_PATHSPEC(pathspec, PATHSPEC_FROMTOP | PATHSPEC_MAXDEPTH);
1400+
13951401
if (has_symlink_leading_path(path, len))
13961402
return dir->nr;
13971403

1398-
simplify = create_simplify(pathspec);
1404+
simplify = create_simplify(pathspec ? pathspec->raw : NULL);
13991405
if (!len || treat_leading_path(dir, path, len, simplify))
14001406
read_directory_recursive(dir, path, len, 0, simplify);
14011407
free_simplify(simplify);

dir.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ extern int match_pathspec_depth(const struct pathspec *pathspec,
137137
int prefix, char *seen);
138138
extern int within_depth(const char *name, int namelen, int depth, int max_depth);
139139

140-
extern int fill_directory(struct dir_struct *dir, const char **pathspec);
141-
extern int read_directory(struct dir_struct *, const char *path, int len, const char **pathspec);
140+
extern int fill_directory(struct dir_struct *dir, const struct pathspec *pathspec);
141+
extern int read_directory(struct dir_struct *, const char *path, int len, const struct pathspec *pathspec);
142142

143143
extern int is_excluded_from_list(const char *pathname, int pathlen, const char *basename,
144144
int *dtype, struct exclude_list *el);

wt-status.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ static void wt_status_collect_untracked(struct wt_status *s)
514514
dir.flags |= DIR_SHOW_IGNORED_TOO;
515515
setup_standard_excludes(&dir);
516516

517-
fill_directory(&dir, s->pathspec.raw);
517+
fill_directory(&dir, &s->pathspec);
518518

519519
for (i = 0; i < dir.nr; i++) {
520520
struct dir_entry *ent = dir.entries[i];

0 commit comments

Comments
 (0)