svn: Refactoring - removed "ContinuationContext" method parameter from quick merge tasks

This commit is contained in:
Konstantin Kolosovsky
2016-10-11 04:28:23 +03:00
parent 3c1e43b53b
commit a14a30f72f
12 changed files with 118 additions and 96 deletions
@@ -20,6 +20,7 @@ import com.intellij.openapi.vcs.VcsException;
import com.intellij.openapi.vcs.versionBrowser.CommittedChangeList;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.continuation.ContinuationContext;
import com.intellij.util.continuation.SeparatePiecesRunner;
import com.intellij.util.continuation.TaskDescriptor;
import com.intellij.util.continuation.Where;
import org.jetbrains.annotations.CalledInAny;
@@ -41,6 +42,7 @@ public abstract class BaseMergeTask extends TaskDescriptor {
@NotNull protected final QuickMerge myMergeProcess;
@NotNull protected final MergeContext myMergeContext;
@NotNull protected final QuickMergeInteraction myInteraction;
@NotNull private final SeparatePiecesRunner myRunner;
public BaseMergeTask(@NotNull QuickMerge mergeProcess, @NotNull String name, @NotNull Where where) {
super(name, where);
@@ -48,6 +50,38 @@ public abstract class BaseMergeTask extends TaskDescriptor {
myMergeProcess = mergeProcess;
myMergeContext = mergeProcess.getMergeContext();
myInteraction = mergeProcess.getInteraction();
myRunner = mergeProcess.getRunner();
}
@Override
public void run(@NotNull ContinuationContext context) {
try {
run();
}
catch (VcsException e) {
end(e);
}
}
public void run() throws VcsException {
}
@CalledInAny
protected void next(@NotNull TaskDescriptor... tasks) {
myRunner.next(tasks);
}
@CalledInAny
protected void next(@NotNull List<TaskDescriptor> tasks) {
myRunner.next(tasks);
}
protected void suspend() {
myRunner.suspend();
}
protected void ping() {
myRunner.ping();
}
@NotNull
@@ -64,46 +98,49 @@ public abstract class BaseMergeTask extends TaskDescriptor {
return result;
}
protected void runChangeListsMerge(@NotNull ContinuationContext context,
@NotNull List<CommittedChangeList> lists,
protected void runChangeListsMerge(@NotNull List<CommittedChangeList> lists,
@NotNull SvnBranchPointsCalculator.WrapperInvertor copyPoint,
@NotNull String title) {
context.next(new LocalChangesPromptTask(myMergeProcess, false, lists, copyPoint),
new MergeTask(myMergeProcess, new ChangeListsMergerFactory(lists, false, false, true), title));
next(new LocalChangesPromptTask(myMergeProcess, false, lists, copyPoint),
new MergeTask(myMergeProcess, new ChangeListsMergerFactory(lists, false, false, true), title));
}
@Nullable
protected SVNURL parseSourceUrl(@NotNull ContinuationContext context) {
protected SVNURL parseSourceUrl() {
SVNURL result = null;
try {
result = SvnUtil.createUrl(myMergeContext.getSourceUrl());
}
catch (SvnBindException e) {
end(context, e);
end(e);
}
return result;
}
protected void end() {
myRunner.cancelEverything();
}
@CalledInAny
protected void end(@NotNull ContinuationContext context, @NotNull String message, boolean isError) {
protected void end(@NotNull String message, boolean isError) {
LOG.info((isError ? "Error: " : "Info: ") + message);
context.cancelEverything();
end();
getApplication().invokeLater(() -> myInteraction.showErrors(message, isError));
}
@CalledInAny
protected void end(@NotNull ContinuationContext context, @NotNull VcsException e) {
end(context, myMergeContext.getTitle(), e);
protected void end(@NotNull VcsException e) {
end(myMergeContext.getTitle(), e);
}
@CalledInAny
protected void end(@NotNull ContinuationContext context, @NotNull String message, @NotNull VcsException e) {
protected void end(@NotNull String message, @NotNull VcsException e) {
LOG.info(message, e);
context.cancelEverything();
end();
getApplication().invokeLater(() -> myInteraction.showErrors(message, singletonList(e)));
}
}
@@ -15,7 +15,6 @@
*/
package org.jetbrains.idea.svn.integrate;
import com.intellij.util.continuation.ContinuationContext;
import com.intellij.util.continuation.TaskDescriptor;
import com.intellij.util.continuation.Where;
import org.jetbrains.annotations.NotNull;
@@ -32,8 +31,8 @@ public class CheckRepositorySupportsMergeInfoTask extends BaseMergeTask {
}
@Override
public void run(ContinuationContext context) {
context.next(supportsMergeInfo() ? getChooseMergeTypeTasks() : getMergeAllTasks());
public void run() {
next(supportsMergeInfo() ? getChooseMergeTypeTasks() : getMergeAllTasks());
}
private boolean supportsMergeInfo() {
@@ -21,7 +21,6 @@ import com.intellij.openapi.util.Pair;
import com.intellij.openapi.vcs.VcsException;
import com.intellij.openapi.vcs.versionBrowser.ChangeBrowserSettings;
import com.intellij.openapi.vcs.versionBrowser.CommittedChangeList;
import com.intellij.util.continuation.ContinuationContext;
import com.intellij.util.continuation.Where;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.idea.svn.history.LogHierarchyNode;
@@ -64,15 +63,6 @@ public class LoadRecentBranchRevisions extends BaseMergeTask {
* TODO: Try to unify collecting and filtering change lists with similar logic in MergeCalculatorTask.
*/
@Override
public void run(ContinuationContext context) {
try {
run();
}
catch (VcsException e) {
end(context, e);
}
}
public void run() throws VcsException {
initialize(getChangeListsBefore(myFirst));
}
@@ -23,7 +23,6 @@ import com.intellij.openapi.vcs.changes.ChangeListManager;
import com.intellij.openapi.vcs.changes.LocalChangeList;
import com.intellij.openapi.vcs.versionBrowser.CommittedChangeList;
import com.intellij.util.FilePathByPathComparator;
import com.intellij.util.continuation.ContinuationContext;
import com.intellij.util.continuation.Where;
import com.intellij.vcsUtil.VcsUtil;
import org.jetbrains.annotations.NotNull;
@@ -72,30 +71,30 @@ public class LocalChangesPromptTask extends BaseMergeTask {
}
@Override
public void run(ContinuationContext context) {
public void run() {
List<LocalChangeList> localChangeLists = ChangeListManager.getInstance(myMergeContext.getProject()).getChangeListsCopy();
Intersection intersection =
myMergeAll ? getAllChangesIntersection(localChangeLists) : getChangesIntersection(localChangeLists, myChangeListsToMerge);
if (intersection != null && !intersection.getChangesSubset().isEmpty()) {
processIntersection(context, intersection);
processIntersection(intersection);
}
}
private void processIntersection(@NotNull ContinuationContext context, @NotNull Intersection intersection) {
private void processIntersection(@NotNull Intersection intersection) {
//noinspection EnumSwitchStatementWhichMissesCases
switch (myInteraction.selectLocalChangesAction(myMergeAll)) {
case shelve:
context.next(new ShelveLocalChangesTask(myMergeProcess, intersection));
next(new ShelveLocalChangesTask(myMergeProcess, intersection));
break;
case cancel:
context.cancelEverything();
end();
break;
case inspect:
// here's cast is due to generic's bug
@SuppressWarnings("unchecked") Collection<Change> changes = (Collection<Change>)intersection.getChangesSubset().values();
myInteraction.showIntersectedLocalPaths(sorted(getPaths(changes), FilePathByPathComparator.getInstance()));
context.cancelEverything();
end();
break;
}
}
@@ -16,7 +16,6 @@
package org.jetbrains.idea.svn.integrate;
import com.intellij.openapi.vcs.VcsException;
import com.intellij.util.continuation.ContinuationContext;
import com.intellij.util.continuation.TaskDescriptor;
import com.intellij.util.continuation.Where;
import org.jetbrains.annotations.NotNull;
@@ -29,23 +28,23 @@ public class MergeAllOrSelectedChooserTask extends BaseMergeTask {
}
@Override
public void run(ContinuationContext context) {
public void run() {
//noinspection EnumSwitchStatementWhichMissesCases
switch (myInteraction.selectMergeVariant()) {
case all:
context.next(getMergeAllTasks());
next(getMergeAllTasks());
break;
case showLatest:
LoadRecentBranchRevisions loader = new LoadRecentBranchRevisions(myMergeProcess, -1);
ShowRecentInDialogTask dialog = new ShowRecentInDialogTask(myMergeProcess, loader);
context.next(loader, dialog);
next(loader, dialog);
break;
case select:
MergeCalculatorTask calculator = getMergeCalculatorTask(context);
MergeCalculatorTask calculator = getMergeCalculatorTask();
if (calculator != null) {
context.next(getCalculateFirstCopyPointTask(calculator), calculator);
next(getCalculateFirstCopyPointTask(calculator), calculator);
}
break;
}
@@ -59,14 +58,14 @@ public class MergeAllOrSelectedChooserTask extends BaseMergeTask {
}
@Nullable
private MergeCalculatorTask getMergeCalculatorTask(@NotNull ContinuationContext context) {
private MergeCalculatorTask getMergeCalculatorTask() {
MergeCalculatorTask result = null;
try {
result = new MergeCalculatorTask(myMergeProcess);
}
catch (VcsException e) {
end(context, e);
end(e);
}
return result;
@@ -18,7 +18,6 @@ package org.jetbrains.idea.svn.integrate;
import com.intellij.openapi.vcs.VcsException;
import com.intellij.openapi.vcs.changes.TransparentlyFailedValueI;
import com.intellij.util.Consumer;
import com.intellij.util.continuation.ContinuationContext;
import com.intellij.util.continuation.Where;
import org.jetbrains.annotations.NotNull;
@@ -41,45 +40,44 @@ public class MergeAllWithBranchCopyPointTask extends BaseMergeTask
}
@Override
public void run(ContinuationContext context) {
public void run() {
TransparentlyFailedValueI<SvnBranchPointsCalculator.WrapperInvertor, VcsException> inverterValue = myData.get();
if (inverterValue != null) {
runMerge(context, inverterValue);
runMerge(inverterValue);
}
else {
end(context, "Merge start wasn't found", true);
end("Merge start wasn't found", true);
}
}
private void runMerge(@NotNull ContinuationContext context,
@NotNull TransparentlyFailedValueI<SvnBranchPointsCalculator.WrapperInvertor, VcsException> inverterValue) {
private void runMerge(@NotNull TransparentlyFailedValueI<SvnBranchPointsCalculator.WrapperInvertor, VcsException> inverterValue) {
try {
SvnBranchPointsCalculator.WrapperInvertor inverter = inverterValue.get();
if (inverter != null) {
runMerge(context, inverter);
runMerge(inverter);
}
else {
end(context, "Merge start wasn't found", true);
end("Merge start wasn't found", true);
}
}
catch (VcsException e) {
end(context, "Merge start wasn't found", e);
end("Merge start wasn't found", e);
}
}
private void runMerge(@NotNull ContinuationContext context, @NotNull SvnBranchPointsCalculator.WrapperInvertor inverter) {
private void runMerge(@NotNull SvnBranchPointsCalculator.WrapperInvertor inverter) {
boolean reintegrate = inverter.isInvertedSense();
if (reintegrate && !myInteraction.shouldReintegrate(inverter.inverted().getTarget())) {
context.cancelEverything();
end();
}
else {
MergerFactory mergerFactory = createBranchMergerFactory(reintegrate, inverter);
String title = "Merging all from " + myMergeContext.getBranchName() + (reintegrate ? " (reintegrate)" : "");
context.next(new MergeTask(myMergeProcess, mergerFactory, title));
next(new MergeTask(myMergeProcess, mergerFactory, title));
}
}
@@ -24,7 +24,6 @@ import com.intellij.openapi.vcs.versionBrowser.ChangeBrowserSettings;
import com.intellij.openapi.vcs.versionBrowser.CommittedChangeList;
import com.intellij.util.Consumer;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.continuation.ContinuationContext;
import com.intellij.util.continuation.Where;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -66,43 +65,43 @@ public class MergeCalculatorTask extends BaseMergeTask
}
@Override
public void run(ContinuationContext context) {
SvnBranchPointsCalculator.WrapperInvertor copyPoint = getCopyPoint(context);
public void run() {
SvnBranchPointsCalculator.WrapperInvertor copyPoint = getCopyPoint();
if (copyPoint != null && myMergeContext.getWcInfo().getFormat().supportsMergeInfo()) {
List<Pair<SvnChangeList, LogHierarchyNode>> afterCopyPointChangeLists =
getChangeListsAfter(context, copyPoint.getTrue().getTargetRevision());
getChangeListsAfter(copyPoint.getTrue().getTargetRevision());
List<CommittedChangeList> notMergedChangeLists = getNotMergedChangeLists(afterCopyPointChangeLists);
if (!notMergedChangeLists.isEmpty()) {
context.next(new ShowRevisionSelector(myMergeProcess, copyPoint, notMergedChangeLists, myMergeChecker));
next(new ShowRevisionSelector(myMergeProcess, copyPoint, notMergedChangeLists, myMergeChecker));
}
else {
end(context, "Everything is up-to-date", false);
end("Everything is up-to-date", false);
}
}
}
@Nullable
private SvnBranchPointsCalculator.WrapperInvertor getCopyPoint(@NotNull ContinuationContext context) {
private SvnBranchPointsCalculator.WrapperInvertor getCopyPoint() {
SvnBranchPointsCalculator.WrapperInvertor result = null;
try {
result = myCopyData.get().get();
if (result == null) {
end(context, "Merge start wasn't found", true);
end("Merge start wasn't found", true);
}
}
catch (VcsException e) {
end(context, "Merge start wasn't found", e);
end("Merge start wasn't found", e);
}
return result;
}
@NotNull
private List<Pair<SvnChangeList, LogHierarchyNode>> getChangeListsAfter(@NotNull ContinuationContext context, final long revision) {
private List<Pair<SvnChangeList, LogHierarchyNode>> getChangeListsAfter(final long revision) {
ChangeBrowserSettings settings = new ChangeBrowserSettings();
settings.CHANGE_AFTER = Long.toString(revision);
settings.USE_CHANGE_AFTER_FILTER = true;
@@ -121,7 +120,7 @@ public class MergeCalculatorTask extends BaseMergeTask
});
}
catch (VcsException e) {
end(context, "Checking revisions for merge fault", e);
end("Checking revisions for merge fault", e);
}
return result;
@@ -177,22 +176,22 @@ public class MergeCalculatorTask extends BaseMergeTask
}
@Override
public void run(ContinuationContext context) {
public void run() {
QuickMergeInteraction.SelectMergeItemsResult result =
myInteraction.selectMergeItems(myChangeLists, myMergeContext.getTitle(), myMergeChecker);
switch (result.getResultCode()) {
case cancel:
context.cancelEverything();
end();
break;
case all:
context.next(getMergeAllTasks());
next(getMergeAllTasks());
break;
default:
List<CommittedChangeList> lists = result.getSelectedLists();
if (!lists.isEmpty()) {
runChangeListsMerge(context, lists, myCopyPoint, myMergeContext.getTitle());
runChangeListsMerge(lists, myCopyPoint, myMergeContext.getTitle());
}
break;
}
@@ -16,7 +16,6 @@
package org.jetbrains.idea.svn.integrate;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.util.continuation.ContinuationContext;
import com.intellij.util.continuation.Where;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.idea.svn.NestedCopyType;
@@ -32,15 +31,15 @@ public class MergeInitChecksTask extends BaseMergeTask {
}
@Override
public void run(ContinuationContext context) {
SVNURL url = parseSourceUrl(context);
public void run() {
SVNURL url = parseSourceUrl();
if (url != null) {
if (areInSameHierarchy(url, myMergeContext.getWcInfo().getUrl())) {
end(context, "Cannot merge from self", true);
end("Cannot merge from self", true);
}
else if (hasSwitchedRoots() && !myInteraction.shouldContinueSwitchedRootFound()) {
context.cancelEverything();
end();
}
}
}
@@ -19,7 +19,6 @@ import com.intellij.openapi.application.ModalityState;
import com.intellij.openapi.vcs.changes.ChangeListManager;
import com.intellij.openapi.vcs.changes.InvokeAfterUpdateMode;
import com.intellij.openapi.vcs.changes.LocalChangeList;
import com.intellij.util.continuation.ContinuationContext;
import com.intellij.util.continuation.TaskDescriptor;
import com.intellij.util.continuation.Where;
import org.jetbrains.annotations.NotNull;
@@ -36,15 +35,15 @@ public class MergeTask extends BaseMergeTask {
}
@Override
public void run(ContinuationContext context) {
SVNURL sourceUrl = parseSourceUrl(context);
public void run() {
SVNURL sourceUrl = parseSourceUrl();
if (sourceUrl != null) {
context.next(TaskDescriptor.createForBackgroundableTask(newIntegrateTask(sourceUrl)));
next(TaskDescriptor.createForBackgroundableTask(newIntegrateTask(sourceUrl)));
boolean needRefresh = setupDefaultEmptyChangeListForMerge();
if (needRefresh) {
refreshChanges(context);
refreshChanges();
}
}
}
@@ -82,10 +81,9 @@ public class MergeTask extends BaseMergeTask {
return needRefresh;
}
private void refreshChanges(@NotNull ContinuationContext context) {
context.suspend();
private void refreshChanges() {
suspend();
ChangeListManager.getInstance(myMergeContext.getProject())
.invokeAfterUpdate(context::ping, InvokeAfterUpdateMode.BACKGROUND_NOT_CANCELLABLE, "", ModalityState.NON_MODAL);
.invokeAfterUpdate(this::ping, InvokeAfterUpdateMode.BACKGROUND_NOT_CANCELLABLE, "", ModalityState.NON_MODAL);
}
}
@@ -34,10 +34,12 @@ public class QuickMerge {
@NotNull private final MergeContext myMergeContext;
@NotNull private final QuickMergeInteraction myInteraction;
@NotNull private final SeparatePiecesRunner myRunner;
public QuickMerge(@NotNull MergeContext mergeContext, @NotNull QuickMergeInteraction interaction) {
myMergeContext = mergeContext;
myInteraction = interaction;
myRunner = createRunner();
}
@NotNull
@@ -50,6 +52,11 @@ public class QuickMerge {
return myInteraction;
}
@NotNull
public SeparatePiecesRunner getRunner() {
return myRunner;
}
@CalledInAwt
public void execute() {
runMergeTasks(null);
@@ -71,9 +78,8 @@ public class QuickMerge {
finalTask
};
SeparatePiecesRunner runner = createRunner();
runner.next(mapNotNull(tasks, identity()));
runner.ping();
myRunner.next(mapNotNull(tasks, identity()));
myRunner.ping();
}
@NotNull
@@ -23,7 +23,6 @@ import com.intellij.openapi.vcs.changes.Change;
import com.intellij.openapi.vcs.changes.shelf.ShelveChangesManager;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.newvfs.RefreshQueue;
import com.intellij.util.continuation.ContinuationContext;
import com.intellij.util.continuation.Where;
import org.jetbrains.annotations.NotNull;
@@ -47,15 +46,15 @@ public class ShelveLocalChangesTask extends BaseMergeTask {
}
@Override
public void run(ContinuationContext context) {
List<VirtualFile> changedFiles = shelveChanges(context);
public void run() {
List<VirtualFile> changedFiles = shelveChanges();
context.suspend();
RefreshQueue.getInstance().refresh(true, false, context::ping, changedFiles);
suspend();
RefreshQueue.getInstance().refresh(true, false, this::ping, changedFiles);
}
@NotNull
private List<VirtualFile> shelveChanges(@NotNull ContinuationContext context) {
private List<VirtualFile> shelveChanges() {
List<VirtualFile> changedFiles = newArrayList();
ShelveChangesManager shelveManager = ShelveChangesManager.getInstance(myMergeContext.getProject());
@@ -71,10 +70,10 @@ public class ShelveLocalChangesTask extends BaseMergeTask {
changedFiles.addAll(getAfterRevisionsFiles(entry.getValue().stream(), true).collect(toList()));
}
catch (IOException e) {
end(context, new VcsException(e));
end(new VcsException(e));
}
catch (VcsException e) {
end(context, e);
end(e);
}
}
@@ -16,7 +16,6 @@
package org.jetbrains.idea.svn.integrate;
import com.intellij.openapi.vcs.versionBrowser.CommittedChangeList;
import com.intellij.util.continuation.ContinuationContext;
import com.intellij.util.continuation.Where;
import org.jetbrains.annotations.NotNull;
@@ -33,16 +32,16 @@ public class ShowRecentInDialogTask extends BaseMergeTask {
}
@Override
public void run(ContinuationContext context) {
public void run() {
List<CommittedChangeList> lists = myInteraction
.showRecentListsForSelection(myInitialChangeListsLoader.getCommittedChangeLists(), myInitialChangeListsLoader.getHelper(),
myInitialChangeListsLoader.isLastLoaded());
if (!lists.isEmpty()) {
runChangeListsMerge(context, lists, createBranchCopyPoint(), myMergeContext.getTitle());
runChangeListsMerge(lists, createBranchCopyPoint(), myMergeContext.getTitle());
}
else {
context.cancelEverything();
end();
}
}