From fb22becd6c3d17a3330d8a93947f0e9012d04dce Mon Sep 17 00:00:00 2001 From: Anton Makeev Date: Mon, 21 Nov 2016 14:16:16 +0300 Subject: [PATCH] allow removing implicitly ignored directories (CPP-8028 Exclude generated CMake files from VCS automatically) --- .../vcs/changes/ChangeListManager.java | 3 +- .../vcs/changes/ChangeListManagerImpl.java | 8 +++-- .../vcs/changes/IgnoredFilesComponent.java | 30 ++++++++++++++----- .../vcs/MockChangeListManager.java | 7 ++++- 4 files changed, 36 insertions(+), 12 deletions(-) diff --git a/platform/vcs-api/src/com/intellij/openapi/vcs/changes/ChangeListManager.java b/platform/vcs-api/src/com/intellij/openapi/vcs/changes/ChangeListManager.java index 7bc5a6f5cbe7..7b9fa95aa18f 100644 --- a/platform/vcs-api/src/com/intellij/openapi/vcs/changes/ChangeListManager.java +++ b/platform/vcs-api/src/com/intellij/openapi/vcs/changes/ChangeListManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2016 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -139,6 +139,7 @@ public abstract class ChangeListManager implements ChangeListModification { public abstract void addFilesToIgnore(final IgnoredFileBean... ignoredFiles); public abstract void addDirectoryToIgnoreImplicitly(@NotNull String path); + public abstract void removeImplicitlyIgnoredDirectory(@NotNull String path); public abstract void setFilesToIgnore(final IgnoredFileBean... ignoredFiles); public abstract IgnoredFileBean[] getFilesToIgnore(); public abstract boolean isIgnoredFile(@NotNull VirtualFile file); diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangeListManagerImpl.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangeListManagerImpl.java index fda0d5762b9b..767160dc9703 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangeListManagerImpl.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangeListManagerImpl.java @@ -54,7 +54,6 @@ import com.intellij.util.messages.Topic; import com.intellij.util.ui.UIUtil; import com.intellij.vcsUtil.VcsUtil; import org.jdom.Element; -import org.jetbrains.annotations.CalledInAwt; import org.jetbrains.annotations.*; import javax.swing.*; @@ -63,7 +62,7 @@ import java.util.*; import java.util.concurrent.*; import java.util.concurrent.atomic.AtomicReference; -import static com.intellij.openapi.vcs.ProjectLevelVcsManager.*; +import static com.intellij.openapi.vcs.ProjectLevelVcsManager.VCS_CONFIGURATION_CHANGED; @State(name = "ChangeListManager", storages = @Storage(StoragePathMacros.WORKSPACE_FILE)) public class ChangeListManagerImpl extends ChangeListManagerEx implements ProjectComponent, ChangeListOwner, PersistentStateComponent { @@ -1431,6 +1430,11 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec myIgnoredIdeaLevel.addIgnoredDirectoryImplicitly(path, myProject); } + @Override + public void removeImplicitlyIgnoredDirectory(@NotNull String path) { + myIgnoredIdeaLevel.removeImplicitlyIgnoredDirectory(path, myProject); + } + public IgnoredFilesComponent getIgnoredFilesComponent() { return myIgnoredIdeaLevel; } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/IgnoredFilesComponent.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/IgnoredFilesComponent.java index 0b3ae211debd..ab8953cacdb0 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/IgnoredFilesComponent.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/IgnoredFilesComponent.java @@ -102,20 +102,34 @@ public class IgnoredFilesComponent { return; } } - List toRemove = new ArrayList<>(); - for (IgnoredFileBean bean : myFilesToIgnore) { - if ((bean.getType() == IgnoreSettingsType.UNDER_DIR || bean.getType() == IgnoreSettingsType.FILE) && - FileUtil.isAncestor(path, bean.getPath(), false)) { - toRemove.add(bean); - } - } - myFilesToIgnore.removeAll(toRemove); + doRemoveFilesToIgnore(path, true); myFilesToIgnore.add(IgnoredBeanFactory.ignoreUnderDirectory(path, project)); } finally { myWriteLock.unlock(); } } + + public void removeImplicitlyIgnoredDirectory(@NotNull String path, @NotNull Project project) { + myWriteLock.lock(); + try { + doRemoveFilesToIgnore(path, false); + } + finally { + myWriteLock.unlock(); + } + } + + private void doRemoveFilesToIgnore(@NotNull String path, boolean includingSubpaths) { + List toRemove = new ArrayList<>(); + for (IgnoredFileBean bean : myFilesToIgnore) { + if ((bean.getType() == IgnoreSettingsType.UNDER_DIR || bean.getType() == IgnoreSettingsType.FILE) && + includingSubpaths ? FileUtil.isAncestor(path, bean.getPath(), false) : FileUtil.pathsEqual(path, bean.getPath())) { + toRemove.add(bean); + } + } + myFilesToIgnore.removeAll(toRemove); + } private void addIgnoredFiles(@NotNull IgnoredFileBean[] filesToIgnore) { for (IgnoredFileBean bean : filesToIgnore) { diff --git a/platform/vcs-impl/testSrc/com/intellij/testFramework/vcs/MockChangeListManager.java b/platform/vcs-impl/testSrc/com/intellij/testFramework/vcs/MockChangeListManager.java index 56feefa0cadc..0e353c6867ef 100644 --- a/platform/vcs-impl/testSrc/com/intellij/testFramework/vcs/MockChangeListManager.java +++ b/platform/vcs-impl/testSrc/com/intellij/testFramework/vcs/MockChangeListManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2016 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -281,6 +281,11 @@ public class MockChangeListManager extends ChangeListManagerEx { throw new UnsupportedOperationException(); } + @Override + public void removeImplicitlyIgnoredDirectory(@NotNull String path) { + throw new UnsupportedOperationException(); + } + @Override public void setFilesToIgnore(IgnoredFileBean... ignoredFiles) { throw new UnsupportedOperationException();