DefaultVcsRootPolicy refactoring: 'isIgnored' check moved from 'matchesDefaultMapping' implementations to 'getMappingFor'

This commit is contained in:
nik
2014-07-22 14:25:42 +04:00
parent 363b2cd981
commit 006705cf3d
2 changed files with 12 additions and 13 deletions
@@ -21,7 +21,6 @@ import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.components.StorageScheme;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleManager;
import com.intellij.openapi.module.ModuleUtil;
import com.intellij.openapi.module.ModuleUtilCore;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ex.ProjectEx;
@@ -35,7 +34,6 @@ import com.intellij.openapi.vcs.changes.FilePathUnderVcs;
import com.intellij.openapi.vcs.changes.VcsGuess;
import com.intellij.openapi.vcs.ex.ProjectLevelVcsManagerEx;
import com.intellij.openapi.vcs.impl.projectlevelman.NewMappings;
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VfsUtilCore;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;
@@ -102,10 +100,7 @@ public class ModuleDefaultVcsRootPolicy extends DefaultVcsRootPolicy {
if (matchContext != null) {
return true;
}
if (myBaseDir != null && VfsUtilCore.isAncestor(myBaseDir, file, false)) {
return !ProjectRootManager.getInstance(myProject).getFileIndex().isIgnored(file);
}
return false;
return myBaseDir != null && VfsUtilCore.isAncestor(myBaseDir, file, false);
}
@Override
@@ -53,17 +53,17 @@ public class NewMappings {
private final DefaultVcsRootPolicy myDefaultVcsRootPolicy;
private final MessageBus myMessageBus;
private final FileStatusManager myFileStatusManager;
private final FileIndexFacade myExcludedFileIndex;
private final FileIndexFacade myFileIndexFacade;
private final Project myProject;
private boolean myActivated;
public NewMappings(final Project project, final MessageBus messageBus,
final ProjectLevelVcsManagerImpl vcsManager, FileStatusManager fileStatusManager, FileIndexFacade excludedFileIndex) {
final ProjectLevelVcsManagerImpl vcsManager, FileStatusManager fileStatusManager, FileIndexFacade fileIndexFacade) {
myProject = project;
myMessageBus = messageBus;
myFileStatusManager = fileStatusManager;
myExcludedFileIndex = excludedFileIndex;
myFileIndexFacade = fileIndexFacade;
myLock = new Object();
myVcsToPaths = new HashMap<String, List<VcsDirectoryMapping>>();
myFileWatchRequestsManager = new FileWatchRequestsManager(myProject, this, LocalFileSystem.getInstance());
@@ -232,7 +232,12 @@ public class NewMappings {
}
@Nullable
public VcsDirectoryMapping getMappingFor(final VirtualFile file, final Object matchContext) {
public VcsDirectoryMapping getMappingFor(final VirtualFile file, final Object parentModule) {
// if parentModule is not null it means that file belongs to the module so it isn't excluded
if (parentModule == null && myFileIndexFacade.isExcludedFile(file)) {
return null;
}
// performance: calculate file path just once, rather than once per mapping
String path = file.getPath();
final String systemIndependentPath = FileUtil.toSystemIndependentName((file.isDirectory() && (! path.endsWith("/"))) ? (path + "/") : path);
@@ -242,7 +247,7 @@ public class NewMappings {
}
for (int i = mappings.length - 1; i >= 0; -- i) {
final VcsDirectoryMapping mapping = mappings[i];
if (fileMatchesMapping(file, matchContext, systemIndependentPath, mapping)) {
if (fileMatchesMapping(file, parentModule, systemIndependentPath, mapping)) {
return mapping;
}
}
@@ -262,8 +267,7 @@ public class NewMappings {
if (mapping.getDirectory().length() == 0) {
return myDefaultVcsRootPolicy.matchesDefaultMapping(file, matchContext);
}
return FileUtil.startsWith(systemIndependentPath, mapping.systemIndependentPath()) &&
! myExcludedFileIndex.isExcludedFile(file);
return FileUtil.startsWith(systemIndependentPath, mapping.systemIndependentPath());
}
public List<VirtualFile> getMappingsAsFilesUnderVcs(final AbstractVcs vcs) {