From d95728d5cf08de22b88ac985d9406705ae848909 Mon Sep 17 00:00:00 2001 From: irengrig Date: Tue, 13 Nov 2012 16:58:45 +0400 Subject: [PATCH] IDEA-94774 Creating new project - svn deadlock --- .../src/org/jetbrains/idea/svn/SvnUtil.java | 49 ++++++++++++++++++ .../svn/checkin/SvnCheckinEnvironment.java | 51 ++++++------------- .../svn/rollback/SvnRollbackEnvironment.java | 46 +++++++++-------- 3 files changed, 90 insertions(+), 56 deletions(-) diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/SvnUtil.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/SvnUtil.java index 7aaca745b5c8..2597e63f9bfc 100644 --- a/plugins/svn4idea/src/org/jetbrains/idea/svn/SvnUtil.java +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/SvnUtil.java @@ -21,17 +21,22 @@ import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.progress.ProgressManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Computable; +import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.Ref; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vcs.AbstractVcsHelper; import com.intellij.openapi.vcs.VcsException; +import com.intellij.openapi.vcs.changes.Change; +import com.intellij.openapi.vcs.changes.ChangesUtil; import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VfsUtilCore; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.VirtualFileManager; import com.intellij.openapi.wm.impl.status.StatusBarUtil; import com.intellij.util.ArrayUtil; +import com.intellij.util.containers.Convertor; +import com.intellij.util.containers.MultiMap; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -292,6 +297,50 @@ public class SvnUtil { return ""; } + public static Collection> splitChangesIntoWc(final SvnVcs vcs, final List changes) { + return splitIntoWc(vcs, changes, new Convertor() { + @Override + public File convert(Change o) { + return ChangesUtil.getFilePath(o).getIOFile(); + } + }); + } + + public static Collection> splitFilesIntoWc(final SvnVcs vcs, final List committables) { + return splitIntoWc(vcs, committables, Convertor.SELF); + } + + public static Collection> splitIntoWc(final SvnVcs vcs, final List committables, + Convertor convertor) { + if (committables.size() == 1) { + return Collections.singletonList(committables); + } + + final MultiMap, T> result = new MultiMap, T>() { + @Override + protected Collection createCollection() { + return new ArrayList(); + } + }; + for (T committable : committables) { + final RootUrlInfo path = vcs.getSvnFileUrlMapping().getWcRootForFilePath(convertor.convert(committable)); + if (path == null) { + result.putValue(new Pair(null, null), committable); + } else { + result.putValue(new Pair(path.getRepositoryUrlUrl(), path.getFormat()), committable); + } + } + + if (result.size() == 1) { + return Collections.singletonList(committables); + } + final Collection> result2 = new ArrayList>(); + for (Map.Entry, Collection> entry : result.entrySet()) { + result2.add((List)entry.getValue()); + } + return result2; + } + private static class LocationsCrawler implements SvnWCRootCrawler { private final SvnVcs myVcs; private final Map myLocations; diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/checkin/SvnCheckinEnvironment.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/checkin/SvnCheckinEnvironment.java index c6a017189e63..ea1a7ee6937e 100644 --- a/plugins/svn4idea/src/org/jetbrains/idea/svn/checkin/SvnCheckinEnvironment.java +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/checkin/SvnCheckinEnvironment.java @@ -25,7 +25,6 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.MessageType; import com.intellij.openapi.util.Computable; import com.intellij.openapi.util.Condition; -import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.vcs.CheckinProjectPanel; import com.intellij.openapi.vcs.FilePath; @@ -43,12 +42,17 @@ import com.intellij.openapi.vfs.VirtualFileManager; import com.intellij.util.FunctionUtil; import com.intellij.util.NullableFunction; import com.intellij.util.PairConsumer; -import com.intellij.util.containers.MultiMap; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.jetbrains.idea.svn.*; -import org.tmatesoft.svn.core.*; +import org.jetbrains.idea.svn.SvnBundle; +import org.jetbrains.idea.svn.SvnConfiguration; +import org.jetbrains.idea.svn.SvnUtil; +import org.jetbrains.idea.svn.SvnVcs; +import org.tmatesoft.svn.core.SVNCancelException; +import org.tmatesoft.svn.core.SVNCommitInfo; +import org.tmatesoft.svn.core.SVNDepth; +import org.tmatesoft.svn.core.SVNException; import org.tmatesoft.svn.core.wc.*; import javax.swing.*; @@ -84,7 +88,7 @@ public class SvnCheckinEnvironment implements CheckinEnvironment { private List commitInt(List paths, final String comment, final boolean force, final boolean recursive, final Set feedback) { final List exception = new ArrayList(); - final Collection committables = getCommitables(paths); + final List committables = getCommitables(paths); final SVNCommitClient committer = mySvnVcs.createCommitClient(); @@ -156,44 +160,19 @@ public class SvnCheckinEnvironment implements CheckinEnvironment { return exception; } - private void doCommit(Collection committables, + private void doCommit(List committables, ProgressIndicator progress, SVNCommitClient committer, String comment, boolean force, boolean recursive, List exception, final Set feedback) { - final Collection> collections = splitIntoWc(committables); - for (Collection collection : collections) { + final Collection> collections = SvnUtil.splitFilesIntoWc(mySvnVcs, committables); + for (List collection : collections) { doCommitOneWc(collection, progress, committer, comment, force, recursive, exception, feedback); } } - private Collection> splitIntoWc(Collection committables) { - if (committables.size() == 1) { - return Collections.singletonList(committables); - } - - final MultiMap, File> result = new MultiMap, File>(); - for (File committable : committables) { - final RootUrlInfo path = mySvnVcs.getSvnFileUrlMapping().getWcRootForFilePath(committable); - if (path == null) { - result.putValue(new Pair(null, null), committable); - } else { - result.putValue(new Pair(path.getRepositoryUrlUrl(), path.getFormat()), committable); - } - } - - if (result.size() == 1) { - return Collections.singletonList(committables); - } - final Collection> result2 = new ArrayList>(); - for (Map.Entry, Collection> entry : result.entrySet()) { - result2.add(entry.getValue()); - } - return result2; - } - private void doCommitOneWc(Collection committables, ProgressIndicator progress, SVNCommitClient committer, @@ -265,7 +244,7 @@ public class SvnCheckinEnvironment implements CheckinEnvironment { } private static class Adder { - private final Collection myResult = new ArrayList(); + private final List myResult = new ArrayList(); private final Set myDuplicatesControlSet = new HashSet(); public void add(final File file) { @@ -276,12 +255,12 @@ public class SvnCheckinEnvironment implements CheckinEnvironment { } } - public Collection getResult() { + public List getResult() { return myResult; } } - private Collection getCommitables(List paths) { + private List getCommitables(List paths) { final Adder adder = new Adder(); SVNStatusClient statusClient = mySvnVcs.createStatusClient(); diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/rollback/SvnRollbackEnvironment.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/rollback/SvnRollbackEnvironment.java index 5ad3c0d390a0..fd81233810c4 100644 --- a/plugins/svn4idea/src/org/jetbrains/idea/svn/rollback/SvnRollbackEnvironment.java +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/rollback/SvnRollbackEnvironment.java @@ -30,10 +30,7 @@ import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.jetbrains.idea.svn.MoveRenameReplaceCheck; -import org.jetbrains.idea.svn.SvnBundle; -import org.jetbrains.idea.svn.SvnChangeProvider; -import org.jetbrains.idea.svn.SvnVcs; +import org.jetbrains.idea.svn.*; import org.tmatesoft.svn.core.SVNDepth; import org.tmatesoft.svn.core.SVNErrorCode; import org.tmatesoft.svn.core.SVNException; @@ -62,31 +59,40 @@ public class SvnRollbackEnvironment extends DefaultRollbackEnvironment { public void rollbackChanges(List changes, final List exceptions, @NotNull final RollbackProgressListener listener) { listener.indeterminate(); final SvnChangeProvider changeProvider = (SvnChangeProvider) mySvnVcs.getChangeProvider(); - + final Collection> collections = SvnUtil.splitChangesIntoWc(mySvnVcs, changes); + for (List collection : collections) { + rollbackGroupForWc(collection, exceptions, listener, changeProvider); + } + } + + private void rollbackGroupForWc(List changes, + final List exceptions, + final RollbackProgressListener listener, + SvnChangeProvider changeProvider) { final UnversionedFilesGroupCollector collector = new UnversionedFilesGroupCollector(); final ChangesChecker checker = new ChangesChecker(changeProvider, collector); checker.gather(changes); exceptions.addAll(checker.getExceptions()); - final SVNWCClient client = mySvnVcs.createWCClient(); - client.setEventHandler(new ISVNEventHandler() { - public void handleEvent(SVNEvent event, double progress) { - if (event.getAction() == SVNEventAction.REVERT) { - final File file = event.getFile(); - if (file != null) { - listener.accept(file); - } - } - if (event.getAction() == SVNEventAction.FAILED_REVERT) { - exceptions.add(new VcsException("Revert failed")); + final SVNWCClient client = mySvnVcs.createWCClient(); + client.setEventHandler(new ISVNEventHandler() { + public void handleEvent(SVNEvent event, double progress) { + if (event.getAction() == SVNEventAction.REVERT) { + final File file = event.getFile(); + if (file != null) { + listener.accept(file); } } + if (event.getAction() == SVNEventAction.FAILED_REVERT) { + exceptions.add(new VcsException("Revert failed")); + } + } - public void checkCancelled() { - listener.checkCanceled(); - } - }); + public void checkCancelled() { + listener.checkCanceled(); + } + }); final List> fromTo = collector.getFromTo(); final List> fromToModified = new ArrayList>();