diff --git a/platform/core-api/src/com/intellij/openapi/vfs/VersionManagingFileSystem.java b/platform/core-api/src/com/intellij/openapi/vfs/VersionManagingFileSystem.java index ad6eaecea819..bd9baa4cb160 100644 --- a/platform/core-api/src/com/intellij/openapi/vfs/VersionManagingFileSystem.java +++ b/platform/core-api/src/com/intellij/openapi/vfs/VersionManagingFileSystem.java @@ -1,18 +1,58 @@ -// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// 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.vfs; +import com.intellij.util.ObjectUtils; import org.jetbrains.annotations.NotNull; /** - * Allows to disable local history creation for a specific file in a virtual file system implementation. + * VirtualFileSystem interface to control file appearance in a local history. */ public interface VersionManagingFileSystem { - /** - * Checks if a local history should be created for the file in question. - * @param file The virtual file to check. - * @return {@code true} if the file can be versioned. It's actual versioning in this case depends on other conditions, for example, if - * the file is ignored. {@code false} if file's change history should not be tracked. - */ - boolean isVersionable(@NotNull VirtualFile file); + enum Type { + /** + * File is excluded from local history. Used to explicitly suppress file history collection. + */ + DISABLED, + /** + * File's history by the IDE's own local history manager. + */ + LOCAL, + + /** + * File's history is managed by the virtual file system. + * + */ + FILE_SYSTEM + } + + /** + * Determines a versioning type of the given virtual file. + * + * @param file The file to check. + * @return File versioning {@link Type} + */ + Type getVersioningType(@NotNull VirtualFile file); + + /** + * A helper method to check if file's history is managed by the virtual file system extending {@code VersionManagingFileSystem} interface. + * + * @param file The file to check. + * @return True if file's history is managed by the file system. + */ + static boolean isFsSupported(@NotNull VirtualFile file) { + return ObjectUtils.doIfCast(file.getFileSystem(), VersionManagingFileSystem.class, + fs -> fs.getVersioningType(file)) == Type.FILE_SYSTEM; + } + + /** + * A helper method to check if file's history is disabled by the managing file system. + * + * @param file The file to check. + * @return True if file's history is disabled. + */ + static boolean isDisabled(@NotNull VirtualFile file) { + return ObjectUtils.doIfCast(file.getFileSystem(), VersionManagingFileSystem.class, + fs -> fs.getVersioningType(file)) == Type.DISABLED; + } } diff --git a/platform/core-api/src/com/intellij/openapi/vfs/VersionedFileSystem.java b/platform/core-api/src/com/intellij/openapi/vfs/VersionedFileSystem.java deleted file mode 100644 index cd5d6a486904..000000000000 --- a/platform/core-api/src/com/intellij/openapi/vfs/VersionedFileSystem.java +++ /dev/null @@ -1,11 +0,0 @@ -// 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.vfs; - -import org.jetbrains.annotations.ApiStatus; - -/** - * Marker interface for file system to show up in LocalHistory - */ -@ApiStatus.Internal -public interface VersionedFileSystem { -} diff --git a/platform/lvcs-impl/src/com/intellij/history/core/Paths.java b/platform/lvcs-impl/src/com/intellij/history/core/Paths.java index 46e0fff49b73..ae89eb08b078 100644 --- a/platform/lvcs-impl/src/com/intellij/history/core/Paths.java +++ b/platform/lvcs-impl/src/com/intellij/history/core/Paths.java @@ -8,7 +8,7 @@ import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vcs.FilePath; import com.intellij.openapi.vcs.LocalFilePath; import com.intellij.openapi.vcs.UrlFilePath; -import com.intellij.openapi.vfs.VersionedFileSystem; +import com.intellij.openapi.vfs.VersionManagingFileSystem; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.io.URLUtil; @@ -123,7 +123,7 @@ public final class Paths { @NotNull public static FilePath createDvcsFilePath(@NotNull VirtualFile file) { - if (file.getFileSystem() instanceof VersionedFileSystem) { + if (VersionManagingFileSystem.isFsSupported(file)) { return new UrlFilePath(file.getUrl(), file.isDirectory()); } else { diff --git a/platform/lvcs-impl/src/com/intellij/history/integration/IdeaGateway.java b/platform/lvcs-impl/src/com/intellij/history/integration/IdeaGateway.java index ac8a7171b2cd..5e070d629759 100644 --- a/platform/lvcs-impl/src/com/intellij/history/integration/IdeaGateway.java +++ b/platform/lvcs-impl/src/com/intellij/history/integration/IdeaGateway.java @@ -51,12 +51,11 @@ public class IdeaGateway { } public boolean isVersioned(@NotNull VirtualFile f, boolean shouldBeInContent) { - VirtualFileSystem fileSystem = f.getFileSystem(); - if (fileSystem instanceof VersionManagingFileSystem && !((VersionManagingFileSystem)fileSystem).isVersionable(f)) { + if (VersionManagingFileSystem.isDisabled(f)) { return false; } if (!f.isInLocalFileSystem()) { - return isNonLocalVersioned(f); + return VersionManagingFileSystem.isFsSupported(f); } if (!f.isDirectory()) { @@ -96,10 +95,6 @@ public class IdeaGateway { return true; } - public static boolean isNonLocalVersioned(@NotNull VirtualFile f) { - return f.getFileSystem() instanceof VersionedFileSystem; - } - public String getPathOrUrl(@NotNull VirtualFile file) { return file.isInLocalFileSystem() ? file.getPath() : file.getUrl(); } @@ -277,7 +272,7 @@ public class IdeaGateway { List roots = new SmartList<>(); for (VirtualFile root : ManagingFS.getInstance().getRoots()) { - if ((root.isInLocalFileSystem() || isNonLocalVersioned(root)) && !(root.getFileSystem() instanceof TempFileSystem)) { + if ((root.isInLocalFileSystem() || VersionManagingFileSystem.isFsSupported(root)) && !(root.getFileSystem() instanceof TempFileSystem)) { roots.add(root); } } diff --git a/platform/lvcs-impl/src/com/intellij/history/integration/ui/actions/LocalHistoryGroup.java b/platform/lvcs-impl/src/com/intellij/history/integration/ui/actions/LocalHistoryGroup.java index 5a9c87fa2493..bd3df8a3ddf0 100644 --- a/platform/lvcs-impl/src/com/intellij/history/integration/ui/actions/LocalHistoryGroup.java +++ b/platform/lvcs-impl/src/com/intellij/history/integration/ui/actions/LocalHistoryGroup.java @@ -2,13 +2,13 @@ package com.intellij.history.integration.ui.actions; -import com.intellij.history.integration.IdeaGateway; import com.intellij.ide.actions.NonTrivialActionGroup; import com.intellij.openapi.actionSystem.ActionPlaces; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.CommonDataKeys; import com.intellij.openapi.project.DumbAware; import com.intellij.openapi.project.Project; +import com.intellij.openapi.vfs.VersionManagingFileSystem; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiElement; import org.jetbrains.annotations.NotNull; @@ -22,7 +22,7 @@ public class LocalHistoryGroup extends NonTrivialActionGroup implements DumbAwar PsiElement element = e.getData(CommonDataKeys.PSI_ELEMENT); if (project == null || ActionPlaces.isPopupPlace(e.getPlace()) && ( - file != null && !(file.isInLocalFileSystem() || IdeaGateway.isNonLocalVersioned(file)) || file == null && element != null)) { + file != null && !(file.isInLocalFileSystem() || VersionManagingFileSystem.isFsSupported(file)) || file == null && element != null)) { e.getPresentation().setEnabledAndVisible(false); } else {