From 1a89d14b2aa9bbc9f393b7b53849a8d68dc64262 Mon Sep 17 00:00:00 2001 From: Aleksey Pivovarov Date: Tue, 24 Sep 2024 13:50:53 +0200 Subject: [PATCH] IJPL-158659 vcs: fix missing readAction in GitToolbarWidgetAction GitOrigin-RevId: ffeb82824c1115830a908fbf57a3616713564394 --- .../src/com/intellij/dvcs/DvcsUtil.java | 33 ++++++++++++------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/platform/dvcs-impl/src/com/intellij/dvcs/DvcsUtil.java b/platform/dvcs-impl/src/com/intellij/dvcs/DvcsUtil.java index 3fff51b0ce86..5631f5e9a393 100644 --- a/platform/dvcs-impl/src/com/intellij/dvcs/DvcsUtil.java +++ b/platform/dvcs-impl/src/com/intellij/dvcs/DvcsUtil.java @@ -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 entries = ProjectRootManager.getInstance(project).getFileIndex().getOrderEntriesForFile(file); - Set 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 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 findVcsRootForModuleLibrary(@NotNull Project project, @NotNull VirtualFile file) { + ProjectLevelVcsManager vcsManager = ProjectLevelVcsManager.getInstance(project); + + List entries = ProjectRootManager.getInstance(project).getFileIndex().getOrderEntriesForFile(file); + Set 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}. */