diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/HgVFSListener.java b/plugins/hg4idea/src/org/zmlx/hg4idea/HgVFSListener.java index 143d6d135350..fd14558b21c9 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/HgVFSListener.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/HgVFSListener.java @@ -181,13 +181,13 @@ public class HgVFSListener extends VcsVFSListener { // add for all files at once if (!adds.isEmpty()) { - new HgAddCommand(myProject).execute(adds); + new HgAddCommand(myProject).executeInCurrentThread(adds); } // copy needs to be run for each file separately if (!copies.isEmpty()) { - for(Map.Entry copy : copies.entrySet()) { - new HgCopyCommand(myProject).execute(copy.getKey(), copy.getValue()); + for (Map.Entry copy : copies.entrySet()) { + new HgCopyCommand(myProject).executeInCurrentThread(copy.getKey(), copy.getValue()); } } diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgAddCommand.java b/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgAddCommand.java index 251fe65d4ae2..2839fbe5716b 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgAddCommand.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgAddCommand.java @@ -40,47 +40,54 @@ public class HgAddCommand { /** * Adds given files to their Mercurial repositories. - * @param hgFiles files to be added. + * @param files files to be added. */ - public void execute(@NotNull Collection files) { - execute(files, null); + public void executeInCurrentThread(@NotNull Collection files) { + executeInCurrentThread(files, null); } public void addWithProgress(final Collection files) { if (files.size() >= HgUtil.MANY_FILES) { - new Task.Backgroundable(myProject, "Adding files to Mercurial", true) { - @Override public void run(@NotNull ProgressIndicator indicator) { + new Task.Backgroundable(myProject, "Adding Files to Mercurial", true) { + @Override + public void run(@NotNull ProgressIndicator indicator) { indicator.setIndeterminate(false); - execute(files, indicator); + executeInCurrentThread(files, indicator); } }.queue(); - } else { + } + else { ApplicationManager.getApplication().executeOnPooledThread(new Runnable() { - @Override public void run() { - execute(files); + @Override + public void run() { + executeInCurrentThread(files); } }); } } - private void execute(@NotNull Collection files, @Nullable ProgressIndicator indicator) { + private void executeInCurrentThread(@NotNull Collection files, @Nullable ProgressIndicator indicator) { final Map> sorted = HgUtil.sortByHgRoots(myProject, files); for (Map.Entry> entry : sorted.entrySet()) { if (indicator != null) { - if (indicator.isCanceled()) { return; } + if (indicator.isCanceled()) { + return; + } indicator.setFraction(0); indicator.setText2("Adding files to " + entry.getKey().getPresentableUrl()); } - addFiles(entry.getKey(), entry.getValue(), indicator); + addFilesSynchronously(entry.getKey(), entry.getValue(), indicator); } } - private void addFiles(VirtualFile repo, Collection files, @Nullable ProgressIndicator indicator) { + private void addFilesSynchronously(VirtualFile repo, Collection files, @Nullable ProgressIndicator indicator) { final List> chunks = VcsFileUtil.chunkFiles(repo, files); int currentChunk = 0; for (List paths : chunks) { if (indicator != null) { - if (indicator.isCanceled()) { return; } + if (indicator.isCanceled()) { + return; + } indicator.setFraction((double)currentChunk / chunks.size()); currentChunk++; } diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgCopyCommand.java b/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgCopyCommand.java index 8841179d171a..a20a243b93de 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgCopyCommand.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgCopyCommand.java @@ -29,20 +29,20 @@ public class HgCopyCommand { myProject = project; } - public void execute(VirtualFile source, VirtualFile target) { + public void executeInCurrentThread(VirtualFile source, VirtualFile target) { VirtualFile sourceRepo = VcsUtil.getVcsRootFor(myProject, source); VirtualFile targetRepo = VcsUtil.getVcsRootFor(myProject, target); HgCommandExecutor executor = new HgCommandExecutor(myProject, VcsFileUtil.relativeOrFullPath(sourceRepo, source)); if (sourceRepo != null && targetRepo != null && sourceRepo.equals(targetRepo)) { - executor.execute(sourceRepo, "copy", Arrays.asList("--after", - VcsFileUtil.relativeOrFullPath(sourceRepo, source), - VcsFileUtil.relativeOrFullPath(targetRepo, target)), null); - } else { + executor.executeInCurrentThread(sourceRepo, "copy", Arrays.asList("--after", + VcsFileUtil.relativeOrFullPath(sourceRepo, source), + VcsFileUtil.relativeOrFullPath(targetRepo, target))); + } + else { // copying from one repository to another => 'hg add' in new repo if (targetRepo != null) { - new HgAddCommand(myProject).execute(Collections.singleton(target)); + new HgAddCommand(myProject).executeInCurrentThread(Collections.singleton(target)); } } } - }