@matheusbsbs / matheus-bagliano / commits / 16e2cfa909
Fork 0

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>

Junio C Hamano committed Jan 8, 2010 at 20:56 UTC 16e2cfa90993b23bda8ff1ffb958cac20e58b058
1 file changed +29 -21
dir.c
+29 -21
@@ -631,28 +631,12 @@ enum path_treatment {
631 path_recurse,
632 };
633
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)
638 {
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);
640 if (exclude && (dir->flags & DIR_COLLECT_IGNORED)
641 && in_pathspec(path, *len, simplify))
642 dir_add_ignored(dir, path, *len);
@@ -703,6 +687,30 @@ static enum path_treatment treat_path(struct dir_struct *dir,
687 return path_handled;
688 }
689
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 +
714 /*
715 * Read a directory tree. We currently ignore anything but
716 * directories, regular files and symlinks. That's because git