@matheusbsbs / matheus-bagliano / commits / 2df179d3df
Fork 0

dir: fix confusion based on variable tense

Despite having contributed several fixes in this area, I have for months (years?) assumed that the "exclude" variable was a directive; this caused me to think of it as a different mode we operate in and left me confused as I tried to build up a mental model around why we'd need such a directive. I mostly tried to ignore it while focusing on the pieces I was trying to understand. Then I finally traced this variable all back to a call to is_excluded(), meaning it was actually functioning as an adjective. In particular, it was a checked property ("Does this path match a rule in .gitignore?"), rather than a mode passed in from the caller. Change the variable name to match the part of speech used by the function called to define it, which will hopefully make these bits of code slightly clearer to the next reader. Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Elijah Newren committed Apr 1, 2020 at 04:17 UTC 2df179d3dfeb431cc3030ac44e79b136debf1fd9
1 file changed +13 -13
dir.c
+13 -13
@@ -1656,7 +1656,7 @@ static enum exist_status directory_exists_in_index(struct index_state *istate,
1656 static enum path_treatment treat_directory(struct dir_struct *dir,
1657 struct index_state *istate,
1658 struct untracked_cache_dir *untracked,
1659 - const char *dirname, int len, int baselen, int exclude,
1659 + const char *dirname, int len, int baselen, int excluded,
1660 const struct pathspec *pathspec)
1661 {
1662 int nested_repo = 0;
@@ -1679,13 +1679,13 @@ static enum path_treatment treat_directory(struct dir_struct *dir,
1679 }
1680 if (nested_repo)
1681 return ((dir->flags & DIR_SKIP_NESTED_GIT) ? path_none :
1682 - (exclude ? path_excluded : path_untracked));
1682 + (excluded ? path_excluded : path_untracked));
1683
1684 if (dir->flags & DIR_SHOW_OTHER_DIRECTORIES)
1685 break;
1686 - if (exclude &&
1687 - (dir->flags & DIR_SHOW_IGNORED_TOO) &&
1688 - (dir->flags & DIR_SHOW_IGNORED_TOO_MODE_MATCHING)) {
1686 + if (excluded &&
1687 + (dir->flags & DIR_SHOW_IGNORED_TOO) &&
1688 + (dir->flags & DIR_SHOW_IGNORED_TOO_MODE_MATCHING)) {
1689
1690 /*
1691 * This is an excluded directory and we are
@@ -1713,7 +1713,7 @@ static enum path_treatment treat_directory(struct dir_struct *dir,
1713 /* This is the "show_other_directories" case */
1714
1715 if (!(dir->flags & DIR_HIDE_EMPTY_DIRECTORIES))
1716 - return exclude ? path_excluded : path_untracked;
1716 + return excluded ? path_excluded : path_untracked;
1717
1718 untracked = lookup_untracked(dir->untracked, untracked,
1719 dirname + baselen, len - baselen);
@@ -1723,7 +1723,7 @@ static enum path_treatment treat_directory(struct dir_struct *dir,
1723 * the directory contains any files.
1724 */
1725 return read_directory_recursive(dir, istate, dirname, len,
1726 - untracked, 1, exclude, pathspec);
1726 + untracked, 1, excluded, pathspec);
1727 }
1728
1729 /*
@@ -1904,7 +1904,7 @@ static enum path_treatment treat_path(struct dir_struct *dir,
1904 int baselen,
1905 const struct pathspec *pathspec)
1906 {
1907 - int has_path_in_index, dtype, exclude;
1907 + int has_path_in_index, dtype, excluded;
1908 enum path_treatment path_treatment;
1909
1910 if (!cdir->d_name)
@@ -1949,13 +1949,13 @@ static enum path_treatment treat_path(struct dir_struct *dir,
1949 (directory_exists_in_index(istate, path->buf, path->len) == index_nonexistent))
1950 return path_none;
1951
1952 - exclude = is_excluded(dir, istate, path->buf, &dtype);
1952 + excluded = is_excluded(dir, istate, path->buf, &dtype);
1953
1954 /*
1955 * Excluded? If we don't explicitly want to show
1956 * ignored files, ignore it
1957 */
1958 - if (exclude && !(dir->flags & (DIR_SHOW_IGNORED|DIR_SHOW_IGNORED_TOO)))
1958 + if (excluded && !(dir->flags & (DIR_SHOW_IGNORED|DIR_SHOW_IGNORED_TOO)))
1959 return path_excluded;
1960
1961 switch (dtype) {
@@ -1965,7 +1965,7 @@ static enum path_treatment treat_path(struct dir_struct *dir,
1965 strbuf_addch(path, '/');
1966 path_treatment = treat_directory(dir, istate, untracked,
1967 path->buf, path->len,
1968 - baselen, exclude, pathspec);
1968 + baselen, excluded, pathspec);
1969 /*
1970 * If 1) we only want to return directories that
1971 * match an exclude pattern and 2) this directory does
@@ -1974,7 +1974,7 @@ static enum path_treatment treat_path(struct dir_struct *dir,
1974 * recurse into this directory (instead of marking the
1975 * directory itself as an ignored path).
1976 */
1977 - if (!exclude &&
1977 + if (!excluded &&
1978 path_treatment == path_excluded &&
1979 (dir->flags & DIR_SHOW_IGNORED_TOO) &&
1980 (dir->flags & DIR_SHOW_IGNORED_TOO_MODE_MATCHING))
@@ -1982,7 +1982,7 @@ static enum path_treatment treat_path(struct dir_struct *dir,
1982 return path_treatment;
1983 case DT_REG:
1984 case DT_LNK:
1985 - return exclude ? path_excluded : path_untracked;
1985 + return excluded ? path_excluded : path_untracked;
1986 }
1987 }
1988