From 16462075df10f1040480e7d7b3ca47f68d82b53a Mon Sep 17 00:00:00 2001 From: Nadya Zabrodina Date: Wed, 28 Oct 2015 15:08:29 +0300 Subject: [PATCH] [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 --- .../openapi/vcs/changes/ChangeListUtil.java | 55 ++++++++++++++++++ .../patch/ApplyPatchDifferentiatedDialog.java | 51 +++++++---------- .../changes/shelf/UnshelveChangesAction.java | 57 +++---------------- .../shelf/UnshelveWithDialogAction.java | 13 +++-- 4 files changed, 91 insertions(+), 85 deletions(-) create mode 100644 platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangeListUtil.java diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangeListUtil.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangeListUtil.java new file mode 100644 index 000000000000..8d1b9cdedf46 --- /dev/null +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangeListUtil.java @@ -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 matched = ContainerUtil.findAll(changeListManager.getChangeListsCopy(), new Condition() { + @Override + public boolean value(LocalChangeList list) { + return defaultName.contains(list.getName().trim()); + } + }); + + return matched.isEmpty() ? null : Collections.max(matched, new Comparator() { + @Override + public int compare(LocalChangeList o1, LocalChangeList o2) { + return Ints.compare(o1.getName().trim().length(), o2.getName().trim().length()); + } + }); + } +} diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/ApplyPatchDifferentiatedDialog.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/ApplyPatchDifferentiatedDialog.java index 14dd001cd165..681b407b214f 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/ApplyPatchDifferentiatedDialog.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/ApplyPatchDifferentiatedDialog.java @@ -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 executors, - @NotNull final ApplyPatchMode applyPatchMode, - @NotNull final VirtualFile patchFile, - List binaryShelvedPatches, - @Nullable Collection 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 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 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 executors, - @NotNull final ApplyPatchMode applyPatchMode, - @Nullable final VirtualFile patchFile, - @Nullable final List patches, - @Nullable final LocalChangeList defaultList, - @Nullable List binaryShelvedPatches, - @Nullable Collection preselectedChanges) { + public ApplyPatchDifferentiatedDialog(final Project project, + final ApplyPatchExecutor callback, + final List executors, + @NotNull final ApplyPatchMode applyPatchMode, + @Nullable final VirtualFile patchFile, + @Nullable final List patches, + @Nullable final LocalChangeList defaultList, + @Nullable List binaryShelvedPatches, + @Nullable Collection 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 patches, final LocalChangeList localChangeList) { + private void init(List patches) { final List 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; diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/UnshelveChangesAction.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/UnshelveChangesAction.java index 5d2779d6f90e..ebd71dd6a18b 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/UnshelveChangesAction.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/UnshelveChangesAction.java @@ -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 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 matched = ContainerUtil.findAll(changeListManager.getChangeListsCopy(), new Condition() { - @Override - public boolean value(LocalChangeList list) { - return defaultName.contains(list.getName().trim()); - } - }); - - return matched.isEmpty() ? null : Collections.max(matched, new Comparator() { - @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); diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/UnshelveWithDialogAction.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/UnshelveWithDialogAction.java index 5b6f36d9e582..ad514bd156d7 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/UnshelveWithDialogAction.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/UnshelveWithDialogAction.java @@ -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.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(); }