MCPcopy Create free account
hub / github.com/git/git / treat_directory

Function treat_directory

dir.c:1966–2216  ·  view source on GitHub ↗

* When we find a directory when traversing the filesystem, we * have three distinct cases: * * - ignore it * - see it as a directory * - recurse into it * * and which one we choose depends on a combination of existing * git index contents and the flags passed into the directory * traversal routine. * * Case 1: If we *already* have entries in the index under that * directory name, we

Source from the content-addressed store, hash-verified

1964 * (c) otherwise, we recurse into it.
1965 */
1966static enum path_treatment treat_directory(struct dir_struct *dir,
1967 struct index_state *istate,
1968 struct untracked_cache_dir *untracked,
1969 const char *dirname, int len, int baselen, int excluded,
1970 const struct pathspec *pathspec)
1971{
1972 /*
1973 * WARNING: From this function, you can return path_recurse or you
1974 * can call read_directory_recursive() (or neither), but
1975 * you CAN'T DO BOTH.
1976 */
1977 enum path_treatment state;
1978 int matches_how = 0;
1979 int check_only, stop_early;
1980 int old_ignored_nr, old_untracked_nr;
1981 /* The "len-1" is to strip the final '/' */
1982 enum exist_status status = directory_exists_in_index(istate, dirname, len-1);
1983
1984 if (status == index_directory)
1985 return path_recurse;
1986 if (status == index_gitdir)
1987 return path_none;
1988 if (status != index_nonexistent)
1989 BUG("Unhandled value for directory_exists_in_index: %d\n", status);
1990
1991 /*
1992 * We don't want to descend into paths that don't match the necessary
1993 * patterns. Clearly, if we don't have a pathspec, then we can't check
1994 * for matching patterns. Also, if (excluded) then we know we matched
1995 * the exclusion patterns so as an optimization we can skip checking
1996 * for matching patterns.
1997 */
1998 if (pathspec && !excluded) {
1999 matches_how = match_pathspec_with_flags(istate, pathspec,
2000 dirname, len,
2001 0 /* prefix */,
2002 NULL /* seen */,
2003 DO_MATCH_LEADING_PATHSPEC);
2004 if (!matches_how)
2005 return path_none;
2006 }
2007
2008
2009 if ((dir->flags & DIR_SKIP_NESTED_GIT) ||
2010 !(dir->flags & DIR_NO_GITLINKS)) {
2011 /*
2012 * Determine if `dirname` is a nested repo by confirming that:
2013 * 1) we are in a nonbare repository, and
2014 * 2) `dirname` is not an immediate parent of `the_repository->gitdir`,
2015 * which could occur if the git_dir or worktree location was
2016 * manually configured by the user; see t2205 testcases 1-3 for
2017 * examples where this matters
2018 */
2019 int nested_repo;
2020 struct strbuf sb = STRBUF_INIT;
2021 strbuf_addstr(&sb, dirname);
2022 nested_repo = is_nonbare_repository_dir(&sb);
2023

Callers 1

treat_pathFunction · 0.85

Calls 8

strbuf_addstrFunction · 0.85
real_pathdupFunction · 0.85
strbuf_releaseFunction · 0.85
read_directory_recursiveFunction · 0.85
lookup_untrackedFunction · 0.85

Tested by

no test coverage detected