Skip to content

Commit c5c4edd

Browse files
newrengitster
authored andcommitted
dir: break part of read_directory_recursive() out for reuse
Create an add_path_to_appropriate_result_list() function from the code at the end of read_directory_recursive() so we can use it elsewhere. Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 072a231 commit c5c4edd

File tree

1 file changed

+37
-23
lines changed

1 file changed

+37
-23
lines changed

dir.c

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1932,6 +1932,40 @@ static void close_cached_dir(struct cached_dir *cdir)
19321932
}
19331933
}
19341934

1935+
static void add_path_to_appropriate_result_list(struct dir_struct *dir,
1936+
struct untracked_cache_dir *untracked,
1937+
struct cached_dir *cdir,
1938+
struct index_state *istate,
1939+
struct strbuf *path,
1940+
int baselen,
1941+
const struct pathspec *pathspec,
1942+
enum path_treatment state)
1943+
{
1944+
/* add the path to the appropriate result list */
1945+
switch (state) {
1946+
case path_excluded:
1947+
if (dir->flags & DIR_SHOW_IGNORED)
1948+
dir_add_name(dir, istate, path->buf, path->len);
1949+
else if ((dir->flags & DIR_SHOW_IGNORED_TOO) ||
1950+
((dir->flags & DIR_COLLECT_IGNORED) &&
1951+
exclude_matches_pathspec(path->buf, path->len,
1952+
pathspec)))
1953+
dir_add_ignored(dir, istate, path->buf, path->len);
1954+
break;
1955+
1956+
case path_untracked:
1957+
if (dir->flags & DIR_SHOW_IGNORED)
1958+
break;
1959+
dir_add_name(dir, istate, path->buf, path->len);
1960+
if (cdir->fdir)
1961+
add_untracked(untracked, path->buf + baselen);
1962+
break;
1963+
1964+
default:
1965+
break;
1966+
}
1967+
}
1968+
19351969
/*
19361970
* Read a directory tree. We currently ignore anything but
19371971
* directories, regular files and symlinks. That's because git
@@ -2035,29 +2069,9 @@ static enum path_treatment read_directory_recursive(struct dir_struct *dir,
20352069
continue;
20362070
}
20372071

2038-
/* add the path to the appropriate result list */
2039-
switch (state) {
2040-
case path_excluded:
2041-
if (dir->flags & DIR_SHOW_IGNORED)
2042-
dir_add_name(dir, istate, path.buf, path.len);
2043-
else if ((dir->flags & DIR_SHOW_IGNORED_TOO) ||
2044-
((dir->flags & DIR_COLLECT_IGNORED) &&
2045-
exclude_matches_pathspec(path.buf, path.len,
2046-
pathspec)))
2047-
dir_add_ignored(dir, istate, path.buf, path.len);
2048-
break;
2049-
2050-
case path_untracked:
2051-
if (dir->flags & DIR_SHOW_IGNORED)
2052-
break;
2053-
dir_add_name(dir, istate, path.buf, path.len);
2054-
if (cdir.fdir)
2055-
add_untracked(untracked, path.buf + baselen);
2056-
break;
2057-
2058-
default:
2059-
break;
2060-
}
2072+
add_path_to_appropriate_result_list(dir, untracked, &cdir,
2073+
istate, &path, baselen,
2074+
pathspec, state);
20612075
}
20622076
close_cached_dir(&cdir);
20632077
out:

0 commit comments

Comments
 (0)