diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/roots/VcsRootDetectorImpl.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/roots/VcsRootDetectorImpl.java index f6021a6a551a..8d99c3b0af3f 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/roots/VcsRootDetectorImpl.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/roots/VcsRootDetectorImpl.java @@ -62,15 +62,12 @@ public class VcsRootDetectorImpl implements VcsRootDetector { return Collections.emptyList(); } - final Set roots = scanForRootsInsideDir(startDir); - roots.addAll(scanForRootsInContentRoots()); - for (VcsRoot root : roots) { - if (startDir.equals(root.getPath())) { - return roots; - } + Set roots = scanForRootsInsideDir(startDir); + if (shouldScanAbove(startDir, roots)) { + VcsRoot rootAbove = scanForSingleRootAboveDir(startDir); + if (rootAbove != null) roots.add(rootAbove); } - VcsRoot rootAbove = scanForSingleRootAboveDir(startDir); - if (rootAbove != null) roots.add(rootAbove); + roots.addAll(scanForRootsInContentRoots()); return roots; } @@ -84,18 +81,12 @@ public class VcsRootDetectorImpl implements VcsRootDetector { continue; } - Set rootsInsideRoot = scanForRootsInsideDir(contentRoot); - boolean shouldScanAbove = true; - for (VcsRoot root : rootsInsideRoot) { - if (contentRoot.equals(root.getPath())) { - shouldScanAbove = false; - } - } - if (shouldScanAbove) { + Set vcsRootsInContentRoot = scanForRootsInsideDir(contentRoot); + if (shouldScanAbove(contentRoot, vcsRootsInContentRoot)) { VcsRoot rootAbove = scanForSingleRootAboveDir(contentRoot); - if (rootAbove != null) rootsInsideRoot.add(rootAbove); + if (rootAbove != null) vcsRootsInContentRoot.add(rootAbove); } - vcsRoots.addAll(rootsInsideRoot); + vcsRoots.addAll(vcsRootsInContentRoot); } return vcsRoots; } @@ -122,6 +113,10 @@ public class VcsRootDetectorImpl implements VcsRootDetector { return roots; } + private static boolean shouldScanAbove(@NotNull VirtualFile startDir, @NotNull Set rootsInsideDir) { + return rootsInsideDir.stream().noneMatch(it -> startDir.equals(it.getPath())); + } + private static boolean depthLimitExceeded(int depth) { int maxDepth = Registry.intValue("vcs.root.detector.folder.depth"); return maxDepth >= 0 && maxDepth < depth;