diff --git a/vcs-impl/src/com/intellij/openapi/diff/impl/patch/formove/PatchApplier.java b/vcs-impl/src/com/intellij/openapi/diff/impl/patch/formove/PatchApplier.java index 5795aa9de576..142b5adc21e3 100644 --- a/vcs-impl/src/com/intellij/openapi/diff/impl/patch/formove/PatchApplier.java +++ b/vcs-impl/src/com/intellij/openapi/diff/impl/patch/formove/PatchApplier.java @@ -13,14 +13,16 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.Messages; import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.Ref; +import com.intellij.openapi.vcs.FilePath; import com.intellij.openapi.vcs.VcsBundle; -import com.intellij.openapi.vcs.changes.ChangeListManager; -import com.intellij.openapi.vcs.changes.LocalChangeList; -import com.intellij.openapi.vcs.changes.VcsDirtyScopeManager; +import com.intellij.openapi.vcs.changes.*; import com.intellij.openapi.vcs.changes.patch.ApplyPatchAction; import com.intellij.openapi.vcs.changes.patch.RelativePathCalculator; import com.intellij.openapi.vfs.ReadonlyStatusHandler; import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.openapi.vfs.newvfs.RefreshSession; +import com.intellij.openapi.vfs.newvfs.RefreshQueue; +import com.intellij.util.Consumer; import org.jetbrains.annotations.Nullable; import java.io.IOException; @@ -52,6 +54,7 @@ public class PatchApplier { myVerifier = new PathsVerifier(myProject, myBaseDirectory, myPatches); } + // todo progress public ApplyPatchStatus execute() { myRemainingPatches.addAll(myPatches); @@ -84,22 +87,40 @@ public class PatchApplier { }); showApplyStatus(refStatus.get()); - final List directlyAffected = myVerifier.getDirectlyAffected(); - final List indirectlyAffected = myVerifier.getAllAffected(); - - refreshIndirectlyAffected(indirectlyAffected); - final VcsDirtyScopeManager vcsDirtyScopeManager = VcsDirtyScopeManager.getInstance(myProject); - vcsDirtyScopeManager.filesDirty(directlyAffected, null); - if ((myTargetChangeList != null) && (! directlyAffected.isEmpty())) { - ApplyPatchAction.moveChangesOfVsToList(myProject, directlyAffected, myTargetChangeList); - } else { - final ChangeListManager changeListManager = ChangeListManager.getInstance(myProject); - changeListManager.scheduleUpdate(); - } + refreshFiles(); return refStatus.get(); } + private void refreshFiles() { + final List directlyAffected = myVerifier.getDirectlyAffected(); + final List indirectlyAffected = myVerifier.getAllAffected(); + + final RefreshSession session = RefreshQueue.getInstance().createSession(false, true, new Runnable() { + public void run() { + if (myProject.isDisposed()) return; + + final ChangeListManager changeListManager = ChangeListManager.getInstance(myProject); + if ((myTargetChangeList != null) && (! directlyAffected.isEmpty()) && + (! myTargetChangeList.getName().equals(changeListManager.getDefaultListName()))) { + changeListManager.invokeAfterUpdate(new FilesMover(changeListManager, directlyAffected), InvokeAfterUpdateMode.BACKGROUND_CANCELLABLE, + VcsBundle.message("change.lists.manager.move.changes.to.list"), + new Consumer() { + public void consume(final VcsDirtyScopeManager vcsDirtyScopeManager) { + vcsDirtyScopeManager.filePathsDirty(directlyAffected, null); + } + }); + } else { + final VcsDirtyScopeManager vcsDirtyScopeManager = VcsDirtyScopeManager.getInstance(myProject); + // will schedule update + vcsDirtyScopeManager.filePathsDirty(directlyAffected, null); + } + } + }); + session.addAllFiles(indirectlyAffected); + session.launch(); + } + @Nullable private ApplyPatchStatus actualApply(final PathsVerifier verifier) { final List> textPatches = verifier.getTextPatches(); @@ -275,4 +296,25 @@ public class PatchApplier { return child; } + private class FilesMover implements Runnable { + private final ChangeListManager myChangeListManager; + private final List myDirectlyAffected; + + public FilesMover(final ChangeListManager changeListManager, final List directlyAffected) { + myChangeListManager = changeListManager; + myDirectlyAffected = directlyAffected; + } + + public void run() { + List changes = new ArrayList(); + for(FilePath file: myDirectlyAffected) { + final Change change = myChangeListManager.getChange(file); + if (change != null) { + changes.add(change); + } + } + + myChangeListManager.moveChangesTo(myTargetChangeList, changes.toArray(new Change[changes.size()])); + } + } } diff --git a/vcs-impl/src/com/intellij/openapi/diff/impl/patch/formove/PathsVerifier.java b/vcs-impl/src/com/intellij/openapi/diff/impl/patch/formove/PathsVerifier.java index 83e259e243e4..3ac07e30b18f 100644 --- a/vcs-impl/src/com/intellij/openapi/diff/impl/patch/formove/PathsVerifier.java +++ b/vcs-impl/src/com/intellij/openapi/diff/impl/patch/formove/PathsVerifier.java @@ -5,6 +5,8 @@ import com.intellij.openapi.diff.impl.patch.TextFilePatch; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.Pair; +import com.intellij.openapi.vcs.FilePath; +import com.intellij.openapi.vcs.FilePathImpl; import com.intellij.openapi.vcs.ProjectLevelVcsManager; import com.intellij.openapi.vcs.VcsBundle; import com.intellij.openapi.vcs.changes.patch.RelativePathCalculator; @@ -15,10 +17,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; public class PathsVerifier { // in @@ -27,7 +26,7 @@ public class PathsVerifier { private final List myPatches; // temp private final Map myMovedFiles; - private final List myMoveResults; + private final List myBeforePaths; private final List myCreatedDirectories; // out private final List> myTextPatches; @@ -40,7 +39,7 @@ public class PathsVerifier { myPatches = patches; myMovedFiles = new HashMap(); - myMoveResults = new ArrayList(); + myBeforePaths = new ArrayList(); myCreatedDirectories = new ArrayList(); myTextPatches = new ArrayList>(); myBinaryPatches = new ArrayList>(); @@ -48,25 +47,42 @@ public class PathsVerifier { } // those to be moved to CL: target + created dirs - public List getDirectlyAffected() { - final List affected = new ArrayList(); - affected.addAll(myCreatedDirectories); - affected.addAll(myWritableFiles); - affected.removeAll(myMovedFiles.keySet()); - affected.addAll(myMoveResults); + public List getDirectlyAffected() { + final List affected = new ArrayList(); + addAllFilePath(myCreatedDirectories, affected); + addAllFilePath(myWritableFiles, affected); + affected.addAll(myBeforePaths); return affected; } // old parents of moved files public List getAllAffected() { - final List affected = getDirectlyAffected(); - for (MovedFileData data : myMovedFiles.values()) { - affected.add(data.getNewParent()); - // old parent - affected.add(data.getCurrent().getParent()); + final List affected = new ArrayList(); + affected.addAll(myCreatedDirectories); + affected.addAll(myWritableFiles); + + // after files' parent + for (VirtualFile file : myMovedFiles.keySet()) { + final VirtualFile parent = file.getParent(); + if (parent != null) { + affected.add(parent); + } + } + // before.. + for (FilePath path : myBeforePaths) { + final FilePath parent = path.getParentPath(); + if (parent != null) { + affected.add(parent.getVirtualFile()); + } } return affected; } + + private void addAllFilePath(final Collection files, final Collection paths) { + for (VirtualFile file : files) { + paths.add(new FilePathImpl(file)); + } + } public boolean execute() { try { @@ -136,6 +152,7 @@ public class PathsVerifier { return false; } addPatch(myPatch, beforeFile); + myBeforePaths.add(new FilePathImpl(beforeFile.getParent(), beforeFile.getName(), beforeFile.isDirectory())); return true; } } @@ -391,8 +408,8 @@ public class PathsVerifier { public void doMoveIfNeeded(final VirtualFile file) throws IOException { final MovedFileData movedFile = myMovedFiles.get(file); if (movedFile != null) { + myBeforePaths.add(new FilePathImpl(file.getParent(), file.getName(), file.isDirectory())); final VirtualFile moveResult = movedFile.doMove(); - myMoveResults.add(moveResult); } } diff --git a/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangeListManagerImpl.java b/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangeListManagerImpl.java index d8a38a60ccce..26e6b6428876 100644 --- a/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangeListManagerImpl.java +++ b/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangeListManagerImpl.java @@ -546,26 +546,8 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec @Nullable public Change getChange(final FilePath file) { - final VirtualFile virtualFile = file.getVirtualFile(); - if (virtualFile == null) { - return null; - } synchronized (myDataLock) { - final LocalChangeList list = myWorker.getListCopy(virtualFile); - if (list != null) { - for (Change change : list.getChanges()) { - final ContentRevision afterRevision = change.getAfterRevision(); - if (afterRevision != null && afterRevision.getFile().equals(file)) { - return change; - } - final ContentRevision beforeRevision = change.getBeforeRevision(); - if (beforeRevision != null && beforeRevision.getFile().equals(file)) { - return change; - } - } - } - - return null; + return myWorker.getChangeForPath(file); } } diff --git a/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangeListWorker.java b/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangeListWorker.java index 38349774c4cc..c661703b2367 100644 --- a/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangeListWorker.java +++ b/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangeListWorker.java @@ -292,6 +292,23 @@ public class ChangeListWorker implements ChangeListsWriteOperations { return null; } + @Nullable + public Change getChangeForPath(final FilePath file) { + for (LocalChangeList list : myMap.values()) { + for (Change change : list.getChanges()) { + final ContentRevision afterRevision = change.getAfterRevision(); + if (afterRevision != null && afterRevision.getFile().equals(file)) { + return change; + } + final ContentRevision beforeRevision = change.getBeforeRevision(); + if (beforeRevision != null && beforeRevision.getFile().equals(file)) { + return change; + } + } + } + return null; + } + public FileStatus getStatus(final VirtualFile file) { return myIdx.getStatus(file); } diff --git a/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/ApplyPatchAction.java b/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/ApplyPatchAction.java index 3519bfdccead..cc622719e7d8 100644 --- a/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/ApplyPatchAction.java +++ b/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/ApplyPatchAction.java @@ -31,16 +31,11 @@ import com.intellij.openapi.vcs.FilePath; import com.intellij.openapi.vcs.FilePathImpl; import com.intellij.openapi.vcs.VcsBundle; import com.intellij.openapi.vcs.VcsException; -import com.intellij.openapi.vcs.changes.Change; -import com.intellij.openapi.vcs.changes.ChangeListManager; -import com.intellij.openapi.vcs.changes.InvokeAfterUpdateMode; -import com.intellij.openapi.vcs.changes.LocalChangeList; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.Processor; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.ArrayList; import java.util.List; public class ApplyPatchAction extends AnAction { @@ -183,43 +178,6 @@ public class ApplyPatchAction extends AnAction { } } - public static void moveChangesOfVsToList(final Project project, final List files, final LocalChangeList targetChangeList) { - final ChangeListManager changeListManager = ChangeListManager.getInstance(project); - if (targetChangeList != changeListManager.getDefaultChangeList()) { - changeListManager.invokeAfterUpdate(new Runnable() { - public void run() { - List changes = new ArrayList(); - for(VirtualFile file: files) { - final Change change = changeListManager.getChange(file); - if (change != null) { - changes.add(change); - } - } - - changeListManager.moveChangesTo(targetChangeList, changes.toArray(new Change[changes.size()])); - } - }, InvokeAfterUpdateMode.BACKGROUND_NOT_CANCELLABLE, VcsBundle.message("change.lists.manager.move.changes.to.list")); - } - } - - public static void moveChangesToList(final Project project, final List files, final LocalChangeList targetChangeList) { - final ChangeListManager changeListManager = ChangeListManager.getInstance(project); - if (targetChangeList != changeListManager.getDefaultChangeList()) { - changeListManager.invokeAfterUpdate(new Runnable() { - public void run() { - List changes = new ArrayList(); - for(FilePath file: files) { - final Change change = changeListManager.getChange(file); - if (change != null) { - changes.add(change); - } - } - changeListManager.moveChangesTo(targetChangeList, changes.toArray(new Change[changes.size()])); - } - }, InvokeAfterUpdateMode.BACKGROUND_NOT_CANCELLABLE, VcsBundle.message("change.lists.manager.move.changes.to.list")); - } - } - public static class ApplyPatchMergeRequestFactory implements PatchMergeRequestFactory { private final boolean myReadOnly;