[shelve ]IDEA-146790 "Unshelve..." refression: use commit messages for new changelists

* provide external commit message and local changeList for unshelve;
* remove unnecessary dialog constructor;
* move common methods to Util class;
* todo: provide commit message via patch info and parse using our patch info reader
This commit is contained in:
Nadya Zabrodina
2015-10-28 15:11:42 +03:00
parent 03a49e38f5
commit 16462075df
4 changed files with 91 additions and 85 deletions
@@ -0,0 +1,55 @@
/*
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.openapi.vcs.changes;
import com.google.common.primitives.Ints;
import com.intellij.openapi.util.Condition;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
public class ChangeListUtil {
@Nullable
public static LocalChangeList getPredefinedChangeList(@NotNull String defaultName, @NotNull ChangeListManager changeListManager) {
final LocalChangeList sameNamedList = changeListManager.findChangeList(defaultName);
if (sameNamedList != null) return sameNamedList;
LocalChangeList list = tryToMatchWithExistingChangelist(changeListManager, defaultName);
return list == null ? changeListManager.getDefaultChangeList() : list;
}
@Nullable
private static LocalChangeList tryToMatchWithExistingChangelist(@NotNull ChangeListManager changeListManager,
@NotNull final String defaultName) {
List<LocalChangeList> matched = ContainerUtil.findAll(changeListManager.getChangeListsCopy(), new Condition<LocalChangeList>() {
@Override
public boolean value(LocalChangeList list) {
return defaultName.contains(list.getName().trim());
}
});
return matched.isEmpty() ? null : Collections.max(matched, new Comparator<LocalChangeList>() {
@Override
public int compare(LocalChangeList o1, LocalChangeList o2) {
return Ints.compare(o1.getName().trim().length(), o2.getName().trim().length());
}
});
}
}
@@ -105,22 +105,12 @@ public class ApplyPatchDifferentiatedDialog extends DialogWrapper {
private VirtualFileAdapter myListener;
private final boolean myCanChangePatchFile;
private String myHelpId = "reference.dialogs.vcs.patch.apply";
public ApplyPatchDifferentiatedDialog(final Project project,
final ApplyPatchExecutor callback,
final List<ApplyPatchExecutor> executors,
@NotNull final ApplyPatchMode applyPatchMode,
@NotNull final VirtualFile patchFile,
List<ShelveChangesManager.ShelvedBinaryFilePatch> binaryShelvedPatches,
@Nullable Collection<Change> preselectedChanges) {
this(project, callback, executors, applyPatchMode, patchFile, null, null, binaryShelvedPatches, preselectedChanges);
}
private final LocalChangeList myLocalChangeList;
private final String myCommitMessage; //may be provided externally; todo: parse with Additional Info Reader from patch meta information
public ApplyPatchDifferentiatedDialog(final Project project, final ApplyPatchExecutor callback, final List<ApplyPatchExecutor> executors,
@NotNull final ApplyPatchMode applyPatchMode, @NotNull final VirtualFile patchFile) {
this(project, callback, executors, applyPatchMode, patchFile, null, null, null, null);
this(project, callback, executors, applyPatchMode, patchFile, null, null, null, null, null);
}
public ApplyPatchDifferentiatedDialog(final Project project,
@@ -129,18 +119,18 @@ public class ApplyPatchDifferentiatedDialog extends DialogWrapper {
@NotNull final ApplyPatchMode applyPatchMode,
@NotNull final List<TextFilePatch> patches,
@Nullable final LocalChangeList defaultList) {
this(project, callback, executors, applyPatchMode, null, patches, defaultList, null, null);
this(project, callback, executors, applyPatchMode, null, patches, defaultList, null, null, null);
}
private ApplyPatchDifferentiatedDialog(final Project project,
final ApplyPatchExecutor callback,
final List<ApplyPatchExecutor> executors,
@NotNull final ApplyPatchMode applyPatchMode,
@Nullable final VirtualFile patchFile,
@Nullable final List<TextFilePatch> patches,
@Nullable final LocalChangeList defaultList,
@Nullable List<ShelveChangesManager.ShelvedBinaryFilePatch> binaryShelvedPatches,
@Nullable Collection<Change> preselectedChanges) {
public ApplyPatchDifferentiatedDialog(final Project project,
final ApplyPatchExecutor callback,
final List<ApplyPatchExecutor> executors,
@NotNull final ApplyPatchMode applyPatchMode,
@Nullable final VirtualFile patchFile,
@Nullable final List<TextFilePatch> patches,
@Nullable final LocalChangeList defaultList,
@Nullable List<ShelveChangesManager.ShelvedBinaryFilePatch> binaryShelvedPatches,
@Nullable Collection<Change> preselectedChanges, @Nullable String externalCommitMessage) {
super(project, true);
myCallback = callback;
myExecutors = executors;
@@ -191,6 +181,8 @@ public class ApplyPatchDifferentiatedDialog extends DialogWrapper {
}
});
myCommitMessage = externalCommitMessage;
myLocalChangeList = defaultList;
myLoadQueue = new ZipperUpdater(500, Alarm.ThreadToUse.POOLED_THREAD, getDisposable());
myCanChangePatchFile = applyPatchMode.isCanChangePatchFile();
myReset = myCanChangePatchFile ? new Runnable() {
@@ -207,7 +199,7 @@ public class ApplyPatchDifferentiatedDialog extends DialogWrapper {
});
ChangeListManager changeListManager = ChangeListManager.getInstance(project);
myChangeListChooser.setChangeLists(changeListManager.getChangeListsCopy());
myChangeListChooser.setDefaultSelection(changeListManager.getDefaultChangeList());
myChangeListChooser.setDefaultSelection(myLocalChangeList != null ? myLocalChangeList : changeListManager.getDefaultChangeList());
myChangeListChooser.init();
myInfoCalculator = new ChangesLegendCalculator();
@@ -219,7 +211,7 @@ public class ApplyPatchDifferentiatedDialog extends DialogWrapper {
init(patchFile);
}
else if (patches != null) {
init(patches, defaultList);
init(patches);
}
myPatchFileLabel.setVisible(myCanChangePatchFile);
@@ -256,15 +248,11 @@ public class ApplyPatchDifferentiatedDialog extends DialogWrapper {
myLoadQueue.queue(myUpdater);
}
private void init(List<? extends FilePatch> patches, final LocalChangeList localChangeList) {
private void init(List<? extends FilePatch> patches) {
final List<AbstractFilePatchInProgress> matchedPatches = new MatchPatchPaths(myProject).execute(patches);
//todo add shelved binary patches
ApplicationManager.getApplication().invokeLater(new Runnable() {
public void run() {
if (localChangeList != null) {
myChangeListChooser.setDefaultSelection(localChangeList);
}
myPatches.clear();
myPatches.addAll(matchedPatches);
updateTree(true);
@@ -365,7 +353,8 @@ public class ApplyPatchDifferentiatedDialog extends DialogWrapper {
ApplicationManager.getApplication().invokeLater(new Runnable() {
public void run() {
myChangeListChooser.setDefaultName(file.getNameWithoutExtension().replace('_', ' ').trim());
myChangeListChooser
.setDefaultName(myCommitMessage != null ? myCommitMessage : file.getNameWithoutExtension().replace('_', ' ').trim());
myPatches.clear();
myPatches.addAll(matchedPatches);
myReader = patchReader;
@@ -13,16 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* Created by IntelliJ IDEA.
* User: yole
* Date: 23.11.2006
* Time: 17:20:10
*/
package com.intellij.openapi.vcs.changes.shelf;
import com.google.common.primitives.Ints;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.diagnostic.Logger;
@@ -32,20 +24,17 @@ import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.progress.Task;
import com.intellij.openapi.project.DumbAwareAction;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Condition;
import com.intellij.openapi.vcs.VcsBundle;
import com.intellij.openapi.vcs.changes.BackgroundFromStartOption;
import com.intellij.openapi.vcs.changes.ChangeListManager;
import com.intellij.openapi.vcs.changes.LocalChangeList;
import com.intellij.openapi.vcs.changes.ui.ChangeListChooser;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import static com.intellij.openapi.vcs.changes.ChangeListUtil.getPredefinedChangeList;
public class UnshelveChangesAction extends DumbAwareAction {
private final Logger LOG = Logger.getInstance("#com.intellij.openapi.vcs.changes.shelf.UnshelveChangesAction");
@@ -61,27 +50,13 @@ public class UnshelveChangesAction extends DumbAwareAction {
}
LOG.assertTrue(changeLists != null);
final ChangeListManager changeListManager = ChangeListManager.getInstance(project);
final List<LocalChangeList> allChangeLists = changeListManager.getChangeListsCopy();
String defaultName = changeLists[0].DESCRIPTION;
LocalChangeList list = null;
if (changeLists.length == 1) {
final LocalChangeList sameNamedList = changeListManager.findChangeList(defaultName);
if (sameNamedList != null) {
list = sameNamedList;
}
else {
list = tryToMatchWithExistingChangelist(changeListManager, defaultName);
}
}
if (list == null) {
list = changeListManager.getDefaultChangeList();
}
final ChangeListChooser chooser = new ChangeListChooser(project, allChangeLists, list,
final ChangeListManager changeListManager = ChangeListManager.getInstance(project);
LocalChangeList list =
changeLists.length == 1 ? getPredefinedChangeList(defaultName, changeListManager) : changeListManager.getDefaultChangeList();
final ChangeListChooser chooser = new ChangeListChooser(project, changeListManager.getChangeListsCopy(), list,
VcsBundle.message("unshelve.changelist.chooser.title"), defaultName);
if (!chooser.showAndGet()) {
return;
}
if (!chooser.showAndGet()) return;
FileDocumentManager.getInstance().saveAllDocuments();
@@ -98,24 +73,6 @@ public class UnshelveChangesAction extends DumbAwareAction {
});
}
@Nullable
private static LocalChangeList tryToMatchWithExistingChangelist(@NotNull ChangeListManager changeListManager,
@NotNull final String defaultName) {
List<LocalChangeList> matched = ContainerUtil.findAll(changeListManager.getChangeListsCopy(), new Condition<LocalChangeList>() {
@Override
public boolean value(LocalChangeList list) {
return defaultName.contains(list.getName().trim());
}
});
return matched.isEmpty() ? null : Collections.max(matched, new Comparator<LocalChangeList>() {
@Override
public int compare(LocalChangeList o1, LocalChangeList o2) {
return Ints.compare(o1.getName().trim().length(), o2.getName().trim().length());
}
});
}
@Override
public void update(AnActionEvent e) {
final Project project = e.getData(CommonDataKeys.PROJECT);
@@ -23,6 +23,7 @@ import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.MessageType;
import com.intellij.openapi.vcs.VcsDataKeys;
import com.intellij.openapi.vcs.changes.Change;
import com.intellij.openapi.vcs.changes.ChangeListManager;
import com.intellij.openapi.vcs.changes.patch.ApplyPatchDefaultExecutor;
import com.intellij.openapi.vcs.changes.patch.ApplyPatchDifferentiatedDialog;
import com.intellij.openapi.vcs.changes.patch.ApplyPatchExecutor;
@@ -39,6 +40,9 @@ import java.io.File;
import java.util.Collections;
import java.util.List;
import static com.intellij.openapi.vcs.changes.ChangeListUtil.getPredefinedChangeList;
import static com.intellij.util.containers.ContainerUtil.newArrayList;
/**
* @author irengrig
* Date: 2/25/11
@@ -69,10 +73,11 @@ public class UnshelveWithDialogAction extends DumbAwareAction {
});
final ApplyPatchDifferentiatedDialog dialog =
new ApplyPatchDifferentiatedDialog(project, new ApplyPatchDefaultExecutor(project), Collections.<ApplyPatchExecutor>emptyList(),
ApplyPatchMode.UNSHELVE, virtualFile, binaryShelvedPatches,
hasNotAllSelectedChanges(project, changeList, preselectedChanges)
? ContainerUtil.newArrayList(preselectedChanges)
: null);
ApplyPatchMode.UNSHELVE, virtualFile, null,
getPredefinedChangeList(changeList.DESCRIPTION, ChangeListManager.getInstance(project)),
binaryShelvedPatches,
hasNotAllSelectedChanges(project, changeList, preselectedChanges) ?
newArrayList(preselectedChanges) : null, changeList.DESCRIPTION);
dialog.setHelpId("reference.dialogs.vcs.unshelve");
dialog.show();
}