From 6412fe2de02ca164edf544eb15c89d6b0547f006 Mon Sep 17 00:00:00 2001 From: Alexandr Evstigneev Date: Mon, 13 Feb 2017 12:37:39 +0300 Subject: [PATCH] adjusted addFilesToVcsWithConfirmation according to IDEA-CR-18124 - Method is now synchronous - Got rid of redundant (for now) exceptionsProcessor - Threading is now more straightforward (recommended to execute on pooled thread) --- .../src/com/intellij/vcsUtil/VcsFileUtil.java | 69 +++++++------------ 1 file changed, 26 insertions(+), 43 deletions(-) diff --git a/platform/vcs-impl/src/com/intellij/vcsUtil/VcsFileUtil.java b/platform/vcs-impl/src/com/intellij/vcsUtil/VcsFileUtil.java index d8848fbb51a8..98461e6818ca 100644 --- a/platform/vcs-impl/src/com/intellij/vcsUtil/VcsFileUtil.java +++ b/platform/vcs-impl/src/com/intellij/vcsUtil/VcsFileUtil.java @@ -21,6 +21,7 @@ import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.progress.ProgressManager; import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.Ref; import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.util.ThrowableNotNullFunction; import com.intellij.openapi.util.io.FileUtil; @@ -388,21 +389,16 @@ public class VcsFileUtil { addFilesToVcsWithConfirmation(project, Arrays.asList(virtualFiles)); } - public static void addFilesToVcsWithConfirmation(@NotNull Project project, @NotNull Collection virtualFiles) { - addFilesToVcsWithConfirmation(project, virtualFiles, null); - } - /** * Finds all VCSs related to the passed files, suggests user to add files to the respected VCSs honoring addition and silence settings - * and adds them if user or settings confirmed addition + * and adds them if user or settings confirmed addition. Because of potentially long operation of collecting files it's highly recommended + * to invoke it on the pooled thread. Method works synchronously. * - * @param project project we work in - * @param virtualFiles collection of virtual files to add; directories being added recursively - * @param exceptionsProcessor optional exceptions processor + * @param project project we work in + * @param virtualFiles collection of virtual files to add; directories being added recursively */ public static void addFilesToVcsWithConfirmation(@NotNull Project project, - @NotNull Collection virtualFiles, - @Nullable VcsExceptionsProcessor exceptionsProcessor) { + @NotNull Collection virtualFiles) { if (virtualFiles.isEmpty()) { return; } @@ -422,49 +418,36 @@ public class VcsFileUtil { if (addOption.getValue() == VcsShowConfirmationOption.Value.DO_NOTHING_SILENTLY) return; List filesList = new ArrayList<>(vcsMap.get(vcs)); if (addOption.getValue() == VcsShowConfirmationOption.Value.DO_ACTION_SILENTLY) { - performAdding(vcs, filesList, exceptionsProcessor); + performAdditions(vcs, filesList); } else { AbstractVcsHelper helper = AbstractVcsHelper.getInstance(project); - ApplicationManager.getApplication().invokeLater(() -> { - Collection filesToAdd = - helper - .selectFilesToProcess( - new ArrayList<>(filesList), - VcsBundle.message("confirmation.title.add.files.to", vcs.getDisplayName()), - null, - VcsBundle.message("confirmation.title.add.file.to", vcs.getDisplayName()), - null, - addOption); + Ref> filesToAdd = Ref.create(); - if (filesToAdd != null) { - ApplicationManager.getApplication().executeOnPooledThread(() -> { - performAdding(vcs, new ArrayList<>(filesToAdd), exceptionsProcessor); - }); - } - }); + ApplicationManager.getApplication().invokeAndWait(() -> filesToAdd.set( + helper + .selectFilesToProcess( + new ArrayList<>(filesList), + VcsBundle.message("confirmation.title.add.files.to", vcs.getDisplayName()), + null, + VcsBundle.message("confirmation.title.add.file.to", vcs.getDisplayName()), + null, + addOption)) + ); + + if (!filesToAdd.isNull()) { + performAdditions(vcs, new ArrayList<>(filesToAdd.get())); + } } } } - private static void performAdding(@NotNull AbstractVcs vcs, - @NotNull List value, - @Nullable VcsExceptionsProcessor exceptionsProcessor) { + private static void performAdditions(@NotNull AbstractVcs vcs, + @NotNull List value) { CheckinEnvironment checkinEnvironment = vcs.getCheckinEnvironment(); - if (checkinEnvironment == null) { - return; + if (checkinEnvironment != null) { + checkinEnvironment.scheduleUnversionedFilesForAddition(value); } - List exceptions = checkinEnvironment.scheduleUnversionedFilesForAddition(value); - if (exceptions == null || exceptionsProcessor == null) { - return; - } - for (VcsException exception : exceptions) { - exceptionsProcessor.process(vcs, exception); - } - } - - public interface VcsExceptionsProcessor { - void process(@NotNull AbstractVcs vcs, @NotNull VcsException exception); } }