Skip to content

Commit 52ee181

Browse files
committed
Only apply IndexDiffFilter when scanning directories
When getStatus() is called with specific files rather than directories, tests expect those files to be present in the result even when clean (all-NORMAL status). IndexDiffFilter filters out clean entries entirely, breaking that contract. Restrict IndexDiffFilter to directory-only scans. This pleases the tests but still applies the optimization in the Commit dilog, which calls getStatus() on a directory with potentially many files. A better approach would be to preload file status and parallelize computing hashes with fti.isModified(indexEntry, true,...), so that it doesn't block main thread. This, however, requires a lot of refactoring, so let's try a simple approach first.
1 parent 8465e80 commit 52ee181

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

ide/libs.git/src/org/netbeans/libs/git/jgit/commands/StatusCommand.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,19 @@ protected void run () throws GitException {
135135
final int T_WORKSPACE = 2;
136136
// IndexDiffFilter skips files where HEAD==index and working tree
137137
// is unmodified (avoiding content hashing for clean files).
138-
// Combine with path filters when present.
139-
TreeFilter diffFilter = new IndexDiffFilter(T_INDEX, T_WORKSPACE, true);
140-
if (!pathFilters.isEmpty()) {
141-
diffFilter = AndTreeFilter.create(PathFilterGroup.create(pathFilters), diffFilter);
138+
// Only apply when all roots are directories: callers that pass
139+
// specific files expect those files in the result even when clean.
140+
boolean allRootsAreDirs = Arrays.stream(roots).allMatch(File::isDirectory);
141+
TreeFilter diffFilter;
142+
if (allRootsAreDirs) {
143+
diffFilter = new IndexDiffFilter(T_INDEX, T_WORKSPACE, true);
144+
if (!pathFilters.isEmpty()) {
145+
diffFilter = AndTreeFilter.create(PathFilterGroup.create(pathFilters), diffFilter);
146+
}
147+
} else if (!pathFilters.isEmpty()) {
148+
diffFilter = PathFilterGroup.create(pathFilters);
149+
} else {
150+
diffFilter = TreeFilter.ALL;
142151
}
143152
treeWalk.setFilter(diffFilter);
144153
String lastPath = null;

0 commit comments

Comments
 (0)