[downburst] IJ-CR-104248 review changes

GitOrigin-RevId: 24e82e0ef4fe48541d3f6dbb94864f0c48e62850
This commit is contained in:
Rustam Vishniakov
2023-03-09 14:17:07 +01:00
committed by intellij-monorepo-bot
parent 0a7659bfd1
commit 5bcbeb9e93
5 changed files with 56 additions and 32 deletions

View File

@@ -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;
}
}

View File

@@ -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 {
}

View File

@@ -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 {

View File

@@ -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<VirtualFile> 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);
}
}

View File

@@ -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 {