static enum path_treatment treat_one_path(struct dir_struct *dir, struct strbuf *path, const struct path_simplify *simplify, int dtype, struct dirent *de) { int exclude; int has_path_in_index = !!cache_file_exists(path->buf, path->len, ignore_case); if (dtype == DT_UNKNOWN) dtype = get_dtype(de, path->buf, path->len); /* Always exclude indexed files */ if (dtype != DT_DIR && has_path_in_index) return path_none; /* * When we are looking at a directory P in the working tree, * there are three cases: * * (1) P exists in the index. Everything inside the directory P in * the working tree needs to go when P is checked out from the * index. * * (2) P does not exist in the index, but there is P/Q in the index. * We know P will stay a directory when we check out the contents * of the index, but we do not know yet if there is a directory * P/Q in the working tree to be killed, so we need to recurse. * * (3) P does not exist in the index, and there is no P/Q in the index * to require P to be a directory, either. Only in this case, we * know that everything inside P will not be killed without * recursing. */ if ((dir->flags & DIR_COLLECT_KILLED_ONLY) && (dtype == DT_DIR) && !has_path_in_index && (directory_exists_in_index(path->buf, path->len) == index_nonexistent)) return path_none; exclude = is_excluded(dir, path->buf, &dtype); /* * Excluded? If we don't explicitly want to show * ignored files, ignore it */ if (exclude && !(dir->flags & (DIR_SHOW_IGNORED|DIR_SHOW_IGNORED_TOO))) return path_excluded; switch (dtype) { default: return path_none; case DT_DIR: strbuf_addch(path, '/'); return treat_directory(dir, path->buf, path->len, exclude, simplify); case DT_REG: case DT_LNK: return exclude ? path_excluded : path_untracked; } }
static enum path_treatment treat_one_path(struct dir_struct *dir, struct strbuf *path, const struct path_simplify *simplify, int dtype, struct dirent *de) { int exclude; if (dtype == DT_UNKNOWN) dtype = get_dtype(de, path->buf, path->len); /* Always exclude indexed files */ if (dtype != DT_DIR && cache_name_exists(path->buf, path->len, ignore_case)) return path_none; exclude = is_excluded(dir, path->buf, &dtype); /* * Excluded? If we don't explicitly want to show * ignored files, ignore it */ if (exclude && !(dir->flags & (DIR_SHOW_IGNORED|DIR_SHOW_IGNORED_TOO))) return path_excluded; switch (dtype) { default: return path_none; case DT_DIR: strbuf_addch(path, '/'); return treat_directory(dir, path->buf, path->len, exclude, simplify); case DT_REG: case DT_LNK: return exclude ? path_excluded : path_untracked; } }
static enum path_treatment treat_one_path(struct dir_struct *dir, char *path, int *len, const struct path_simplify *simplify, int dtype, struct dirent *de) { int exclude = excluded(dir, path, &dtype); if (exclude && (dir->flags & DIR_COLLECT_IGNORED) && exclude_matches_pathspec(path, *len, simplify)) dir_add_ignored(dir, path, *len); /* * Excluded? If we don't explicitly want to show * ignored files, ignore it */ if (exclude && !(dir->flags & DIR_SHOW_IGNORED)) return path_ignored; if (dtype == DT_UNKNOWN) dtype = get_dtype(de, path, *len); /* * Do we want to see just the ignored files? * We still need to recurse into directories, * even if we don't ignore them, since the * directory may contain files that we do.. */ if (!exclude && (dir->flags & DIR_SHOW_IGNORED)) { if (dtype != DT_DIR) return path_ignored; } switch (dtype) { default: return path_ignored; case DT_DIR: memcpy(path + *len, "/", 2); (*len)++; switch (treat_directory(dir, path, *len, simplify)) { case show_directory: if (exclude != !!(dir->flags & DIR_SHOW_IGNORED)) return path_ignored; break; case recurse_into_directory: return path_recurse; case ignore_directory: return path_ignored; } break; case DT_REG: case DT_LNK: break; } return path_handled; }
/* * Read a directory tree. We currently ignore anything but * directories, regular files and symlinks. That's because git * doesn't handle them at all yet. Maybe that will change some * day. * * Also, we ignore the name ".git" (even if it is not a directory). * That likely will not change. */ static int read_directory_recursive(struct dir_struct *dir, const char *path, const char *base, int baselen, int check_only, const struct path_simplify *simplify) { DIR *fdir = opendir(path); int contents = 0; if (fdir) { struct dirent *de; char fullname[PATH_MAX + 1]; memcpy(fullname, base, baselen); while ((de = readdir(fdir)) != NULL) { int len, dtype; int exclude; if (is_dot_or_dotdot(de->d_name) || !strcmp(de->d_name, ".git")) continue; len = strlen(de->d_name); /* Ignore overly long pathnames! */ if (len + baselen + 8 > sizeof(fullname)) continue; memcpy(fullname + baselen, de->d_name, len+1); if (simplify_away(fullname, baselen + len, simplify)) continue; dtype = DTYPE(de); exclude = excluded(dir, fullname, &dtype); if (exclude && (dir->flags & DIR_COLLECT_IGNORED) && in_pathspec(fullname, baselen + len, simplify)) dir_add_ignored(dir, fullname, baselen + len); /* * Excluded? If we don't explicitly want to show * ignored files, ignore it */ if (exclude && !(dir->flags & DIR_SHOW_IGNORED)) continue; if (dtype == DT_UNKNOWN) dtype = get_dtype(de, fullname); /* * Do we want to see just the ignored files? * We still need to recurse into directories, * even if we don't ignore them, since the * directory may contain files that we do.. */ if (!exclude && (dir->flags & DIR_SHOW_IGNORED)) { if (dtype != DT_DIR) continue; } switch (dtype) { default: continue; case DT_DIR: memcpy(fullname + baselen + len, "/", 2); len++; switch (treat_directory(dir, fullname, baselen + len, simplify)) { case show_directory: if (exclude != !!(dir->flags & DIR_SHOW_IGNORED)) continue; break; case recurse_into_directory: contents += read_directory_recursive(dir, fullname, fullname, baselen + len, 0, simplify); continue; case ignore_directory: continue; } break; case DT_REG: case DT_LNK: break; } contents++; if (check_only) goto exit_early; else dir_add_name(dir, fullname, baselen + len); } exit_early: closedir(fdir); } return contents; }