mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-18754 (After unshelving with new changelist creation default changelist gets populated not new)
This commit is contained in:
@@ -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<VirtualFile> directlyAffected = myVerifier.getDirectlyAffected();
|
||||
final List<VirtualFile> 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<FilePath> directlyAffected = myVerifier.getDirectlyAffected();
|
||||
final List<VirtualFile> 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<VcsDirtyScopeManager>() {
|
||||
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<Pair<VirtualFile, FilePatch>> textPatches = verifier.getTextPatches();
|
||||
@@ -275,4 +296,25 @@ public class PatchApplier {
|
||||
return child;
|
||||
}
|
||||
|
||||
private class FilesMover implements Runnable {
|
||||
private final ChangeListManager myChangeListManager;
|
||||
private final List<FilePath> myDirectlyAffected;
|
||||
|
||||
public FilesMover(final ChangeListManager changeListManager, final List<FilePath> directlyAffected) {
|
||||
myChangeListManager = changeListManager;
|
||||
myDirectlyAffected = directlyAffected;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
List<Change> changes = new ArrayList<Change>();
|
||||
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()]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<FilePatch> myPatches;
|
||||
// temp
|
||||
private final Map<VirtualFile, MovedFileData> myMovedFiles;
|
||||
private final List<VirtualFile> myMoveResults;
|
||||
private final List<FilePath> myBeforePaths;
|
||||
private final List<VirtualFile> myCreatedDirectories;
|
||||
// out
|
||||
private final List<Pair<VirtualFile, FilePatch>> myTextPatches;
|
||||
@@ -40,7 +39,7 @@ public class PathsVerifier {
|
||||
myPatches = patches;
|
||||
|
||||
myMovedFiles = new HashMap<VirtualFile, MovedFileData>();
|
||||
myMoveResults = new ArrayList<VirtualFile>();
|
||||
myBeforePaths = new ArrayList<FilePath>();
|
||||
myCreatedDirectories = new ArrayList<VirtualFile>();
|
||||
myTextPatches = new ArrayList<Pair<VirtualFile,FilePatch>>();
|
||||
myBinaryPatches = new ArrayList<Pair<VirtualFile,FilePatch>>();
|
||||
@@ -48,25 +47,42 @@ public class PathsVerifier {
|
||||
}
|
||||
|
||||
// those to be moved to CL: target + created dirs
|
||||
public List<VirtualFile> getDirectlyAffected() {
|
||||
final List<VirtualFile> affected = new ArrayList<VirtualFile>();
|
||||
affected.addAll(myCreatedDirectories);
|
||||
affected.addAll(myWritableFiles);
|
||||
affected.removeAll(myMovedFiles.keySet());
|
||||
affected.addAll(myMoveResults);
|
||||
public List<FilePath> getDirectlyAffected() {
|
||||
final List<FilePath> affected = new ArrayList<FilePath>();
|
||||
addAllFilePath(myCreatedDirectories, affected);
|
||||
addAllFilePath(myWritableFiles, affected);
|
||||
affected.addAll(myBeforePaths);
|
||||
return affected;
|
||||
}
|
||||
|
||||
// old parents of moved files
|
||||
public List<VirtualFile> getAllAffected() {
|
||||
final List<VirtualFile> affected = getDirectlyAffected();
|
||||
for (MovedFileData data : myMovedFiles.values()) {
|
||||
affected.add(data.getNewParent());
|
||||
// old parent
|
||||
affected.add(data.getCurrent().getParent());
|
||||
final List<VirtualFile> affected = new ArrayList<VirtualFile>();
|
||||
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<VirtualFile> files, final Collection<FilePath> 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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<VirtualFile> files, final LocalChangeList targetChangeList) {
|
||||
final ChangeListManager changeListManager = ChangeListManager.getInstance(project);
|
||||
if (targetChangeList != changeListManager.getDefaultChangeList()) {
|
||||
changeListManager.invokeAfterUpdate(new Runnable() {
|
||||
public void run() {
|
||||
List<Change> changes = new ArrayList<Change>();
|
||||
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<FilePath> files, final LocalChangeList targetChangeList) {
|
||||
final ChangeListManager changeListManager = ChangeListManager.getInstance(project);
|
||||
if (targetChangeList != changeListManager.getDefaultChangeList()) {
|
||||
changeListManager.invokeAfterUpdate(new Runnable() {
|
||||
public void run() {
|
||||
List<Change> changes = new ArrayList<Change>();
|
||||
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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user