[vcs] Move "Show Affected Revisions" implementation to vcs-impl & fix it from annotat...
authorKirill Likhodedov <Kirill.Likhodedov@gmail.com>
Wed, 19 Aug 2015 16:07:20 +0000 (19:07 +0300)
committerAleksey Pivovarov <AMPivovarov@gmail.com>
Thu, 3 Sep 2015 16:28:13 +0000 (19:28 +0300)
platform/vcs-api/src/com/intellij/openapi/vcs/AbstractVcsHelper.java
platform/vcs-api/src/com/intellij/openapi/vcs/annotate/ShowAllAffectedGenericAction.java
platform/vcs-impl/src/com/intellij/openapi/vcs/history/FileHistoryPanelImpl.java
platform/vcs-impl/src/com/intellij/openapi/vcs/impl/AbstractVcsHelperImpl.java
plugins/git4idea/tests/git4idea/test/MockVcsHelper.java
plugins/hg4idea/testSrc/org/zmlx/hg4idea/test/HgMockVcsHelper.java

index 0a78568d1cae8d109eac559d5b7714721373fc97..be697393381adff3548aa1fb836bae315137db6a 100644 (file)
@@ -25,6 +25,7 @@ import com.intellij.openapi.vcs.changes.CommitResultHandler;
 import com.intellij.openapi.vcs.changes.LocalChangeList;
 import com.intellij.openapi.vcs.history.VcsFileRevision;
 import com.intellij.openapi.vcs.history.VcsHistoryProvider;
+import com.intellij.openapi.vcs.history.VcsRevisionNumber;
 import com.intellij.openapi.vcs.merge.MergeDialogCustomizer;
 import com.intellij.openapi.vcs.merge.MergeProvider;
 import com.intellij.openapi.vcs.versionBrowser.ChangeBrowserSettings;
@@ -201,4 +202,12 @@ public abstract class AbstractVcsHelper {
    */
   public abstract boolean commitChanges(@NotNull Collection<Change> changes, @NotNull LocalChangeList initialChangeList,
                                @NotNull String commitMessage, @Nullable CommitResultHandler customResultHandler);
+
+  public abstract void loadAndShowCommittedChangesDetails(@NotNull Project project,
+                                                          @NotNull VcsRevisionNumber revision,
+                                                          @NotNull VirtualFile file,
+                                                          @NotNull VcsKey key,
+                                                          @Nullable RepositoryLocation location,
+                                                          boolean local);
+
 }
index b707b664f7bf28ce10ab9a28b847e4ed651c46f9..cdf05959e3796319477ad627a13ae526644dcf22 100644 (file)
@@ -19,26 +19,14 @@ import com.intellij.openapi.actionSystem.ActionManager;
 import com.intellij.openapi.actionSystem.AnAction;
 import com.intellij.openapi.actionSystem.AnActionEvent;
 import com.intellij.openapi.actionSystem.CommonDataKeys;
-import com.intellij.openapi.progress.ProgressIndicator;
-import com.intellij.openapi.progress.ProgressManager;
-import com.intellij.openapi.progress.Task;
 import com.intellij.openapi.project.DumbAware;
 import com.intellij.openapi.project.Project;
-import com.intellij.openapi.ui.Messages;
-import com.intellij.openapi.util.Pair;
 import com.intellij.openapi.vcs.*;
-import com.intellij.openapi.vcs.changes.BackgroundFromStartOption;
-import com.intellij.openapi.vcs.history.ShortVcsRevisionNumber;
 import com.intellij.openapi.vcs.history.VcsFileRevision;
 import com.intellij.openapi.vcs.history.VcsRevisionNumber;
-import com.intellij.openapi.vcs.versionBrowser.ChangeBrowserSettings;
-import com.intellij.openapi.vcs.versionBrowser.CommittedChangeList;
-import com.intellij.openapi.vcs.vfs.VcsFileSystem;
-import com.intellij.openapi.vcs.vfs.VcsVirtualFile;
 import com.intellij.openapi.vfs.VirtualFile;
 import org.jetbrains.annotations.NotNull;
