Skip to content

Commit cd129ee

Browse files
newrengitster
authored andcommitted
dir: consolidate treat_path() and treat_one_path()
Commit 16e2cfa ("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 commit b9670c1 ("dir: fix checks on common prefix directory", 2019-12-19). Finally, in commit ad6f215 ("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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 446f46d commit cd129ee

File tree

1 file changed

+55
-66
lines changed

1 file changed

+55
-66
lines changed

dir.c

Lines changed: 55 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1863,21 +1863,65 @@ static int resolve_dtype(int dtype, struct index_state *istate,
18631863
return dtype;
18641864
}
18651865

1866-
static enum path_treatment treat_one_path(struct dir_struct *dir,
1867-
struct untracked_cache_dir *untracked,
1868-
struct index_state *istate,
1869-
struct strbuf *path,
1870-
int baselen,
1871-
const struct pathspec *pathspec,
1872-
int dtype)
1873-
{
1874-
int exclude;
1875-
int has_path_in_index = !!index_file_exists(istate, path->buf, path->len, ignore_case);
1866+
static enum path_treatment treat_path_fast(struct dir_struct *dir,
1867+
struct untracked_cache_dir *untracked,
1868+
struct cached_dir *cdir,
1869+
struct index_state *istate,
1870+
struct strbuf *path,
1871+
int baselen,
1872+
const struct pathspec *pathspec)
1873+
{
1874+
strbuf_setlen(path, baselen);
1875+
if (!cdir->ucd) {
1876+
strbuf_addstr(path, cdir->file);
1877+
return path_untracked;
1878+
}
1879+
strbuf_addstr(path, cdir->ucd->name);
1880+
/* treat_one_path() does this before it calls treat_directory() */
1881+
strbuf_complete(path, '/');
1882+
if (cdir->ucd->check_only)
1883+
/*
1884+
* check_only is set as a result of treat_directory() getting
1885+
* to its bottom. Verify again the same set of directories
1886+
* with check_only set.
1887+
*/
1888+
return read_directory_recursive(dir, istate, path->buf, path->len,
1889+
cdir->ucd, 1, 0, pathspec);
1890+
/*
1891+
* We get path_recurse in the first run when
1892+
* directory_exists_in_index() returns index_nonexistent. We
1893+
* are sure that new changes in the index does not impact the
1894+
* outcome. Return now.
1895+
*/
1896+
return path_recurse;
1897+
}
1898+
1899+
static enum path_treatment treat_path(struct dir_struct *dir,
1900+
struct untracked_cache_dir *untracked,
1901+
struct cached_dir *cdir,
1902+
struct index_state *istate,
1903+
struct strbuf *path,
1904+
int baselen,
1905+
const struct pathspec *pathspec)
1906+
{
1907+
int has_path_in_index, dtype, exclude;
18761908
enum path_treatment path_treatment;
18771909

1878-
dtype = resolve_dtype(dtype, istate, path->buf, path->len);
1910+
if (!cdir->d_name)
1911+
return treat_path_fast(dir, untracked, cdir, istate, path,
1912+
baselen, pathspec);
1913+
if (is_dot_or_dotdot(cdir->d_name) || !fspathcmp(cdir->d_name, ".git"))
1914+
return path_none;
1915+
strbuf_setlen(path, baselen);
1916+
strbuf_addstr(path, cdir->d_name);
1917+
if (simplify_away(path->buf, path->len, pathspec))
1918+
return path_none;
1919+
1920+
dtype = resolve_dtype(cdir->d_type, istate, path->buf, path->len);
18791921

18801922
/* Always exclude indexed files */
1923+
has_path_in_index = !!index_file_exists(istate, path->buf, path->len,
1924+
ignore_case);
18811925
if (dtype != DT_DIR && has_path_in_index)
18821926
return path_none;
18831927

@@ -1942,61 +1986,6 @@ static enum path_treatment treat_one_path(struct dir_struct *dir,
19421986
}
19431987
}
19441988

1945-
static enum path_treatment treat_path_fast(struct dir_struct *dir,
1946-
struct untracked_cache_dir *untracked,
1947-
struct cached_dir *cdir,
1948-
struct index_state *istate,
1949-
struct strbuf *path,
1950-
int baselen,
1951-
const struct pathspec *pathspec)
1952-
{
1953-
strbuf_setlen(path, baselen);
1954-
if (!cdir->ucd) {
1955-
strbuf_addstr(path, cdir->file);
1956-
return path_untracked;
1957-
}
1958-
strbuf_addstr(path, cdir->ucd->name);
1959-
/* treat_one_path() does this before it calls treat_directory() */
1960-
strbuf_complete(path, '/');
1961-
if (cdir->ucd->check_only)
1962-
/*
1963-
* check_only is set as a result of treat_directory() getting
1964-
* to its bottom. Verify again the same set of directories
1965-
* with check_only set.
1966-
*/
1967-
return read_directory_recursive(dir, istate, path->buf, path->len,
1968-
cdir->ucd, 1, 0, pathspec);
1969-
/*
1970-
* We get path_recurse in the first run when
1971-
* directory_exists_in_index() returns index_nonexistent. We
1972-
* are sure that new changes in the index does not impact the
1973-
* outcome. Return now.
1974-
*/
1975-
return path_recurse;
1976-
}
1977-
1978-
static enum path_treatment treat_path(struct dir_struct *dir,
1979-
struct untracked_cache_dir *untracked,
1980-
struct cached_dir *cdir,
1981-
struct index_state *istate,
1982-
struct strbuf *path,
1983-
int baselen,
1984-
const struct pathspec *pathspec)
1985-
{
1986-
if (!cdir->d_name)
1987-
return treat_path_fast(dir, untracked, cdir, istate, path,
1988-
baselen, pathspec);
1989-
if (is_dot_or_dotdot(cdir->d_name) || !fspathcmp(cdir->d_name, ".git"))
1990-
return path_none;
1991-
strbuf_setlen(path, baselen);
1992-
strbuf_addstr(path, cdir->d_name);
1993-
if (simplify_away(path->buf, path->len, pathspec))
1994-
return path_none;
1995-
1996-
return treat_one_path(dir, untracked, istate, path, baselen, pathspec,
1997-
cdir->d_type);
1998-
}
1999-
20001989
static void add_untracked(struct untracked_cache_dir *dir, const char *name)
20011990
{
20021991
if (!dir)

0 commit comments

Comments
 (0)