Merge branch 'nz/shared_shelf'
authorNadya Zabrodina <Nadya.Zabrodina@jetbrains.com>
Mon, 17 Aug 2015 16:39:55 +0000 (19:39 +0300)
committerNadya Zabrodina <Nadya.Zabrodina@jetbrains.com>
Mon, 17 Aug 2015 16:39:55 +0000 (19:39 +0300)
Conflicts:
platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/CompoundShelfFileProcessor.java
platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/ShelveChangesManager.java

1  2 
platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/ShelveChangesManager.java

index 577e8f488169b2fed7b1deae428dcfe99166d818,9a4f0bdf767f7948a3b73b5d19bcdb3490ca099f..da65f1d9741b0e5c7e9f0e71ad8dfced5795ae5a
   */
  package com.intellij.openapi.vcs.changes.shelf;
  
- import com.intellij.ide.impl.ProjectUtil;
  import com.intellij.lifecycle.PeriodicalTasksCloser;
  import com.intellij.openapi.application.ApplicationManager;
 +import com.intellij.openapi.application.ModalityState;
 +import com.intellij.openapi.application.PathManager;
  import com.intellij.openapi.application.impl.LaterInvocator;
  import com.intellij.openapi.components.AbstractProjectComponent;
+ import com.intellij.openapi.components.PathMacroManager;
+ import com.intellij.openapi.components.TrackingPathMacroSubstitutor;
  import com.intellij.openapi.diagnostic.Logger;
  import com.intellij.openapi.diff.impl.patch.*;
  import com.intellij.openapi.diff.impl.patch.apply.ApplyFilePatchBase;
@@@ -52,6 -55,8 +57,7 @@@ import com.intellij.openapi.vfs.Virtual
  import com.intellij.util.Consumer;
  import com.intellij.util.PathUtil;
  import com.intellij.util.SmartList;
 -import com.intellij.util.continuation.*;
+ import com.intellij.util.containers.ContainerUtil;
  import com.intellij.util.messages.MessageBus;
  import com.intellij.util.messages.Topic;
  import com.intellij.util.text.CharArrayCharSequence;
@@@ -58,7 -64,7 +65,8 @@@ import com.intellij.util.text.UniqueNam
  import com.intellij.util.ui.UIUtil;
  import com.intellij.vcsUtil.FilesProgress;
  import org.jdom.Element;
 +import org.jetbrains.annotations.CalledInAny;
+ import org.jdom.Parent;
  import org.jetbrains.annotations.NonNls;
  import org.jetbrains.annotations.NotNull;
  import org.jetbrains.annotations.Nullable;
