Skip to content

Commit 2df179d

Browse files
newrengitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0126d14 commit 2df179d

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

dir.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1656,7 +1656,7 @@ static enum exist_status directory_exists_in_index(struct index_state *istate,
16561656
static enum path_treatment treat_directory(struct dir_struct *dir,
16571657
struct index_state *istate,
16581658
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,
16601660
const struct pathspec *pathspec)
16611661
{
16621662
int nested_repo = 0;
@@ -1679,13 +1679,13 @@ static enum path_treatment treat_directory(struct dir_struct *dir,
16791679
}
16801680
if (nested_repo)
16811681
return ((dir->flags & DIR_SKIP_NESTED_GIT) ? path_none :
1682-
(exclude ? path_excluded : path_untracked));
1682+
(excluded ? path_excluded : path_untracked));
16831683

16841684
if (dir->flags & DIR_SHOW_OTHER_DIRECTORIES)
16851685
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)) {
16891689

16901690
/*
16911691
* This is an excluded directory and we are
@@ -1713,7 +1713,7 @@ static enum path_treatment treat_directory(struct dir_struct *dir,
17131713
/* This is the "show_other_directories" case */
17141714

17151715
if (!(dir->flags & DIR_HIDE_EMPTY_DIRECTORIES))
1716-
return exclude ? path_excluded : path_untracked;
1716+
return excluded ? path_excluded : path_untracked;
17171717

17181718
untracked = lookup_untracked(dir->untracked, untracked,
17191719
dirname + baselen, len - baselen);
@@ -1723,7 +1723,7 @@ static enum path_treatment treat_directory(struct dir_struct *dir,
17231723
* the directory contains any files.
17241724
*/
17251725
return read_directory_recursive(dir, istate, dirname, len,
1726-
untracked, 1, exclude, pathspec);
1726+
untracked, 1, excluded, pathspec);
17271727
}
17281728

17291729
/*
@@ -1904,7 +1904,7 @@ static enum path_treatment treat_path(struct dir_struct *dir,
19041904
int baselen,
19051905
const struct pathspec *pathspec)
19061906
{
1907-
int has_path_in_index, dtype, exclude;
1907+
int has_path_in_index, dtype, excluded;
19081908
enum path_treatment path_treatment;
19091909

19101910
if (!cdir->d_name)
@@ -1949,13 +1949,13 @@ static enum path_treatment treat_path(struct dir_struct *dir,
19491949
(directory_exists_in_index(istate, path->buf, path->len) == index_nonexistent))
19501950
return path_none;
19511951

1952-
exclude = is_excluded(dir, istate, path->buf, &dtype);
1952+
excluded = is_excluded(dir, istate, path->buf, &dtype);
19531953

19541954
/*
19551955
* Excluded? If we don't explicitly want to show
19561956
* ignored files, ignore it
19571957
*/
1958-
if (exclude && !(dir->flags & (DIR_SHOW_IGNORED|DIR_SHOW_IGNORED_TOO)))
1958+
if (excluded && !(dir->flags & (DIR_SHOW_IGNORED|DIR_SHOW_IGNORED_TOO)))
19591959
return path_excluded;
19601960

19611961
switch (dtype) {
@@ -1965,7 +1965,7 @@ static enum path_treatment treat_path(struct dir_struct *dir,
19651965
strbuf_addch(path, '/');
19661966
path_treatment = treat_directory(dir, istate, untracked,
19671967
path->buf, path->len,
1968-
baselen, exclude, pathspec);
1968+
baselen, excluded, pathspec);
19691969
/*
19701970
* If 1) we only want to return directories that
19711971
* match an exclude pattern and 2) this directory does
@@ -1974,15 +1974,15 @@ static enum path_treatment treat_path(struct dir_struct *dir,
19741974
* recurse into this directory (instead of marking the
19751975
* directory itself as an ignored path).
19761976
*/
1977-
if (!exclude &&
1977+
if (!excluded &&
19781978
path_treatment == path_excluded &&
19791979
(dir->flags & DIR_SHOW_IGNORED_TOO) &&
19801980
(dir->flags & DIR_SHOW_IGNORED_TOO_MODE_MATCHING))
19811981
return path_recurse;
19821982
return path_treatment;
19831983
case DT_REG:
19841984
case DT_LNK:
1985-
return exclude ? path_excluded : path_untracked;
1985+
return excluded ? path_excluded : path_untracked;
19861986
}
19871987
}
19881988

0 commit comments

Comments
 (0)