From 02dc4db01a16d8cacca71e7e9233458acf613c6a Mon Sep 17 00:00:00 2001 From: Konstantin Kolosovsky Date: Sun, 8 Dec 2019 18:47:31 +0300 Subject: [PATCH] vcs: Disallow "Browse Changes" action if corresponding repository location is not found Previously tab with empty title with "Repository" tab functionality was opened (e.g. there was no "Filter" action like in tabs with correct repository location). Looks like such behavior was not intended. GitOrigin-RevId: 0f9737d8326f85b65166b44632655cab142cc835 --- .../openapi/vcs/AbstractVcsHelper.java | 12 +++------ .../changes/actions/BrowseChangesAction.java | 25 ++++++++++++++---- .../committed/CommittedChangesPanel.java | 7 +++-- .../vcs/impl/AbstractVcsHelperImpl.java | 26 +++++++------------ .../tests/git4idea/test/MockVcsHelper.kt | 6 +---- .../zmlx/hg4idea/test/HgMockVcsHelper.java | 8 ++---- 6 files changed, 40 insertions(+), 44 deletions(-) diff --git a/platform/vcs-api/src/com/intellij/openapi/vcs/AbstractVcsHelper.java b/platform/vcs-api/src/com/intellij/openapi/vcs/AbstractVcsHelper.java index 14b7174e0296..643a448a4646 100644 --- a/platform/vcs-api/src/com/intellij/openapi/vcs/AbstractVcsHelper.java +++ b/platform/vcs-api/src/com/intellij/openapi/vcs/AbstractVcsHelper.java @@ -69,17 +69,11 @@ public abstract class AbstractVcsHelper { public abstract void showWhatDiffersBrowser(@Nullable Component parent, Collection changes, @Nls String title); - public abstract void openCommittedChangesTab(AbstractVcs vcs, - VirtualFile root, + public abstract void openCommittedChangesTab(@NotNull CommittedChangesProvider provider, + @NotNull RepositoryLocation location, ChangeBrowserSettings settings, int maxCount, - final String title); - - public abstract void openCommittedChangesTab(CommittedChangesProvider provider, - RepositoryLocation location, - ChangeBrowserSettings settings, - int maxCount, - final String title); + String title); /** * Shows the multiple file merge dialog for resolving conflicts in the specified set of virtual files. diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/BrowseChangesAction.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/BrowseChangesAction.java index b1c432939453..02bf42cff991 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/BrowseChangesAction.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/BrowseChangesAction.java @@ -1,4 +1,4 @@ -// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.openapi.vcs.changes.actions; import com.intellij.openapi.actionSystem.AnAction; @@ -8,13 +8,18 @@ import com.intellij.openapi.actionSystem.Presentation; import com.intellij.openapi.components.ServiceKt; import com.intellij.openapi.project.DumbAware; import com.intellij.openapi.project.Project; +import com.intellij.openapi.ui.MessageType; import com.intellij.openapi.vcs.AbstractVcs; import com.intellij.openapi.vcs.AbstractVcsHelper; import com.intellij.openapi.vcs.CommittedChangesProvider; +import com.intellij.openapi.vcs.RepositoryLocation; +import com.intellij.openapi.vcs.changes.committed.CommittedChangesCache; import com.intellij.openapi.vcs.changes.committed.CommittedChangesFilterDialog; import com.intellij.openapi.vcs.changes.committed.CommittedChangesVisibilityPredicate; +import com.intellij.openapi.vcs.changes.committed.RepositoryLocationCache; import com.intellij.openapi.vcs.versionBrowser.ChangeBrowserSettings; import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.vcsUtil.VcsUtil; import org.jetbrains.annotations.NotNull; import static com.intellij.CommonBundle.getCancelButtonText; @@ -22,6 +27,7 @@ import static com.intellij.openapi.ui.Messages.*; import static com.intellij.openapi.vcs.AbstractVcs.fileInVcsByFileStatus; import static com.intellij.openapi.vcs.VcsBundle.message; import static com.intellij.openapi.vcs.changes.ChangesUtil.getVcsForFile; +import static com.intellij.openapi.vcs.ui.VcsBalloonProblemNotifier.showOverVersionControlView; import static com.intellij.util.ObjectUtils.notNull; public class BrowseChangesAction extends AnAction implements DumbAware { @@ -35,7 +41,7 @@ public class BrowseChangesAction extends AnAction implements DumbAware { CommittedChangesFilterDialog dialog = new CommittedChangesFilterDialog(project, provider.createFilterUI(true), settings); if (dialog.showAndGet()) { - showChanges(vcs, file, settings); + showChanges(vcs, provider, file, settings); } } @@ -69,12 +75,21 @@ public class BrowseChangesAction extends AnAction implements DumbAware { return vcs.allowsRemoteCalls(file) && fileInVcsByFileStatus(project, file); } - private static void showChanges(@NotNull AbstractVcs vcs, @NotNull VirtualFile file, @NotNull ChangeBrowserSettings settings) { + private static void showChanges(@NotNull AbstractVcs vcs, + @NotNull CommittedChangesProvider provider, + @NotNull VirtualFile file, + @NotNull ChangeBrowserSettings settings) { int maxCount = !settings.isAnyFilterSpecified() ? askMaxCount(vcs.getProject()) : 0; + if (maxCount < 0) return; - if (maxCount >= 0) { - AbstractVcsHelper.getInstance(vcs.getProject()).openCommittedChangesTab(vcs, file, settings, maxCount, null); + RepositoryLocationCache cache = CommittedChangesCache.getInstance(vcs.getProject()).getLocationCache(); + RepositoryLocation location = cache.getLocation(vcs, VcsUtil.getFilePath(file), false); + if (location == null) { + showOverVersionControlView(vcs.getProject(), "Repository location not found for " + file.getPresentableUrl(), MessageType.ERROR); + return; } + + AbstractVcsHelper.getInstance(vcs.getProject()).openCommittedChangesTab(provider, location, settings, maxCount, null); } private static int askMaxCount(@NotNull Project project) { diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/CommittedChangesPanel.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/CommittedChangesPanel.java index a898dd766742..7a63944053b6 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/CommittedChangesPanel.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/CommittedChangesPanel.java @@ -48,8 +48,11 @@ public class CommittedChangesPanel extends JPanel implements DataProvider, Dispo private volatile boolean myInLoad; private final Consumer myIfNotCachedReloader; - public CommittedChangesPanel(Project project, final CommittedChangesProvider provider, final ChangeBrowserSettings settings, - @Nullable final RepositoryLocation location, @Nullable ActionGroup extraActions) { + public CommittedChangesPanel(@NotNull Project project, + @NotNull CommittedChangesProvider provider, + ChangeBrowserSettings settings, + @Nullable RepositoryLocation location, + @Nullable ActionGroup extraActions) { super(new BorderLayout()); mySettings = settings; myProject = project; diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/AbstractVcsHelperImpl.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/AbstractVcsHelperImpl.java index 17174abcbdc6..3d90c84b0e05 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/AbstractVcsHelperImpl.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/AbstractVcsHelperImpl.java @@ -35,7 +35,10 @@ import com.intellij.openapi.vcs.annotate.FileAnnotation; import com.intellij.openapi.vcs.changes.Change; import com.intellij.openapi.vcs.changes.CommitResultHandler; import com.intellij.openapi.vcs.changes.LocalChangeList; -import com.intellij.openapi.vcs.changes.committed.*; +import com.intellij.openapi.vcs.changes.committed.ChangesBrowserDialog; +import com.intellij.openapi.vcs.changes.committed.CommittedChangesFilterDialog; +import com.intellij.openapi.vcs.changes.committed.CommittedChangesPanel; +import com.intellij.openapi.vcs.changes.committed.CommittedChangesTableModel; import com.intellij.openapi.vcs.changes.ui.*; import com.intellij.openapi.vcs.history.FileHistoryRefresher; import com.intellij.openapi.vcs.history.FileHistoryRefresherI; @@ -472,28 +475,17 @@ public class AbstractVcsHelperImpl extends AbstractVcsHelper { } @Override - public void openCommittedChangesTab(final AbstractVcs vcs, - final VirtualFile root, - final ChangeBrowserSettings settings, - final int maxCount, - String title) { - RepositoryLocationCache cache = CommittedChangesCache.getInstance(myProject).getLocationCache(); - RepositoryLocation location = cache.getLocation(vcs, VcsUtil.getFilePath(root), false); - openCommittedChangesTab(vcs.getCommittedChangesProvider(), location, settings, maxCount, title); - } - - @Override - public void openCommittedChangesTab(final CommittedChangesProvider provider, - final RepositoryLocation location, - final ChangeBrowserSettings settings, - final int maxCount, + public void openCommittedChangesTab(@NotNull CommittedChangesProvider provider, + @NotNull RepositoryLocation location, + ChangeBrowserSettings settings, + int maxCount, String title) { DefaultActionGroup extraActions = new DefaultActionGroup(); CommittedChangesPanel panel = new CommittedChangesPanel(myProject, provider, settings, location, extraActions); panel.setMaxCount(maxCount); panel.refreshChanges(false); final ContentFactory factory = ContentFactory.SERVICE.getInstance(); - if (title == null && location != null) { + if (title == null) { title = VcsBundle.message("browse.changes.content.title", location.toPresentableString()); } final Content content = factory.createContent(panel, title, false); diff --git a/plugins/git4idea/tests/git4idea/test/MockVcsHelper.kt b/plugins/git4idea/tests/git4idea/test/MockVcsHelper.kt index 5cf13c7fca4f..32958967ccbf 100644 --- a/plugins/git4idea/tests/git4idea/test/MockVcsHelper.kt +++ b/plugins/git4idea/tests/git4idea/test/MockVcsHelper.kt @@ -40,11 +40,7 @@ class MockVcsHelper(project: Project) : AbstractVcsHelper(project) { throw UnsupportedOperationException() } - override fun openCommittedChangesTab(vcs: AbstractVcs?, root: VirtualFile?, settings: ChangeBrowserSettings?, maxCount: Int, title: String?) { - throw UnsupportedOperationException() - } - - override fun openCommittedChangesTab(provider: CommittedChangesProvider<*, *>?, location: RepositoryLocation?, settings: ChangeBrowserSettings?, maxCount: Int, title: String?) { + override fun openCommittedChangesTab(provider: CommittedChangesProvider<*, *>, location: RepositoryLocation, settings: ChangeBrowserSettings?, maxCount: Int, title: String?) { throw UnsupportedOperationException() } diff --git a/plugins/hg4idea/testSrc/org/zmlx/hg4idea/test/HgMockVcsHelper.java b/plugins/hg4idea/testSrc/org/zmlx/hg4idea/test/HgMockVcsHelper.java index ec5321cd9f81..c682e7d93431 100644 --- a/plugins/hg4idea/testSrc/org/zmlx/hg4idea/test/HgMockVcsHelper.java +++ b/plugins/hg4idea/testSrc/org/zmlx/hg4idea/test/HgMockVcsHelper.java @@ -78,12 +78,8 @@ public class HgMockVcsHelper extends AbstractVcsHelper { } @Override - public void openCommittedChangesTab(AbstractVcs vcs, VirtualFile root, ChangeBrowserSettings settings, int maxCount, String title) { - } - - @Override - public void openCommittedChangesTab(CommittedChangesProvider provider, - RepositoryLocation location, + public void openCommittedChangesTab(@NotNull CommittedChangesProvider provider, + @NotNull RepositoryLocation location, ChangeBrowserSettings settings, int maxCount, String title) {