dir: consolidate treat_path() and treat_one_path()
Commitmaint16e2cfa909
("read_directory(): further split treat_path()", 2010-01-08) split treat_one_path() out of treat_path(), because treat_leading_path() would not have access to a dirent but wanted to re-use as much of treat_path() as possible. Not re-using all of treat_path() caused other bugs, as noted in commitb9670c1f5e
("dir: fix checks on common prefix directory", 2019-12-19). Finally, in commitad6f2157f9
("dir: restructure in a way to avoid passing around a struct dirent", 2020-01-16), dirents were removed from treat_path() and other functions entirely. Since the only reason for splitting these functions was the lack of a dirent -- which no longer applies to either function -- and since the split caused problems in the past resulting in us not using treat_one_path() separately anymore, just undo the split. Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
parent
446f46d8c7
commit
cd129eed98
111
dir.c
111
dir.c
|
@ -1863,21 +1863,65 @@ static int resolve_dtype(int dtype, struct index_state *istate,
|
||||||
return dtype;
|
return dtype;
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum path_treatment treat_one_path(struct dir_struct *dir,
|
static enum path_treatment treat_path_fast(struct dir_struct *dir,
|
||||||
struct untracked_cache_dir *untracked,
|
struct untracked_cache_dir *untracked,
|
||||||
|
struct cached_dir *cdir,
|
||||||
struct index_state *istate,
|
struct index_state *istate,
|
||||||
struct strbuf *path,
|
struct strbuf *path,
|
||||||
int baselen,
|
int baselen,
|
||||||
const struct pathspec *pathspec,
|
const struct pathspec *pathspec)
|
||||||
int dtype)
|
|
||||||
{
|
{
|
||||||
int exclude;
|
strbuf_setlen(path, baselen);
|
||||||
int has_path_in_index = !!index_file_exists(istate, path->buf, path->len, ignore_case);
|
if (!cdir->ucd) {
|
||||||
|
strbuf_addstr(path, cdir->file);
|
||||||
|
return path_untracked;
|
||||||
|
}
|
||||||
|
strbuf_addstr(path, cdir->ucd->name);
|
||||||
|
/* treat_one_path() does this before it calls treat_directory() */
|
||||||
|
strbuf_complete(path, '/');
|
||||||
|
if (cdir->ucd->check_only)
|
||||||
|
/*
|
||||||
|
* check_only is set as a result of treat_directory() getting
|
||||||
|
* to its bottom. Verify again the same set of directories
|
||||||
|
* with check_only set.
|
||||||
|
*/
|
||||||
|
return read_directory_recursive(dir, istate, path->buf, path->len,
|
||||||
|
cdir->ucd, 1, 0, pathspec);
|
||||||
|
/*
|
||||||
|
* We get path_recurse in the first run when
|
||||||
|
* directory_exists_in_index() returns index_nonexistent. We
|
||||||
|
* are sure that new changes in the index does not impact the
|
||||||
|
* outcome. Return now.
|
||||||
|
*/
|
||||||
|
return path_recurse;
|
||||||
|
}
|
||||||
|
|
||||||
|
static enum path_treatment treat_path(struct dir_struct *dir,
|
||||||
|
struct untracked_cache_dir *untracked,
|
||||||
|
struct cached_dir *cdir,
|
||||||
|
struct index_state *istate,
|
||||||
|
struct strbuf *path,
|
||||||
|
int baselen,
|
||||||
|
const struct pathspec *pathspec)
|
||||||
|
{
|
||||||
|
int has_path_in_index, dtype, exclude;
|
||||||
enum path_treatment path_treatment;
|
enum path_treatment path_treatment;
|
||||||
|
|
||||||
dtype = resolve_dtype(dtype, istate, path->buf, path->len);
|
if (!cdir->d_name)
|
||||||
|
return treat_path_fast(dir, untracked, cdir, istate, path,
|
||||||
|
baselen, pathspec);
|
||||||
|
if (is_dot_or_dotdot(cdir->d_name) || !fspathcmp(cdir->d_name, ".git"))
|
||||||
|
return path_none;
|
||||||
|
strbuf_setlen(path, baselen);
|
||||||
|
strbuf_addstr(path, cdir->d_name);
|
||||||
|
if (simplify_away(path->buf, path->len, pathspec))
|
||||||
|
return path_none;
|
||||||
|
|
||||||
|
dtype = resolve_dtype(cdir->d_type, istate, path->buf, path->len);
|
||||||
|
|
||||||
/* Always exclude indexed files */
|
/* Always exclude indexed files */
|
||||||
|
has_path_in_index = !!index_file_exists(istate, path->buf, path->len,
|
||||||
|
ignore_case);
|
||||||
if (dtype != DT_DIR && has_path_in_index)
|
if (dtype != DT_DIR && has_path_in_index)
|
||||||
return path_none;
|
return path_none;
|
||||||
|
|
||||||
|
@ -1942,61 +1986,6 @@ static enum path_treatment treat_one_path(struct dir_struct *dir,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum path_treatment treat_path_fast(struct dir_struct *dir,
|
|
||||||
struct untracked_cache_dir *untracked,
|
|
||||||
struct cached_dir *cdir,
|
|
||||||
struct index_state *istate,
|
|
||||||
struct strbuf *path,
|
|
||||||
int baselen,
|
|
||||||
const struct pathspec *pathspec)
|
|
||||||
{
|
|
||||||
strbuf_setlen(path, baselen);
|
|
||||||
if (!cdir->ucd) {
|
|
||||||
strbuf_addstr(path, cdir->file);
|
|
||||||
return path_untracked;
|
|
||||||
}
|
|
||||||
strbuf_addstr(path, cdir->ucd->name);
|
|
||||||
/* treat_one_path() does this before it calls treat_directory() */
|
|
||||||
strbuf_complete(path, '/');
|
|
||||||
if (cdir->ucd->check_only)
|
|
||||||
/*
|
|
||||||
* check_only is set as a result of treat_directory() getting
|
|
||||||
* to its bottom. Verify again the same set of directories
|
|
||||||
* with check_only set.
|
|
||||||
*/
|
|
||||||
return read_directory_recursive(dir, istate, path->buf, path->len,
|
|
||||||
cdir->ucd, 1, 0, pathspec);
|
|
||||||
/*
|
|
||||||
* We get path_recurse in the first run when
|
|
||||||
* directory_exists_in_index() returns index_nonexistent. We
|
|
||||||
* are sure that new changes in the index does not impact the
|
|
||||||
* outcome. Return now.
|
|
||||||
*/
|
|
||||||
return path_recurse;
|
|
||||||
}
|
|
||||||
|
|
||||||
static enum path_treatment treat_path(struct dir_struct *dir,
|
|
||||||
struct untracked_cache_dir *untracked,
|
|
||||||
struct cached_dir *cdir,
|
|
||||||
struct index_state *istate,
|
|
||||||
struct strbuf *path,
|
|
||||||
int baselen,
|
|
||||||
const struct pathspec *pathspec)
|
|
||||||
{
|
|
||||||
if (!cdir->d_name)
|
|
||||||
return treat_path_fast(dir, untracked, cdir, istate, path,
|
|
||||||
baselen, pathspec);
|
|
||||||
if (is_dot_or_dotdot(cdir->d_name) || !fspathcmp(cdir->d_name, ".git"))
|
|
||||||
return path_none;
|
|
||||||
strbuf_setlen(path, baselen);
|
|
||||||
strbuf_addstr(path, cdir->d_name);
|
|
||||||
if (simplify_away(path->buf, path->len, pathspec))
|
|
||||||
return path_none;
|
|
||||||
|
|
||||||
return treat_one_path(dir, untracked, istate, path, baselen, pathspec,
|
|
||||||
cdir->d_type);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void add_untracked(struct untracked_cache_dir *dir, const char *name)
|
static void add_untracked(struct untracked_cache_dir *dir, const char *name)
|
||||||
{
|
{
|
||||||
if (!dir)
|
if (!dir)
|
||||||
|
|
Loading…
Reference in New Issue