IJPL-158659 vcs: fix missing readAction in GitToolbarWidgetAction

GitOrigin-RevId: ffeb82824c1115830a908fbf57a3616713564394
This commit is contained in:
Aleksey Pivovarov
2024-09-24 13:50:53 +02:00
committed by intellij-monorepo-bot
parent 0112a2d9c9
commit 1a89d14b2a

View File

@@ -11,6 +11,7 @@ import com.intellij.ide.file.BatchFileChangeListener;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.actionSystem.impl.SimpleDataContext;
import com.intellij.openapi.application.AccessToken;
import com.intellij.openapi.application.ReadAction;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.fileEditor.FileEditor;
import com.intellij.openapi.fileEditor.FileEditorManager;
@@ -477,18 +478,7 @@ public final class DvcsUtil {
return root;
}
// For libraries, check VCS for the owner module
List<OrderEntry> entries = ProjectRootManager.getInstance(project).getFileIndex().getOrderEntriesForFile(file);
Set<VirtualFile> modulesVcsRoots = new HashSet<>();
for (OrderEntry entry : entries) {
if (entry instanceof LibraryOrderEntry || entry instanceof JdkOrderEntry) {
VirtualFile moduleVcsRoot = vcsManager.getVcsRootFor(entry.getOwnerModule().getModuleFile());
if (moduleVcsRoot != null) {
modulesVcsRoots.add(moduleVcsRoot);
}
}
}
Set<VirtualFile> modulesVcsRoots = ReadAction.compute(() -> findVcsRootForModuleLibrary(project, file));
if (modulesVcsRoots.isEmpty()) {
LOG.debug("No library roots");
return null;
@@ -506,6 +496,25 @@ public final class DvcsUtil {
return topRoot;
}
/**
* IJPL-95268 For libraries, check VCS for the owner module
*/
private static Set<VirtualFile> findVcsRootForModuleLibrary(@NotNull Project project, @NotNull VirtualFile file) {
ProjectLevelVcsManager vcsManager = ProjectLevelVcsManager.getInstance(project);
List<OrderEntry> entries = ProjectRootManager.getInstance(project).getFileIndex().getOrderEntriesForFile(file);
Set<VirtualFile> modulesVcsRoots = new HashSet<>();
for (OrderEntry entry : entries) {
if (entry instanceof LibraryOrderEntry || entry instanceof JdkOrderEntry) {
VirtualFile moduleVcsRoot = vcsManager.getVcsRootFor(entry.getOwnerModule().getModuleFile());
if (moduleVcsRoot != null) {
modulesVcsRoots.add(moduleVcsRoot);
}
}
}
return modulesVcsRoots;
}
/**
* @deprecated Prefer {@link #findVcsRootFor}, {@link #guessWidgetRepository} or {@link #guessRepositoryForOperation}.
*/