Skip to content

Commit 1684644

Browse files
newrengitster
authored andcommitted
dir: include DIR_KEEP_UNTRACKED_CONTENTS handling in treat_directory()
Handling DIR_KEEP_UNTRACKED_CONTENTS within treat_directory() instead of as a post-processing step in read_directory(): * allows us to directly access and remove the relevant entries instead of needing to calculate which ones need to be removed * keeps the logic for directory handling in one location (and puts it closer the the logic for stripping out extra ignored entries, which seems logical). Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8d92fb2 commit 1684644

File tree

1 file changed

+19
-24
lines changed

1 file changed

+19
-24
lines changed

dir.c

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1665,7 +1665,8 @@ static enum path_treatment treat_directory(struct dir_struct *dir,
16651665
* you CAN'T DO BOTH.
16661666
*/
16671667
enum path_treatment state;
1668-
int nested_repo = 0, old_ignored_nr, check_only, stop_early;
1668+
int nested_repo = 0, check_only, stop_early;
1669+
int old_ignored_nr, old_untracked_nr;
16691670
/* The "len-1" is to strip the final '/' */
16701671
enum exist_status status = directory_exists_in_index(istate, dirname, len-1);
16711672

@@ -1785,9 +1786,13 @@ static enum path_treatment treat_directory(struct dir_struct *dir,
17851786
* --porcelain), without listing the individual ignored files
17861787
* underneath. To do so, we'll save the current ignored_nr, and
17871788
* pop all the ones added after it if it turns out the entire
1788-
* directory is ignored.
1789+
* directory is ignored. Also, when DIR_SHOW_IGNORED_TOO and
1790+
* !DIR_KEEP_UNTRACKED_CONTENTS then we don't want to show
1791+
* untracked paths so will need to pop all those off the last
1792+
* after we traverse.
17891793
*/
17901794
old_ignored_nr = dir->ignored_nr;
1795+
old_untracked_nr = dir->nr;
17911796

17921797
/* Actually recurse into dirname now, we'll fixup the state later. */
17931798
untracked = lookup_untracked(dir->untracked, untracked,
@@ -1825,6 +1830,18 @@ static enum path_treatment treat_directory(struct dir_struct *dir,
18251830
}
18261831
}
18271832

1833+
/*
1834+
* We may need to ignore some of the untracked paths we found while
1835+
* traversing subdirectories.
1836+
*/
1837+
if ((dir->flags & DIR_SHOW_IGNORED_TOO) &&
1838+
!(dir->flags & DIR_KEEP_UNTRACKED_CONTENTS)) {
1839+
int i;
1840+
for (i = old_untracked_nr + 1; i<dir->nr; ++i)
1841+
FREE_AND_NULL(dir->entries[i]);
1842+
dir->nr = old_untracked_nr;
1843+
}
1844+
18281845
/*
18291846
* If there is nothing under the current directory and we are not
18301847
* hiding empty directories, then we need to report on the
@@ -2653,28 +2670,6 @@ int read_directory(struct dir_struct *dir, struct index_state *istate,
26532670
QSORT(dir->entries, dir->nr, cmp_dir_entry);
26542671
QSORT(dir->ignored, dir->ignored_nr, cmp_dir_entry);
26552672

2656-
/*
2657-
* If DIR_SHOW_IGNORED_TOO is set, read_directory_recursive() will
2658-
* also pick up untracked contents of untracked dirs; by default
2659-
* we discard these, but given DIR_KEEP_UNTRACKED_CONTENTS we do not.
2660-
*/
2661-
if ((dir->flags & DIR_SHOW_IGNORED_TOO) &&
2662-
!(dir->flags & DIR_KEEP_UNTRACKED_CONTENTS)) {
2663-
int i, j;
2664-
2665-
/* remove from dir->entries untracked contents of untracked dirs */
2666-
for (i = j = 0; j < dir->nr; j++) {
2667-
if (i &&
2668-
check_dir_entry_contains(dir->entries[i - 1], dir->entries[j])) {
2669-
FREE_AND_NULL(dir->entries[j]);
2670-
} else {
2671-
dir->entries[i++] = dir->entries[j];
2672-
}
2673-
}
2674-
2675-
dir->nr = i;
2676-
}
2677-
26782673
trace_performance_leave("read directory %.*s", len, path);
26792674
if (dir->untracked) {
26802675
static int force_untracked_cache = -1;

0 commit comments

Comments
 (0)