@@@ -355,55 -449,77 +451,67 @@@ public class ShelveChangesManager exten
      }
    }
  
 -  public void unshelveChangeList(@NotNull final ShelvedChangeList changeList, @Nullable final List<ShelvedChange> changes,
 -                                 @Nullable final List<ShelvedBinaryFile> binaryFiles, final LocalChangeList targetChangeList) {
 -    unshelveChangeList(changeList, changes, binaryFiles, targetChangeList, true);
+   @NotNull
+   private static String shortenAndSanitize(@NotNull String commitMessage) {
+     @NonNls String defaultPath = FileUtil.sanitizeFileName(commitMessage);
+     if (defaultPath.isEmpty()) {
+       defaultPath = "unnamed";
+     }
+     if (defaultPath.length() > PatchNameChecker.MAX - 10) {
+       defaultPath = defaultPath.substring(0, PatchNameChecker.MAX - 10);
+     }
+     return defaultPath;
+   }
 +  @CalledInAny
 +  public void unshelveChangeList(final ShelvedChangeList changeList,
 +                                 @Nullable final List<ShelvedChange> changes,
 +                                 @Nullable final List<ShelvedBinaryFile> binaryFiles,
 +                                 @Nullable final LocalChangeList targetChangeList,
 +                                 boolean showSuccessNotification) {
 +    unshelveChangeList(changeList, changes, binaryFiles, targetChangeList, showSuccessNotification, false, false, null, null);
    }
  
 -  @AsynchronousExecution
 -  private void unshelveChangeList(@NotNull final ShelvedChangeList changeList,
 -                                  @Nullable final List<ShelvedChange> changes,
 -                                  @Nullable final List<ShelvedBinaryFile> binaryFiles,
 -                                  @Nullable final LocalChangeList targetChangeList,
 -                                  boolean showSuccessNotification) {
 -    final Continuation continuation = Continuation.createForCurrentProgress(myProject, true, "Unshelve changes");
 -    final GatheringContinuationContext initContext = new GatheringContinuationContext();
 -    scheduleUnshelveChangeList(changeList, changes, binaryFiles, targetChangeList, showSuccessNotification, initContext, false,
 -                               false, null, null);
 -    continuation.run(initContext.getList());
 -  }
 -
 -  @AsynchronousExecution
 -  public void scheduleUnshelveChangeList(@NotNull final ShelvedChangeList changeList,
 -                                         @Nullable final List<ShelvedChange> changes,
 -                                         @Nullable final List<ShelvedBinaryFile> binaryFiles,
 -                                         @Nullable final LocalChangeList targetChangeList,
 -                                         final boolean showSuccessNotification,
 -                                         final ContinuationContext context,
 -                                         final boolean systemOperation,
 -                                         final boolean reverse,
 -                                         final String leftConflictTitle,
 -                                         final String rightConflictTitle) {
 -    context.next(new TaskDescriptor("", Where.AWT) {
 -      @Override
 -      public void run(ContinuationContext contextInner) {
 -        final List<FilePatch> remainingPatches = new ArrayList<FilePatch>();
 -
 -        final CommitContext commitContext = new CommitContext();
 -        final List<TextFilePatch> textFilePatches;
 -        try {
 -          textFilePatches = loadTextPatches(myProject, changeList, changes, remainingPatches, commitContext);
 -        }
 -        catch (IOException e) {
 -          LOG.info(e);
 -          PatchApplier.showError(myProject, "Cannot load patch(es): " + e.getMessage(), true);
 -          return;
 -        }
 -        catch (PatchSyntaxException e) {
 -          PatchApplier.showError(myProject, "Cannot load patch(es): " + e.getMessage(), true);
 -          LOG.info(e);
 -          return;
 -        }
 +  @CalledInAny
 +  public void unshelveChangeList(final ShelvedChangeList changeList,
 +                                 @Nullable final List<ShelvedChange> changes,
 +                                 @Nullable final List<ShelvedBinaryFile> binaryFiles,
 +                                 @Nullable final LocalChangeList targetChangeList,
 +                                 final boolean showSuccessNotification,
 +                                 final boolean systemOperation,
 +                                 final boolean reverse,
 +                                 final String leftConflictTitle,
 +                                 final String rightConflictTitle) {
 +    final List<FilePatch> remainingPatches = new ArrayList<FilePatch>();
 +
 +    final CommitContext commitContext = new CommitContext();
 +    final List<TextFilePatch> textFilePatches;
 +    try {
 +      textFilePatches = loadTextPatches(myProject, changeList, changes, remainingPatches, commitContext);
 +    }
 +    catch (IOException e) {
 +      LOG.info(e);
 +      PatchApplier.showError(myProject, "Cannot load patch(es): " + e.getMessage(), true);
 +      return;
 +    }
 +    catch (PatchSyntaxException e) {
 +      PatchApplier.showError(myProject, "Cannot load patch(es): " + e.getMessage(), true);
 +      LOG.info(e);
 +      return;
 +    }
  
 -        final List<FilePatch> patches = new ArrayList<FilePatch>(textFilePatches);
 +    final List<FilePatch> patches = new ArrayList<FilePatch>(textFilePatches);
  
 -        final List<ShelvedBinaryFile> remainingBinaries = new ArrayList<ShelvedBinaryFile>();
 -        final List<ShelvedBinaryFile> binaryFilesToUnshelve = getBinaryFilesToUnshelve(changeList, binaryFiles, remainingBinaries);
 +    final List<ShelvedBinaryFile> remainingBinaries = new ArrayList<ShelvedBinaryFile>();
 +    final List<ShelvedBinaryFile> binaryFilesToUnshelve = getBinaryFilesToUnshelve(changeList, binaryFiles, remainingBinaries);
  
 -        for (final ShelvedBinaryFile shelvedBinaryFile : binaryFilesToUnshelve) {
 -          patches.add(new ShelvedBinaryFilePatch(shelvedBinaryFile));
 -        }
 +    for (final ShelvedBinaryFile shelvedBinaryFile : binaryFilesToUnshelve) {
 +      patches.add(new ShelvedBinaryFilePatch(shelvedBinaryFile));
 +    }
  
 +    ApplicationManager.getApplication().invokeAndWait(new Runnable() {
 +      @Override
 +      public void run() {
          final BinaryPatchApplier binaryPatchApplier = new BinaryPatchApplier();
          final PatchApplier<ShelvedBinaryFilePatch> patchApplier =
            new PatchApplier<ShelvedBinaryFilePatch>(myProject, myProject.getBaseDir(),