Skip to content

Commit 16e2cfa

Browse files
committed
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 <[email protected]>
1 parent 53cc535 commit 16e2cfa

File tree

1 file changed

+29
-21
lines changed

1 file changed

+29
-21
lines changed

dir.c

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -631,28 +631,12 @@ enum path_treatment {
631631
path_recurse,
632632
};
633633

634-
static enum path_treatment treat_path(struct dir_struct *dir,
635-
struct dirent *de,
636-
char *path, int path_max,
637-
int baselen,
638-
const struct path_simplify *simplify,
639-
int *len)
634+
static enum path_treatment treat_one_path(struct dir_struct *dir,
635+
char *path, int *len,
636+
const struct path_simplify *simplify,
637+
int dtype, struct dirent *de)
640638
{
641-
int dtype, exclude;
642-
643-
if (is_dot_or_dotdot(de->d_name) || !strcmp(de->d_name, ".git"))
644-
return path_ignored;
645-
*len = strlen(de->d_name);
646-
/* Ignore overly long pathnames! */
647-
if (*len + baselen + 8 > path_max)
648-
return path_ignored;
649-
memcpy(path + baselen, de->d_name, *len + 1);
650-
*len += baselen;
651-
if (simplify_away(path, *len, simplify))
652-
return path_ignored;
653-
654-
dtype = DTYPE(de);
655-
exclude = excluded(dir, path, &dtype);
639+
int exclude = excluded(dir, path, &dtype);
656640
if (exclude && (dir->flags & DIR_COLLECT_IGNORED)
657641
&& in_pathspec(path, *len, simplify))
658642
dir_add_ignored(dir, path, *len);
@@ -703,6 +687,30 @@ static enum path_treatment treat_path(struct dir_struct *dir,
703687
return path_handled;
704688
}
705689

690+
static enum path_treatment treat_path(struct dir_struct *dir,
691+
struct dirent *de,
692+
char *path, int path_max,
693+
int baselen,
694+
const struct path_simplify *simplify,
695+
int *len)
696+
{
697+
int dtype;
698+
699+
if (is_dot_or_dotdot(de->d_name) || !strcmp(de->d_name, ".git"))
700+
return path_ignored;
701+
*len = strlen(de->d_name);
702+
/* Ignore overly long pathnames! */
703+
if (*len + baselen + 8 > path_max)
704+
return path_ignored;
705+
memcpy(path + baselen, de->d_name, *len + 1);
706+
*len += baselen;
707+
if (simplify_away(path, *len, simplify))
708+
return path_ignored;
709+
710+
dtype = DTYPE(de);
711+
return treat_one_path(dir, path, len, simplify, dtype, de);
712+
}
713+
706714
/*
707715
* Read a directory tree. We currently ignore anything but
708716
* directories, regular files and symlinks. That's because git

0 commit comments

Comments
 (0)