read_directory(): further split treat_path()
The next caller I'll be adding won't have an access to struct dirent because it won't be reading from a directory stream. Split the main part of the function further into a separate function to make it usable by a caller without passing a dirent as long as it knows what type is feeding the function. Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
53cc5356fb
commit
16e2cfa909
50
dir.c
50
dir.c
@ -631,28 +631,12 @@ enum path_treatment {
|
|||||||
path_recurse,
|
path_recurse,
|
||||||
};
|
};
|
||||||
|
|
||||||
static enum path_treatment treat_path(struct dir_struct *dir,
|
static enum path_treatment treat_one_path(struct dir_struct *dir,
|
||||||
struct dirent *de,
|
char *path, int *len,
|
||||||
char *path, int path_max,
|
const struct path_simplify *simplify,
|
||||||
int baselen,
|
int dtype, struct dirent *de)
|
||||||
const struct path_simplify *simplify,
|
|
||||||
int *len)
|
|
||||||
{
|
{
|
||||||
int dtype, exclude;
|
int exclude = excluded(dir, path, &dtype);
|
||||||
|
|
||||||
if (is_dot_or_dotdot(de->d_name) || !strcmp(de->d_name, ".git"))
|
|
||||||
return path_ignored;
|
|
||||||
*len = strlen(de->d_name);
|
|
||||||
/* Ignore overly long pathnames! */
|
|
||||||
if (*len + baselen + 8 > path_max)
|
|
||||||
return path_ignored;
|
|
||||||
memcpy(path + baselen, de->d_name, *len + 1);
|
|
||||||
*len += baselen;
|
|
||||||
if (simplify_away(path, *len, simplify))
|
|
||||||
return path_ignored;
|
|
||||||
|
|
||||||
dtype = DTYPE(de);
|
|
||||||
exclude = excluded(dir, path, &dtype);
|
|
||||||
if (exclude && (dir->flags & DIR_COLLECT_IGNORED)
|
if (exclude && (dir->flags & DIR_COLLECT_IGNORED)
|
||||||
&& in_pathspec(path, *len, simplify))
|
&& in_pathspec(path, *len, simplify))
|
||||||
dir_add_ignored(dir, path, *len);
|
dir_add_ignored(dir, path, *len);
|
||||||
@ -703,6 +687,30 @@ static enum path_treatment treat_path(struct dir_struct *dir,
|
|||||||
return path_handled;
|
return path_handled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static enum path_treatment treat_path(struct dir_struct *dir,
|
||||||
|
struct dirent *de,
|
||||||
|
char *path, int path_max,
|
||||||
|
int baselen,
|
||||||
|
const struct path_simplify *simplify,
|
||||||
|
int *len)
|
||||||
|
{
|
||||||
|
int dtype;
|
||||||
|
|
||||||
|
if (is_dot_or_dotdot(de->d_name) || !strcmp(de->d_name, ".git"))
|
||||||
|
return path_ignored;
|
||||||
|
*len = strlen(de->d_name);
|
||||||
|
/* Ignore overly long pathnames! */
|
||||||
|
if (*len + baselen + 8 > path_max)
|
||||||
|
return path_ignored;
|
||||||
|
memcpy(path + baselen, de->d_name, *len + 1);
|
||||||
|
*len += baselen;
|
||||||
|
if (simplify_away(path, *len, simplify))
|
||||||
|
return path_ignored;
|
||||||
|
|
||||||
|
dtype = DTYPE(de);
|
||||||
|
return treat_one_path(dir, path, len, simplify, dtype, de);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Read a directory tree. We currently ignore anything but
|
* Read a directory tree. We currently ignore anything but
|
||||||
* directories, regular files and symlinks. That's because git
|
* directories, regular files and symlinks. That's because git
|
||||||
|
Loading…
Reference in New Issue
Block a user