Skip to content

Commit

Permalink
convert {read,fill}_directory to take struct pathspec
Browse files Browse the repository at this point in the history
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Nguyễn Thái Ngọc Duy authored and Junio C Hamano committed Jul 15, 2013
1 parent 9b2d614 commit 7327d3d
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 12 deletions.
4 changes: 3 additions & 1 deletion builtin/add.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion builtin/clean.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
2 changes: 1 addition & 1 deletion builtin/grep.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion builtin/ls-files.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 11 additions & 5 deletions dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,18 +142,18 @@ 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;

/*
* 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;
}

Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions dir.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion wt-status.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down

0 comments on commit 7327d3d

Please sign in to comment.