-
-import java.util.List;
+import org.jetbrains.annotations.Nullable;
 
 /**
  * @author irengrig
@@ -72,110 +60,20 @@ public class ShowAllAffectedGenericAction extends AnAction implements DumbAware
     }
   }
 
-  public static void showSubmittedFiles(final Project project, final VcsRevisionNumber revision, final VirtualFile virtualFile, final VcsKey vcsKey) {
+  public static void showSubmittedFiles(@NotNull Project project,
+                                        @NotNull VcsRevisionNumber revision,
+                                        @NotNull VirtualFile virtualFile,
+                                        @NotNull VcsKey vcsKey) {
     showSubmittedFiles(project, revision, virtualFile, vcsKey, null, false);
   }
 
-  public static void showSubmittedFiles(final Project project, final VcsRevisionNumber revision, final VirtualFile virtualFile,
-                                         final VcsKey vcsKey, final RepositoryLocation location, final boolean isNonLocal) {
-    final AbstractVcs vcs = ProjectLevelVcsManager.getInstance(project).findVcsByName(vcsKey.getName());
-    if (vcs == null) return;
-    if (isNonLocal && ! canPresentNonLocal(project, vcsKey, virtualFile)) return;
-
-    final String title = VcsBundle.message("paths.affected.in.revision",
-                                           revision instanceof ShortVcsRevisionNumber
-                                               ? ((ShortVcsRevisionNumber) revision).toShortString()
-                                               :  revision.asString());
-    final CommittedChangeList[] list = new CommittedChangeList[1];
-    final FilePath[] targetPath = new FilePath[1];
-    final VcsException[] exc = new VcsException[1];
-    Task.Backgroundable task = new Task.Backgroundable(project, title, true, BackgroundFromStartOption.getInstance()) {
-      @Override
-      public void run(@NotNull ProgressIndicator indicator) {
-        try {
-          final CommittedChangesProvider provider = vcs.getCommittedChangesProvider();
-          if (!isNonLocal) {
-            final Pair<CommittedChangeList, FilePath> pair = provider.getOneList(virtualFile, revision);
-            if (pair != null) {
-              list[0] = pair.getFirst();
-              targetPath[0] = pair.getSecond();
-            }
-          }
-          else {
-            if (location != null) {
-              final ChangeBrowserSettings settings = provider.createDefaultSettings();
-              settings.USE_CHANGE_BEFORE_FILTER = true;
-              settings.CHANGE_BEFORE = revision.asString();
-              final List<CommittedChangeList> changes = provider.getCommittedChanges(settings, location, 1);
-              if (changes != null && changes.size() == 1) {
-                list[0] = changes.get(0);
-              }
-              return;
-            }
-            else {
-              list[0] = getRemoteList(vcs, revision, virtualFile);
-              /*final RepositoryLocation local = provider.getForNonLocal(virtualFile);
-              if (local != null) {
-                final String number = revision.asString();
-                final ChangeBrowserSettings settings = provider.createDefaultSettings();
-                final List<CommittedChangeList> changes = provider.getCommittedChanges(settings, local, provider.getUnlimitedCountValue());
-                if (changes != null) {
-                  for (CommittedChangeList change : changes) {
-                    if (number.equals(String.valueOf(change.getNumber()))) {
-                      list[0] = change;
-                    }
-                  }
-                }
-              } */
-            }
-          }
-        }
-        catch (VcsException e) {
-          exc[0] = e;
-        }
-      }
-
-      @Override
-      public void onSuccess() {
-        final AbstractVcsHelper instance = AbstractVcsHelper.getInstance(project);
-        if (exc[0] != null) {
-          instance.showError(exc[0], failedText(virtualFile, revision));
-        }
-        else if (list[0] == null) {
-          Messages.showErrorDialog(project, failedText(virtualFile, revision), getTitle());
-        }
-        else {
-          VirtualFile navigateToFile = targetPath[0] != null ?
-                                       new VcsVirtualFile(targetPath[0].getPath(), null, VcsFileSystem.getInstance()) :
-                                       virtualFile;
-          instance.showChangesListBrowser(list[0], navigateToFile, title);
-        }
-      }
-    };
-    ProgressManager.getInstance().run(task);
-  }
-
-  public static CommittedChangeList getRemoteList(final AbstractVcs vcs, final VcsRevisionNumber revision, final VirtualFile nonLocal)
-    throws VcsException {
-    final CommittedChangesProvider provider = vcs.getCommittedChangesProvider();
-    final RepositoryLocation local = provider.getForNonLocal(nonLocal);
-    if (local != null) {
-      final String number = revision.asString();
-      final ChangeBrowserSettings settings = provider.createDefaultSettings();
-      final List<CommittedChangeList> changes = provider.getCommittedChanges(settings, local, provider.getUnlimitedCountValue());
-      if (changes != null) {
-        for (CommittedChangeList change : changes) {
-          if (number.equals(String.valueOf(change.getNumber()))) {
-            return change;
-          }
-        }
-      }
-    }
-    return null;
-  }
-
-  private static String failedText(VirtualFile virtualFile, VcsRevisionNumber revision) {
-    return "Show all affected files for " + virtualFile.getPath() + " at " + revision.asString() + " failed";
+  public static void showSubmittedFiles(@NotNull Project project,
+                                        @NotNull VcsRevisionNumber revision,
+                                        @NotNull VirtualFile virtualFile,
+                                        @NotNull VcsKey vcsKey,
+                                        @Nullable RepositoryLocation location,
+                                        boolean isNonLocal) {
+    AbstractVcsHelper.getInstance(project).loadAndShowCommittedChangesDetails(project, revision, virtualFile, vcsKey, location, isNonLocal);
   }
 
   @Override
index de5439334909cd4bd660717789ac470fb243913f..be86d5960ff8403c376092c4072902ca69967d71 100644 (file)
@@ -47,13 +47,13 @@ import com.intellij.openapi.util.text.StringUtil;
 import com.intellij.openapi.vcs.*;
 import com.intellij.openapi.vcs.actions.AnnotateRevisionActionBase;
 import com.intellij.openapi.vcs.annotate.AnnotationProvider;
-import com.intellij.openapi.vcs.annotate.ShowAllAffectedGenericAction;
 import com.intellij.openapi.vcs.changes.*;
 import com.intellij.openapi.vcs.changes.actions.CreatePatchFromChangesAction;
 import com.intellij.openapi.vcs.changes.committed.AbstractCalledLater;
 import com.intellij.openapi.vcs.changes.issueLinks.IssueLinkHtmlRenderer;
 import com.intellij.openapi.vcs.changes.issueLinks.IssueLinkRenderer;
 import com.intellij.openapi.vcs.changes.issueLinks.TableLinkMouseListener;
+import com.intellij.openapi.vcs.impl.AbstractVcsHelperImpl;
 import com.intellij.openapi.vcs.ui.ReplaceFileConfirmationDialog;
 import com.intellij.openapi.vcs.versionBrowser.CommittedChangeList;
 import com.intellij.openapi.vcs.vfs.VcsFileSystem;
@@ -1685,7 +1685,7 @@ public class FileHistoryPanelImpl extends PanelWithActionsAndCloseButton {
       final VcsVirtualFile vf =
         new VcsVirtualFile(changedRepositoryPath.toPresentableString(), myRevision.getRevision(), VcsFileSystem.getInstance());
       try {
-        myList = ShowAllAffectedGenericAction.getRemoteList(myVcs, myRevision.getRevisionNumber(), vf);
+        myList = AbstractVcsHelperImpl.getRemoteList(myVcs, myRevision.getRevisionNumber(), vf);
         //myList = provider.getOneList(vf, myRevision.getRevisionNumber());
       }
       catch (VcsException e1) {
index 5fdd6c6bcb089dfef7c3adca872f38574bd43862..c94ac4c2f29443ae5eea7a8dbf84d780db0bf8a1 100644 (file)
@@ -33,15 +33,18 @@ import com.intellij.openapi.fileEditor.FileEditorManager;
 import com.intellij.openapi.fileEditor.OpenFileDescriptor;
 import com.intellij.openapi.fileTypes.FileType;
 import com.intellij.openapi.fileTypes.FileTypeManager;
+import com.intellij.openapi.progress.EmptyProgressIndicator;
 import com.intellij.openapi.progress.ProgressIndicator;
 import com.intellij.openapi.progress.ProgressManager;
 import com.intellij.openapi.progress.Task;
+import com.intellij.openapi.progress.impl.CoreProgressManager;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.ui.DialogWrapper;
 import com.intellij.openapi.ui.Messages;
 import com.intellij.openapi.util.Comparing;
 import com.intellij.openapi.util.Disposer;
 import com.intellij.openapi.util.Getter;
+import com.intellij.openapi.util.Pair;
 import com.intellij.openapi.util.text.StringUtil;
 import com.intellij.openapi.vcs.*;
 import com.intellij.openapi.vcs.actions.AnnotateToggleAction;
@@ -60,6 +63,8 @@ import com.intellij.openapi.vcs.merge.MultipleFileMergeDialog;
 import com.intellij.openapi.vcs.versionBrowser.ChangeBrowserSettings;
 import com.intellij.openapi.vcs.versionBrowser.ChangesBrowserSettingsEditor;
 import com.intellij.openapi.vcs.versionBrowser.CommittedChangeList;
+import com.intellij.openapi.vcs.vfs.VcsFileSystem;
+import com.intellij.openapi.vcs.vfs.VcsVirtualFile;
 import com.intellij.openapi.vfs.LocalFileSystem;
 import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.openapi.wm.ToolWindow;
@@ -640,6 +645,105 @@ public class AbstractVcsHelperImpl extends AbstractVcsHelper {
     }
   }
 
+  @Override
+  public void loadAndShowCommittedChangesDetails(@NotNull final Project project,
+                                                 @NotNull final VcsRevisionNumber revision,
+                                                 @NotNull final VirtualFile virtualFile,
+                                                 @NotNull VcsKey vcsKey,
+                                                 @Nullable final RepositoryLocation location,
+                                                 final boolean isNonLocal) {
+    final AbstractVcs vcs = ProjectLevelVcsManager.getInstance(project).findVcsByName(vcsKey.getName());
+    if (vcs == null) return;
+    final CommittedChangesProvider provider = vcs.getCommittedChangesProvider();
+    if (provider == null) return;
+    if (isNonLocal && provider.getForNonLocal(virtualFile) == null) return;
+
+    final String title = VcsBundle.message("paths.affected.in.revision",
+                                           revision instanceof ShortVcsRevisionNumber
+                                           ? ((ShortVcsRevisionNumber)revision).toShortString()
+                                           : revision.asString());
+    final CommittedChangeList[] list = new CommittedChangeList[1];
+    final FilePath[] targetPath = new FilePath[1];
+    final VcsException[] exc = new VcsException[1];
+    Task.Backgroundable task = new Task.Backgroundable(project, title, true, BackgroundFromStartOption.getInstance()) {
+      @Override
+      public void run(@NotNull ProgressIndicator indicator) {
+        try {
+          if (!isNonLocal) {
+            final Pair<CommittedChangeList, FilePath> pair = provider.getOneList(virtualFile, revision);
+            if (pair != null) {
+              list[0] = pair.getFirst();
+              targetPath[0] = pair.getSecond();
+            }
+          }
+          else {
+            if (location != null) {
+              final ChangeBrowserSettings settings = provider.createDefaultSettings();
+              settings.USE_CHANGE_BEFORE_FILTER = true;
+              settings.CHANGE_BEFORE = revision.asString();
+              final List<CommittedChangeList> changes = provider.getCommittedChanges(settings, location, 1);
+              if (changes != null && changes.size() == 1) {
+                list[0] = changes.get(0);
+              }
+            }
+            else {
+              list[0] = getRemoteList(vcs, revision, virtualFile);
+            }
+          }
+        }
+        catch (VcsException e) {
+          exc[0] = e;
+        }
+      }
+
+      @Override
+      public void onSuccess() {
+        if (exc[0] != null) {
+          showError(exc[0], failedText(virtualFile, revision));
+        }
+        else if (list[0] == null) {
+          Messages.showErrorDialog(project, failedText(virtualFile, revision), getTitle());
+        }
+        else {
+          VirtualFile navigateToFile = targetPath[0] != null ?
+                                       new VcsVirtualFile(targetPath[0].getPath(), null, VcsFileSystem.getInstance()) :
+                                       virtualFile;
+          showChangesListBrowser(list[0], navigateToFile, title);
+        }
+      }
+    };
+
+    CoreProgressManager progressManager = (CoreProgressManager)ProgressManager.getInstance();
+    progressManager.runProcessWithProgressAsynchronously(task, new EmptyProgressIndicator(), null, ModalityState.current());
+  }
+
+  @Nullable
+  public static CommittedChangeList getRemoteList(@NotNull AbstractVcs vcs,
+                                                  @NotNull VcsRevisionNumber revision,
+                                                  @NotNull VirtualFile nonLocal)
+    throws VcsException {
+    final CommittedChangesProvider provider = vcs.getCommittedChangesProvider();
+    final RepositoryLocation local = provider.getForNonLocal(nonLocal);
+    if (local != null) {
+      final String number = revision.asString();
+      final ChangeBrowserSettings settings = provider.createDefaultSettings();
+      final List<CommittedChangeList> changes = provider.getCommittedChanges(settings, local, provider.getUnlimitedCountValue());
+      if (changes != null) {
+        for (CommittedChangeList change : changes) {
+          if (number.equals(String.valueOf(change.getNumber()))) {
+            return change;
+          }
+        }
+      }
+    }
+    return null;
+  }
+
+  @NotNull
+  private static String failedText(@NotNull VirtualFile virtualFile, @NotNull VcsRevisionNumber revision) {
+    return "Show all affected files for " + virtualFile.getPath() + " at " + revision.asString() + " failed";
+  }
+
   private static class AsynchronousListsLoader extends Task.Backgroundable {
     private final CommittedChangesProvider myProvider;
     private final RepositoryLocation myLocation;
index a9dba170ae05df95df02e8efce99f45d6b314a84..15bc061c7d29bbfb6a2a8091e60a102a39615a6e 100644 (file)
@@ -25,6 +25,7 @@ import com.intellij.openapi.vcs.changes.CommitResultHandler;
 import com.intellij.openapi.vcs.changes.LocalChangeList;
 import com.intellij.openapi.vcs.history.VcsFileRevision;
 import com.intellij.openapi.vcs.history.VcsHistoryProvider;
+import com.intellij.openapi.vcs.history.VcsRevisionNumber;
 import com.intellij.openapi.vcs.merge.MergeDialogCustomizer;
 import com.intellij.openapi.vcs.merge.MergeProvider;
 import com.intellij.openapi.vcs.versionBrowser.ChangeBrowserSettings;
@@ -227,4 +228,12 @@ public class MockVcsHelper extends AbstractVcsHelper {
     void showMergeDialog();
   }
 
+  @Override
+  public void loadAndShowCommittedChangesDetails(@NotNull Project project,
+                                                 @NotNull VcsRevisionNumber revision,
+                                                 @NotNull VirtualFile file,
+                                                 @NotNull VcsKey key,
+                                                 @Nullable RepositoryLocation location,
+                                                 boolean local) {
+  }
 }
index 30281fce8f809656a85bf860aeb8a516a8d9acd1..9240ba9edf9f70c241094220bbc9c2c180e901a0 100644 (file)
@@ -25,6 +25,7 @@ import com.intellij.openapi.vcs.changes.CommitResultHandler;
 import com.intellij.openapi.vcs.changes.LocalChangeList;
 import com.intellij.openapi.vcs.history.VcsFileRevision;
 import com.intellij.openapi.vcs.history.VcsHistoryProvider;
+import com.intellij.openapi.vcs.history.VcsRevisionNumber;
 import com.intellij.openapi.vcs.merge.MergeDialogCustomizer;
 import com.intellij.openapi.vcs.merge.MergeProvider;
 import com.intellij.openapi.vcs.versionBrowser.ChangeBrowserSettings;
@@ -173,6 +174,16 @@ public class HgMockVcsHelper extends AbstractVcsHelper {
     throw new UnsupportedOperationException();
   }
 
+  @Override
+  public void loadAndShowCommittedChangesDetails(@NotNull Project project,
+                                                 @NotNull VcsRevisionNumber revision,
+                                                 @NotNull VirtualFile file,
+                                                 @NotNull VcsKey key,
+                                                 @Nullable RepositoryLocation location,
+                                                 boolean local) {
+
+  }
+
   public void addListener(VcsHelperListener listener) {
     myListeners.add(listener);
   }