diff --git a/platform/vcs-impl/src/com/intellij/impl/VcsModuleAttachListener.kt b/platform/vcs-impl/src/com/intellij/impl/VcsModuleAttachListener.kt index 8481b4b906b1..c9fc48207649 100644 --- a/platform/vcs-impl/src/com/intellij/impl/VcsModuleAttachListener.kt +++ b/platform/vcs-impl/src/com/intellij/impl/VcsModuleAttachListener.kt @@ -6,6 +6,7 @@ import com.intellij.openapi.roots.ModuleRootManager import com.intellij.openapi.util.io.FileUtil import com.intellij.openapi.vcs.ProjectLevelVcsManager import com.intellij.openapi.vcs.VcsDirectoryMapping +import com.intellij.openapi.vcs.ex.ProjectLevelVcsManagerEx.MAPPING_DETECTION_LOG import com.intellij.openapi.vfs.LocalFileSystem import com.intellij.openapi.vfs.VirtualFile import com.intellij.platform.ModuleAttachListener @@ -27,6 +28,7 @@ class VcsModuleAttachListener : ModuleAttachListener { } private fun addVcsMapping(primaryModule: Module, addedModuleContentRoot: VirtualFile) { + MAPPING_DETECTION_LOG.debug("VcsModuleAttachListener.addVcsMapping", primaryModule, addedModuleContentRoot) val project = primaryModule.project val vcsManager = ProjectLevelVcsManager.getInstance(project) val mappings = vcsManager.directoryMappings @@ -53,6 +55,7 @@ class VcsModuleAttachListener : ModuleAttachListener { } private fun removeVcsMapping(module: Module) { + MAPPING_DETECTION_LOG.debug("VcsModuleAttachListener.removeVcsMapping", module) val project = module.project val vcsManager = ProjectLevelVcsManager.getInstance(project) val mappings = vcsManager.directoryMappings diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/ProjectLevelVcsManagerEx.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/ProjectLevelVcsManagerEx.java index 9af6ec295d92..f15ef148e47a 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/ProjectLevelVcsManagerEx.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/ProjectLevelVcsManagerEx.java @@ -1,10 +1,12 @@ // Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.openapi.vcs.ex; +import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; import com.intellij.openapi.vcs.AbstractVcs; import com.intellij.openapi.vcs.ProjectLevelVcsManager; import com.intellij.openapi.vcs.VcsConfiguration; +import com.intellij.openapi.vcs.impl.projectlevelman.NewMappings; import com.intellij.openapi.vcs.impl.projectlevelman.PersistentVcsShowConfirmationOption; import com.intellij.openapi.vcs.impl.projectlevelman.PersistentVcsShowSettingOption; import com.intellij.openapi.vcs.update.ActionInfo; @@ -20,6 +22,9 @@ import org.jetbrains.annotations.Nullable; import java.util.List; public abstract class ProjectLevelVcsManagerEx extends ProjectLevelVcsManager { + @SuppressWarnings("LoggerInitializedWithForeignClass") + public static final Logger MAPPING_DETECTION_LOG = Logger.getInstance(NewMappings.class); + @Topic.ProjectLevel public static final Topic VCS_ACTIVATED = new Topic<>(VcsActivationListener.class, Topic.BroadcastDirection.NONE); diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/ModuleVcsDetector.kt b/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/ModuleVcsDetector.kt index 2c384c360979..837accd65f59 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/ModuleVcsDetector.kt +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/ModuleVcsDetector.kt @@ -8,6 +8,7 @@ import com.intellij.openapi.project.Project import com.intellij.openapi.startup.StartupActivity import com.intellij.openapi.vcs.AbstractVcs import com.intellij.openapi.vcs.VcsDirectoryMapping +import com.intellij.openapi.vcs.ex.ProjectLevelVcsManagerEx.MAPPING_DETECTION_LOG import com.intellij.openapi.vfs.VirtualFile import com.intellij.util.Alarm import com.intellij.util.concurrency.annotations.RequiresBackgroundThread @@ -23,6 +24,7 @@ internal class ModuleVcsDetector(private val project: Project) { } private fun startDetection() { + MAPPING_DETECTION_LOG.debug("ModuleVcsDetector.startDetection") val busConnection = project.messageBus.connect() WorkspaceModelTopics.getInstance(project).subscribeAfterModuleLoading(busConnection, MyWorkspaceModelChangeListener()) @@ -35,12 +37,15 @@ internal class ModuleVcsDetector(private val project: Project) { @RequiresBackgroundThread private fun autoDetectDefaultRoots() { + MAPPING_DETECTION_LOG.debug("ModuleVcsDetector.autoDetectDefaultRoots") if (vcsManager.haveDefaultMapping() != null) return + val contentRoots = DefaultVcsRootPolicy.getInstance(project).defaultVcsRoots + MAPPING_DETECTION_LOG.debug("ModuleVcsDetector.autoDetectDefaultRoots - contentRoots", contentRoots) + val usedVcses = mutableSetOf() val detectedRoots = mutableSetOf>() - val contentRoots = DefaultVcsRootPolicy.getInstance(project).defaultVcsRoots contentRoots .forEach { root -> val foundVcs = vcsManager.findVersioningVcs(root) @@ -50,6 +55,7 @@ internal class ModuleVcsDetector(private val project: Project) { } } if (detectedRoots.isEmpty()) return + MAPPING_DETECTION_LOG.debug("ModuleVcsDetector.autoDetectDefaultRoots - detectedRoots", detectedRoots) val commonVcs = usedVcses.singleOrNull() if (commonVcs != null) { @@ -65,6 +71,7 @@ internal class ModuleVcsDetector(private val project: Project) { @RequiresBackgroundThread private fun autoDetectForContentRoots(contentRoots: List) { + MAPPING_DETECTION_LOG.debug("ModuleVcsDetector.autoDetectForContentRoots - contentRoots", contentRoots) if (vcsManager.haveDefaultMapping() != null) return val usedVcses = mutableSetOf() @@ -81,6 +88,7 @@ internal class ModuleVcsDetector(private val project: Project) { } } if (detectedRoots.isEmpty()) return + MAPPING_DETECTION_LOG.debug("ModuleVcsDetector.autoDetectForContentRoots - detectedRoots", detectedRoots) val commonVcs = usedVcses.singleOrNull() if (commonVcs != null && !vcsManager.hasAnyMappings()) { @@ -104,15 +112,19 @@ internal class ModuleVcsDetector(private val project: Project) { private val dirtyContentRoots = mutableSetOf() override fun contentRootsChanged(removed: List, added: List) { - if (added.isNotEmpty() && vcsManager.haveDefaultMapping() == null) { - synchronized(dirtyContentRoots) { - dirtyContentRoots.addAll(added) - dirtyContentRoots.removeAll(removed.toSet()) + if (added.isNotEmpty()) { + MAPPING_DETECTION_LOG.debug("ModuleVcsDetector.contentRootsChanged - roots added", added) + if (vcsManager.haveDefaultMapping() == null) { + synchronized(dirtyContentRoots) { + dirtyContentRoots.addAll(added) + dirtyContentRoots.removeAll(removed.toSet()) + } + queue.queue(Update.create("modules scan") { runScanForNewContentRoots() }) } - queue.queue(Update.create("content root scan") { runScanForNewContentRoots() }) } if (removed.isNotEmpty()) { + MAPPING_DETECTION_LOG.debug("ModuleVcsDetector.contentRootsChanged - roots removed", removed) val remotedPaths = removed.map { it.path }.toSet() val removedMappings = vcsManager.directoryMappings.filter { it.directory in remotedPaths } removedMappings.forEach { mapping -> vcsManager.removeDirectoryMapping(mapping) } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/projectlevelman/NewMappings.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/projectlevelman/NewMappings.java index d9d79cbaac8d..7ebd9159ca33 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/projectlevelman/NewMappings.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/projectlevelman/NewMappings.java @@ -596,6 +596,10 @@ public final class NewMappings implements Disposable { } } + if (LOG.isDebugEnabled()) { + LOG.debug("NewMappings.cleanupMappings", getDirectoryMappings(), filteredMappings); + } + updateVcsMappings(filteredMappings); } 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 4a03802d27e2..914d7a87e2ab 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 @@ -19,6 +19,7 @@ import org.jetbrains.annotations.Nullable; import java.util.*; import java.util.regex.Pattern; +import static com.intellij.openapi.vcs.ex.ProjectLevelVcsManagerEx.MAPPING_DETECTION_LOG; import static com.intellij.openapi.vfs.VirtualFileVisitor.CONTINUE; import static com.intellij.openapi.vfs.VirtualFileVisitor.SKIP_CHILDREN; @@ -37,6 +38,7 @@ final class VcsRootDetectorImpl implements VcsRootDetector { @Override @NotNull public Collection detect() { + MAPPING_DETECTION_LOG.debug("VcsRootDetectorImpl.detect"); synchronized (LOCK) { Collection roots = scanForRootsInContentRoots(); myDetectedRoots = ContainerUtil.map(roots, DetectedVcsRoot::new); @@ -47,12 +49,14 @@ final class VcsRootDetectorImpl implements VcsRootDetector { @Override @NotNull public Collection detect(@Nullable VirtualFile startDir) { + MAPPING_DETECTION_LOG.debug("VcsRootDetectorImpl.detect root", startDir); if (startDir == null || !startDir.isInLocalFileSystem()) return Collections.emptyList(); return Collections.unmodifiableSet(scanForDirectory(startDir)); } @Override public @NotNull Collection getOrDetect() { + MAPPING_DETECTION_LOG.debug("VcsRootDetectorImpl.getOrDetect"); synchronized (LOCK) { if (myDetectedRoots != null) { return ContainerUtil.mapNotNull(myDetectedRoots, it -> it.toVcsRoot(myProject)); @@ -83,6 +87,7 @@ final class VcsRootDetectorImpl implements VcsRootDetector { List contentRoots = ContainerUtil.filter(ProjectRootManager.getInstance(myProject).getContentRoots(), file -> file.isInLocalFileSystem()); + MAPPING_DETECTION_LOG.debug("VcsRootDetectorImpl.scanForRootsInContentRoots - contentRoots", contentRoots); VirtualFile baseDir = myProject.getBaseDir(); if (baseDir != null && !contentRoots.contains(baseDir)) { diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/roots/VcsRootProblemNotifier.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/roots/VcsRootProblemNotifier.java index 0df876aad69d..7cd80b423433 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/roots/VcsRootProblemNotifier.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/roots/VcsRootProblemNotifier.java @@ -33,6 +33,7 @@ import static com.intellij.openapi.util.text.StringUtil.escapeXmlEntities; import static com.intellij.openapi.vcs.VcsNotificationIdsHolder.ROOTS_INVALID; import static com.intellij.openapi.vcs.VcsNotificationIdsHolder.ROOTS_REGISTERED; import static com.intellij.openapi.vcs.VcsRootError.Type.UNREGISTERED_ROOT; +import static com.intellij.openapi.vcs.ex.ProjectLevelVcsManagerEx.MAPPING_DETECTION_LOG; import static com.intellij.util.containers.ContainerUtil.*; import static com.intellij.util.ui.UIUtil.BR; @@ -77,7 +78,7 @@ public final class VcsRootProblemNotifier { } return; } - LOG.debug("Following errors detected: " + errors); + MAPPING_DETECTION_LOG.debug("Following errors detected: " + errors); Collection importantUnregisteredRoots = getImportantUnregisteredMappings(errors); Collection invalidRoots = getInvalidRoots(errors); diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/roots/VcsRootScanner.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/roots/VcsRootScanner.java index ce6efed60812..2e671b0bcc64 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/roots/VcsRootScanner.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/roots/VcsRootScanner.java @@ -34,6 +34,7 @@ import java.util.function.Function; import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; +import static com.intellij.openapi.vcs.ex.ProjectLevelVcsManagerEx.MAPPING_DETECTION_LOG; import static com.intellij.openapi.vfs.VirtualFileVisitor.*; @Service @@ -135,6 +136,7 @@ public final class VcsRootScanner implements Disposable { if (myAlarm.isDisposed()) return; if (VcsRootChecker.EXTENSION_POINT_NAME.getExtensionList().isEmpty()) return; + MAPPING_DETECTION_LOG.debug("VcsRootScanner.scheduleScan"); myAlarm.cancelAllRequests(); // one scan is enough, no need to queue, they all do the same myAlarm.addRequest(() -> BackgroundTaskUtil.runUnderDisposeAwareIndicator(myAlarm, () -> { myRootProblemNotifier.rescanAndNotifyIfNeeded(); @@ -179,6 +181,7 @@ public final class VcsRootScanner implements Disposable { public void runActivity(@NotNull Project project) { if (ApplicationManager.getApplication().isUnitTestMode()) return; if (!TrustedProjects.isTrusted(project)) return; // vcs is disabled + MAPPING_DETECTION_LOG.debug("VcsRootScanner.start activity"); getInstance(project).scheduleScan(); }