@Override
 @Nullable
 public VirtualFile getVcsRootFor(@Nullable final VirtualFile file) {
   final VcsDirectoryMapping mapping = myMappings.getMappingFor(file);
   if (mapping == null) {
     return null;
   }
   final String directory = mapping.getDirectory();
   if (directory.isEmpty()) {
     return myDefaultVcsRootPolicy.getVcsRootFor(file);
   }
   return LocalFileSystem.getInstance().findFileByPath(directory);
 }
 @Override
 @Nullable
 public VcsRoot getVcsRootObjectFor(final VirtualFile file) {
   final VcsDirectoryMapping mapping = myMappings.getMappingFor(file);
   if (mapping == null) {
     return null;
   }
   final String directory = mapping.getDirectory();
   final AbstractVcs vcs = findVcsByName(mapping.getVcs());
   if (directory.isEmpty()) {
     return new VcsRoot(vcs, myDefaultVcsRootPolicy.getVcsRootFor(file));
   }
   return new VcsRoot(vcs, LocalFileSystem.getInstance().findFileByPath(directory));
 }
  public ProjectLevelVcsManagerImpl(
      Project project,
      final FileStatusManager manager,
      MessageBus messageBus,
      final FileIndexFacade excludedFileIndex) {
    myProject = project;
    myMessageBus = messageBus;
    mySerialization = new ProjectLevelVcsManagerSerialization();
    myOptionsAndConfirmations = new OptionsAndConfirmations();

    myDefaultVcsRootPolicy = DefaultVcsRootPolicy.getInstance(project);

    myBackgroundableActionHandlerMap =
        new EnumMap<VcsBackgroundableActions, BackgroundableActionEnabledHandler>(
            VcsBackgroundableActions.class);
    myInitialization = new VcsInitialization(myProject);
    myMappings = new NewMappings(myProject, myMessageBus, this, manager);
    myMappingsToRoots = new MappingsToRoots(myMappings, myProject);

    if (!myProject.isDefault()) {
      myVcsEventListenerManager = new VcsEventsListenerManagerImpl();
    }

    myVcsHistoryCache = new VcsHistoryCache();
    myContentRevisionCache = new ContentRevisionCache();
    myConnect = myMessageBus.connect();
    myVcsFileListenerContextHelper = VcsFileListenerContextHelper.getInstance(myProject);
    VcsListener vcsListener =
        new VcsListener() {
          @Override
          public void directoryMappingChanged() {
            myVcsHistoryCache.clear();
            myVcsFileListenerContextHelper.possiblySwitchActivation(hasActiveVcss());
          }
        };
    myExcludedIndex = excludedFileIndex;
    myConnect.subscribe(ProjectLevelVcsManager.VCS_CONFIGURATION_CHANGED, vcsListener);
    myConnect.subscribe(ProjectLevelVcsManager.VCS_CONFIGURATION_CHANGED_IN_PLUGIN, vcsListener);
    myConnect.subscribe(
        UpdatedFilesListener.UPDATED_FILES,
        new UpdatedFilesListener() {
          @Override
          public void consume(Set<String> strings) {
            myContentRevisionCache.clearCurrent(strings);
          }
        });
    myAnnotationLocalChangesListener = new VcsAnnotationLocalChangesListenerImpl(myProject, this);
  }